astex
Class FILE

java.lang.Object
  extended by java.io.InputStream
      extended by astex.FILE
All Implemented Interfaces:
java.io.Closeable

public class FILE
extends java.io.InputStream

A class which implements a high performance byte based input stream. Buffering is performed internally. This class is NOT thread safe.


Field Summary
static int EOF
          The constant that represents the end of file.
static FILE err
           
static FILE in
           
static int MAC
           
static FILE out
          Wrapper allowing write to stdout and stderr.
static int PC
           
static FILE spr
           
static int UNIX
           
 
Constructor Summary
FILE(java.io.InputStream is)
          Constructor that will take an InputStream and create a FILE object that will read from it.
FILE(java.io.OutputStream os)
          Constructor for stdout stderr output.
 
Method Summary
 void close()
          Close a file object.
 boolean currentLineContains(java.lang.String string, int offset)
          Does the current line contain the specified string at the specified location.
 void format(char c)
          Format the char argument.
 void format(double x)
          Format double.
 void format(long d)
          Format integer.
 void format(java.lang.String s)
          Format the String argument.
 char getChar(int offset)
          Return the specified character from the current line.
 java.lang.String getCurrentLineAsString()
          Return the current line as a String.
 double getDouble(int f)
          Synonym for readDoubleFromField.
static java.lang.Exception getException()
          Get the exception (if any) that was thrown when FILE.open() was called.
 java.lang.String getField(int f)
          Get the field as a string.
 byte getFieldChar(int f, int c)
          Get the specified character from the field.
 int getFieldCount()
          Return the number of fields on the current line.
 int getFieldLength(int f)
          Get the start position of the field.
 int getFieldStart(int f)
          Get the start position of the field.
 float getFloat(int f)
           
 java.io.InputStream getInputStream()
          Get the input stream associated with this file.
 int getInteger(int f)
          Synonym for readIntegerFromField.
 int getLineLength()
          Return the length of the current line.
static java.lang.String getRelativePath(java.lang.String path)
          Try and make path relative to current directory.
 java.lang.String getSubstring(int offset, int length)
          Return a substring of the current line.
static boolean getTryFiles()
           
static java.util.Properties loadProperties(java.lang.String resource)
          Convenience method to load a properties file.
static void main(java.lang.String[] args)
          Test program for the FILE class.
 boolean nextLine()
          Advance the FILE object to the next line.
static FILE open(java.io.File file)
          Create a FILE object to read from the specified File object.
static FILE open(java.lang.String resource)
          Return a FILE object for reading the specified resource.
static FILE open(java.net.URL url)
          Create a FILE object to read from the specified URL.
static FILE openFile(java.lang.String filename)
          Create a FILE object to read from the specified filename.
static FILE openURL(java.lang.String urlname)
          Create a FILE object to read from the specified urlname.
 void print(char c)
          Print a char.
 void print(int w, int p, double d)
          Quick print function for floats/doubles.
 void print(int w, long d)
          Quick print function for ints/long
 void print(java.lang.String s)
          print function.
 void print(java.lang.String f, char c)
          Print a formatted char.
 void print(java.lang.String f, double d)
          Print a formatted double.
 void print(java.lang.String f, double d1, double d2, double d3)
          Print function for 3 floats/doubles.
 void print(java.lang.String f, long d)
          Print a formatted integer.
 void print(java.lang.String f, long d1, long d2, long d3)
          Print function for 3 ints/longs.
 void print(java.lang.String f, java.lang.String s)
          Print a formatted String.
 void println(java.lang.String s)
          println function.
 int read()
          Read a single character.
 double readDouble(int offset, int length)
          Read a double precision number from the specified region.
static double readDouble(java.lang.String string)
          Read a double value from a string.
 double readDoubleFromField(int f)
          Read a double from the specified field.
static int readFrom(FILE file)
          Read the data from the specified FILE object.
 int readInteger(int offset, int length)
          Read an integer from the current line buffer.
static int readInteger(java.lang.String string)
          Read an integer from the specified string.
 int readInteger3(int offset)
          Specific method for reading a 3 column integer.
 int readIntegerFromField(int f)
          Read an integer from the specified field.
 java.lang.String readLine()
          Provide a method that will return the current line as a String.
 void setautoFlush(boolean f)
          sets the autoFlush flag.
 void setCharactersInBuffer(int i)
           
static void setCodeBase(java.net.URL url)
          Set the docuemnt base.
static void setDebug(boolean state)
          Set the debug state.
static void setDocumentBase(java.net.URL url)
          Set the docuemnt base.
 void setEolIdentifier(int opsys)
          Set the eond of line characters explicitily.
 void setOutputStream(java.io.OutputStream os)
          Set the output stream.
static void setTryFiles(boolean t)
           
 int skip(int byteCount)
          Skip some bytes.
static java.lang.String[] split(java.lang.String string)
          Convenience methods for splitting strings into fields.
static java.lang.String[] split(java.lang.String string, java.lang.String separators)
          Convenience methods for splitting strings into fields.
static java.lang.String sprint(java.lang.String f, double d)
          Return a formatted double as String.
static java.lang.String sprint(java.lang.String f, long d)
          Return a formatted long as String.
static java.lang.String sprint(java.lang.String f, java.lang.String d)
          Return a formatted String as String.
static boolean stringIsURL(java.lang.String resource)
          Does the resource look like it is a URL?
 void ungetc(int c)
          unget a single character.
static FILE write(java.lang.String file)
          Opens outputstream for writing.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF

public static int EOF
The constant that represents the end of file.


out

public static FILE out
Wrapper allowing write to stdout and stderr.


err

public static FILE err

in

public static FILE in

spr

public static FILE spr

UNIX

public static final int UNIX
See Also:
Constant Field Values

PC

public static final int PC
See Also:
Constant Field Values

MAC

public static final int MAC
See Also:
Constant Field Values
Constructor Detail

FILE

public FILE(java.io.OutputStream os)
Constructor for stdout stderr output.


FILE

public FILE(java.io.InputStream is)
Constructor that will take an InputStream and create a FILE object that will read from it.

Method Detail

setautoFlush

public void setautoFlush(boolean f)
sets the autoFlush flag.


sprint

public static java.lang.String sprint(java.lang.String f,
                                      double d)
Return a formatted double as String.


sprint

public static java.lang.String sprint(java.lang.String f,
                                      long d)
Return a formatted long as String.


sprint

public static java.lang.String sprint(java.lang.String f,
                                      java.lang.String d)
Return a formatted String as String.


print

public void print(char c)
Print a char.


print

public void print(int w,
                  int p,
                  double d)
Quick print function for floats/doubles.


print

public void print(int w,
                  long d)
Quick print function for ints/long


print

public void print(java.lang.String f,
                  double d1,
                  double d2,
                  double d3)
Print function for 3 floats/doubles.


print

public void print(java.lang.String f,
                  long d1,
                  long d2,
                  long d3)
Print function for 3 ints/longs.


print

public void print(java.lang.String s)
print function. No formatting.


println

public void println(java.lang.String s)
println function. No formatting adds eol.


print

public void print(java.lang.String f,
                  java.lang.String s)
Print a formatted String.


print

public void print(java.lang.String f,
                  char c)
Print a formatted char.


print

public void print(java.lang.String f,
                  long d)
Print a formatted integer.


print

public void print(java.lang.String f,
                  double d)
Print a formatted double.


format

public void format(java.lang.String s)
Format the String argument.


format

public void format(long d)
Format integer.


format

public void format(double x)
Format double.


format

public void format(char c)
Format the char argument.


setOutputStream

public void setOutputStream(java.io.OutputStream os)
Set the output stream.


setEolIdentifier

public void setEolIdentifier(int opsys)
Set the eond of line characters explicitily.


write

public static FILE write(java.lang.String file)
Opens outputstream for writing.


setTryFiles

public static void setTryFiles(boolean t)

getTryFiles

public static boolean getTryFiles()

setDebug

public static void setDebug(boolean state)
Set the debug state.


setDocumentBase

public static void setDocumentBase(java.net.URL url)
Set the docuemnt base.


setCodeBase

public static void setCodeBase(java.net.URL url)
Set the docuemnt base.


getException

public static java.lang.Exception getException()
Get the exception (if any) that was thrown when FILE.open() was called.


getInputStream

public java.io.InputStream getInputStream()
Get the input stream associated with this file.


setCharactersInBuffer

public void setCharactersInBuffer(int i)

read

public int read()
Read a single character.

Specified by:
read in class java.io.InputStream

skip

public int skip(int byteCount)
Skip some bytes.


ungetc

public void ungetc(int c)
unget a single character.


getLineLength

public int getLineLength()
Return the length of the current line.


nextLine

public boolean nextLine()
Advance the FILE object to the next line. A return value of EOF indicates that there are no more lines.


readLine

public java.lang.String readLine()
Provide a method that will return the current line as a String. This has the same functionality as the BufferedReader readLine() method. There is no need to use this at all.


getCurrentLineAsString

public java.lang.String getCurrentLineAsString()
Return the current line as a String.


getChar

public char getChar(int offset)
Return the specified character from the current line.


currentLineContains

public boolean currentLineContains(java.lang.String string,
                                   int offset)
Does the current line contain the specified string at the specified location.


getSubstring

public java.lang.String getSubstring(int offset,
                                     int length)
Return a substring of the current line.


readInteger

public int readInteger(int offset,
                       int length)
Read an integer from the current line buffer.


readInteger3

public int readInteger3(int offset)
Specific method for reading a 3 column integer.


readDouble

public double readDouble(int offset,
                         int length)
Read a double precision number from the specified region.


getFieldCount

public int getFieldCount()
Return the number of fields on the current line.


getFieldStart

public int getFieldStart(int f)
Get the start position of the field.


getFieldLength

public int getFieldLength(int f)
Get the start position of the field.


getField

public java.lang.String getField(int f)
Get the field as a string.


getFieldChar

public byte getFieldChar(int f,
                         int c)
Get the specified character from the field.


getRelativePath

public static java.lang.String getRelativePath(java.lang.String path)
Try and make path relative to current directory.


open

public static FILE open(java.lang.String resource)
Return a FILE object for reading the specified resource. If the resource looks like it is a URL name (begins with something like 'http:' or 'ftp:') then an attempt will be made to open it as a URL. Otherwise the resource will be opened as a file.


stringIsURL

public static boolean stringIsURL(java.lang.String resource)
Does the resource look like it is a URL?


open

public static FILE open(java.io.File file)
Create a FILE object to read from the specified File object.


openFile

public static FILE openFile(java.lang.String filename)
Create a FILE object to read from the specified filename.


openURL

public static FILE openURL(java.lang.String urlname)
Create a FILE object to read from the specified urlname.


open

public static FILE open(java.net.URL url)
Create a FILE object to read from the specified URL.


close

public void close()
Close a file object. This also closes the underlying InputStream. Returns true if there is a problem closing the FILE.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream

loadProperties

public static java.util.Properties loadProperties(java.lang.String resource)
Convenience method to load a properties file.


getInteger

public int getInteger(int f)
Synonym for readIntegerFromField.


getFloat

public float getFloat(int f)

getDouble

public double getDouble(int f)
Synonym for readDoubleFromField.


readIntegerFromField

public int readIntegerFromField(int f)
Read an integer from the specified field.


readDoubleFromField

public double readDoubleFromField(int f)
Read a double from the specified field.


readInteger

public static int readInteger(java.lang.String string)
Read an integer from the specified string.


readDouble

public static double readDouble(java.lang.String string)
Read a double value from a string.


split

public static java.lang.String[] split(java.lang.String string)
Convenience methods for splitting strings into fields.


split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String separators)
Convenience methods for splitting strings into fields.


main

public static void main(java.lang.String[] args)
Test program for the FILE class.


readFrom

public static int readFrom(FILE file)
Read the data from the specified FILE object.