futils
Class ReaderUtil

java.lang.Object
  extended by futils.ReaderUtil

public class ReaderUtil
extends java.lang.Object


Constructor Summary
ReaderUtil()
           
 
Method Summary
static void close(java.io.BufferedReader br)
           
static void close(java.io.FileReader fr)
           
static int countTokens(java.io.BufferedReader br)
          Prompts the user for a file and counts the tokens.
static SimpleAddressBook getAddressBook()
          Obtain a list of records using a given record delimiter.
static SimpleAddressBook getAddressBook(java.io.File f, java.lang.String c)
          Do a getRecords with
static boolean getBoolean(java.lang.String prompt)
           
static java.io.BufferedReader getBufferedReader(java.io.File f)
           
static java.io.BufferedReader getBufferedReader(java.lang.String prompt)
           
static byte[] getBytes(int i)
           
static byte[] getBytes(java.lang.String[] o)
           
static double getDouble(java.lang.String prompt)
           
static java.lang.String getFileAsOneBigString(java.io.File f)
          Returns the file instance as a string, reading it in, one line affineTransform a time.
static java.lang.String[] getFileAsStringArray(java.io.File f)
          Reads in a text file
static java.io.FileReader getFileReader(java.io.File file)
           
static java.io.FileReader getFileReader(java.lang.String prompt)
           
static int[] getInt(byte[] b)
           
static int getInt(java.lang.String prompt)
           
static int[] getInts(float f)
           
static java.io.BufferedReader getReader()
           
static java.lang.String[] getReaderAsStringArray(java.io.BufferedReader br)
           
static java.io.File getReadFileAWT(java.lang.String prompt)
          Prompt the user for a file select and return the File instance.
static java.io.File getReadFileSwing(java.lang.String prompt)
           
static java.lang.String getString(java.lang.String prompt)
           
static java.lang.String[] getTokens(java.lang.String s)
           
static boolean isReadableFile(java.io.File f)
          isReadableFile() - validates the file is exists and readable
static void listFile()
           
static void listFilteredHrefFile(java.io.File file)
           
static void main(java.lang.String[] args)
           
static boolean parseBoolean(java.lang.String s)
           
static void print(java.lang.Object[] o)
           
static void printResponse(java.io.Reader br)
           
static void processReader(java.io.BufferedReader br, LineProcessor lp)
           
static void readDataFile(java.io.File file, double[] data)
           
static java.lang.String readLine(java.io.BufferedReader br)
           
static void readQuestion(java.lang.String s)
           
static void setReader(java.io.BufferedReader _br)
           
static int[] string2Int(java.lang.String[] s)
           
static int sum(int[] o)
           
static void testGetFile()
           
static void testGetInts()
           
static void testGetReadFile()
           
static void testGetTokenizer()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderUtil

public ReaderUtil()
Method Detail

setReader

public static void setReader(java.io.BufferedReader _br)

getReader

public static java.io.BufferedReader getReader()

getString

public static java.lang.String getString(java.lang.String prompt)

getBytes

public static byte[] getBytes(int i)
                       throws java.io.IOException
Throws:
java.io.IOException

getInt

public static int[] getInt(byte[] b)

testGetInts

public static void testGetInts()

getInts

public static int[] getInts(float f)

getBytes

public static byte[] getBytes(java.lang.String[] o)
                       throws java.io.IOException
Throws:
java.io.IOException

print

public static void print(java.lang.Object[] o)

sum

public static int sum(int[] o)

string2Int

public static int[] string2Int(java.lang.String[] s)

getTokens

public static java.lang.String[] getTokens(java.lang.String s)

testGetFile

public static void testGetFile()

getFileAsStringArray

public static java.lang.String[] getFileAsStringArray(java.io.File f)
                                               throws java.io.FileNotFoundException
Reads in a text file

Parameters:
f - file to be read in
Returns:
an array of string, one line per array element
Throws:
java.io.FileNotFoundException - we do not guard the input

processReader

public static void processReader(java.io.BufferedReader br,
                                 LineProcessor lp)

getReaderAsStringArray

public static java.lang.String[] getReaderAsStringArray(java.io.BufferedReader br)

getAddressBook

public static SimpleAddressBook getAddressBook()
Obtain a list of records using a given record delimiter. For example, input a file and a delimiter (^m) and return an array of records.
String s[] = getRecords(f, '\r');
In java, C and C++, '\r' = carrage return, '\f' = form feed (or line feed) ^m is a carrage...

Returns:
unparsed array of records as String

getAddressBook

public static SimpleAddressBook getAddressBook(java.io.File f,
                                               java.lang.String c)
                                        throws java.io.IOException
Do a getRecords with

Parameters:
f - as the input file
c - as the delimiting character
Returns:
records in the order in which they appear in the file
Throws:
java.io.IOException - if file is not found

listFile

public static void listFile()

readQuestion

public static void readQuestion(java.lang.String s)

testGetTokenizer

public static void testGetTokenizer()

isReadableFile

public static boolean isReadableFile(java.io.File f)
isReadableFile() - validates the file is exists and readable

Parameters:
f - The file to be examined.
Returns:
boolean - file is readable true/false

getBufferedReader

public static java.io.BufferedReader getBufferedReader(java.lang.String prompt)
Parameters:
prompt - shown to user
Returns:
prompt the user for a bufferedReader from a file.

getBufferedReader

public static java.io.BufferedReader getBufferedReader(java.io.File f)
Parameters:
f - get a bufferedReader from a file
Returns:
a bufferedReader

readLine

public static java.lang.String readLine(java.io.BufferedReader br)
Parameters:
br - bufferedReader is not closed after read
Returns:
line read in string

close

public static void close(java.io.BufferedReader br)
Parameters:
br - closes and catches any exception

getReadFileAWT

public static java.io.File getReadFileAWT(java.lang.String prompt)
Prompt the user for a file select and return the File instance.

Parameters:
prompt - String displayed in a dialog
Returns:
File selected by a user

testGetReadFile

public static void testGetReadFile()

getReadFileSwing

public static java.io.File getReadFileSwing(java.lang.String prompt)

getFileReader

public static java.io.FileReader getFileReader(java.lang.String prompt)

getFileReader

public static java.io.FileReader getFileReader(java.io.File file)

close

public static void close(java.io.FileReader fr)

readDataFile

public static void readDataFile(java.io.File file,
                                double[] data)
                         throws java.io.IOException
Parameters:
file - check this before calling the readDataFile
data - is changed as a side-effect
Throws:
java.io.IOException - if file not found

countTokens

public static int countTokens(java.io.BufferedReader br)
Prompts the user for a file and counts the tokens.

Returns:
returns the number of tokens in a file

listFilteredHrefFile

public static void listFilteredHrefFile(java.io.File file)

parseBoolean

public static boolean parseBoolean(java.lang.String s)
                            throws BooleanException
Throws:
BooleanException

getBoolean

public static boolean getBoolean(java.lang.String prompt)

getInt

public static int getInt(java.lang.String prompt)

getDouble

public static double getDouble(java.lang.String prompt)

getFileAsOneBigString

public static java.lang.String getFileAsOneBigString(java.io.File f)
Returns the file instance as a string, reading it in, one line affineTransform a time.

Parameters:
f - is used as input
Returns:
file contents of the file in one big string;

main

public static void main(java.lang.String[] args)

printResponse

public static void printResponse(java.io.Reader br)
                          throws java.io.IOException
Throws:
java.io.IOException