|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jbeans.io.FileIO
routines for reading and writing files. Features include transparent use of compression and decompression, stdin/stdout.
Field Summary | |
static int |
COMMAND
|
static int |
EOF
|
static int |
FILEERR
|
static int |
FILEFORMAT
|
static int |
FILEMODE
|
static int |
GZIP
|
static int |
HEADER
|
static int |
LINETOOLONG
|
static int |
NO_MEMORY
|
static int |
NO_PIPES
|
static int |
NO_ZIP
|
static int |
OK
|
static int |
OPENFILE
|
static int |
REWINDFILE
|
static int |
REWINDPIPE
|
static java.lang.String |
STDERR_NAME
|
static java.lang.String |
STDIN_NAME
|
static java.lang.String |
STDOUT_NAME
|
static int |
UNKNOWN
|
static int |
ZIP
|
Constructor Summary | |
FileIO(java.lang.String filename,
java.lang.String filemode)
Opens a file for reading or writing. |
Method Summary | |
boolean |
checkError()
Flush the stream and check its error state. |
void |
close()
Closes FileIO instance. |
void |
flush()
Flush the stream. |
java.lang.String |
getFilename()
Returns a filename associated with this FileIO object. |
java.lang.String |
getLine()
Reads a line from file. |
int |
getLineNo()
Returns current line number. |
int |
getMode()
Returns the file mode. |
java.lang.String |
getOriginalFilename()
Returns the original file name. |
java.lang.String |
getOriginalMode()
Returns the original mode string. |
boolean |
getPipeFlag()
Returns true if the file is piped. |
JBeansReader |
getReader()
returns a input reader associated with this file I/O. |
java.io.PrintWriter |
getWriter()
returns a writer associated with this file I/O. |
boolean |
hasReachedEOF()
Returns true if the file has reached EOF. |
static void |
main(java.lang.String[] args)
Tests FileIO class. |
void |
print(boolean b)
Print a boolean value. |
void |
print(char c)
Print a character. |
void |
print(char[] s)
Print an array of characters. |
void |
print(double d)
Print a double-precision floating-point number. |
void |
print(float f)
Print a floating-point number. |
void |
print(int i)
Print an integer. |
void |
print(long l)
Print a long integer. |
void |
print(java.lang.Object obj)
Print an object. |
void |
print(java.lang.String s)
Print a string. |
void |
println()
Terminate the current line by writing the line separator string. |
void |
println(boolean x)
Print a boolean value and then terminate the line. |
void |
println(char x)
Print a character and then terminate the line. |
void |
println(char[] x)
Print an array of characters and then terminate the line. |
void |
println(double x)
Print a double-precision floating-point number and then terminate the line. |
void |
println(float x)
Print a floating-point number and then terminate the line. |
void |
println(int x)
Print an integer and then terminate the line. |
void |
println(long x)
Print a long integer and then terminate the line. |
void |
println(java.lang.Object x)
Print an Object and then terminate the line. |
void |
println(java.lang.String x)
Print a String and then terminate the line. |
int |
read()
Read a single character. |
int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array. |
boolean |
readBoolean()
Reads a boolean from this data input stream. |
byte |
readByte()
Reads a signed 8-bit value from this data input stream. |
char |
readChar()
Reads a Unicode character from this data input stream. |
double |
readDouble()
Reads a double from this data input stream. |
float |
readFloat()
Reads a float from this data input stream. |
int |
readInt()
Reads a signed 32-bit integer from this data input stream. |
java.lang.String |
readLine()
Read a line of text. |
java.lang.String |
readLine(char commentchar)
Read a line of text. |
java.lang.String |
readLine(java.lang.String commentchars)
Read a line of text. |
long |
readLong()
Reads a signed 64-bit integer from this data input stream. |
short |
readShort()
Reads a signed 16-bit number from this data input stream. |
java.lang.String |
readToken()
Read one token as a string. |
void |
write(char[] buf)
Write an array of characters. |
void |
write(char[] buf,
int off,
int len)
Write a portion of an array of characters. |
void |
write(int c)
Write a single character. |
void |
write(java.lang.String s)
Write a string. |
void |
write(java.lang.String s,
int off,
int len)
Write a portion of a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NO_ZIP
public static final int ZIP
public static final int GZIP
public static final java.lang.String STDIN_NAME
public static final java.lang.String STDOUT_NAME
public static final java.lang.String STDERR_NAME
public static final int OK
public static final int UNKNOWN
public static final int NO_MEMORY
public static final int FILEMODE
public static final int NO_PIPES
public static final int OPENFILE
public static final int COMMAND
public static final int REWINDFILE
public static final int REWINDPIPE
public static final int LINETOOLONG
public static final int FILEERR
public static final int HEADER
public static final int FILEFORMAT
public static final int EOF
Constructor Detail |
public FileIO(java.lang.String filename, java.lang.String filemode) throws InvalidFileModeException, FileIOException, java.io.IOException
try { FileIO fio0 = new FileIO("foo0", "r"); FileIO fio1 = new FileIO("foo1.gz", "r"); FileIO fio2 = new FileIO("foo2.zip", "rz"); FileIO fio3 = new FileIO("foo3.gz", "rg"); ... fio0.close(); fio1.close(); fio2.close(); fio3.close(); } catch (InvalidFileModeException ifme) { System.err.println(ifme); } catch (FileIOException fioe) { System.err.println(fioe); } catch (IOException ioe) { System.err.println(ioe); } finally { }
(full-classname)
- (description)
InvalidFileModeException
FileIOException
java.io.IOException
close()
Method Detail |
public final JBeansReader getReader()
getWriter()
public final java.io.PrintWriter getWriter()
getReader()
public final int getMode()
public final java.lang.String getOriginalFilename()
public final java.lang.String getOriginalMode()
public final boolean hasReachedEOF()
public final boolean getPipeFlag()
public final int getLineNo()
public final void close() throws java.io.IOException
java.io.IOException
FileIO(java.lang.String, java.lang.String)
public final java.lang.String getFilename()
public final java.lang.String getLine() throws java.io.EOFException, java.io.IOException
java.io.EOFException
java.io.IOException
public final int read() throws java.io.IOException
java.io.IOException
- If an I/O error occurspublic final int read(char[] cbuf, int off, int len) throws java.io.IOException
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to read
java.io.IOException
- If an I/O error occurspublic final java.lang.String readLine() throws java.io.IOException
java.io.IOException
- If an I/O error occurspublic final java.lang.String readLine(java.lang.String commentchars) throws java.io.IOException
java.io.IOException
- If an I/O error occurspublic final java.lang.String readLine(char commentchar) throws java.io.IOException
java.io.IOException
- If an I/O error occurspublic final java.lang.String readToken() throws java.io.IOException
java.io.IOException
- If an I/O error occurspublic final boolean readBoolean() throws java.io.IOException
boolean
from this data input stream. This
method reads a single byte from the underlying input stream. A
value of 0
represents false
. Any other
value represents true
. This method blocks until
either the byte is read, the end of the stream is detected, or an
exception is thrown.
boolean
value read.
java.io.EOFException
- if this input stream has reached the end.
java.io.IOException
- if an I/O error occurs.public final byte readByte() throws java.io.IOException
b
, where
0 <= b
<= 255, then the
result is:
(byte)(b)
This method blocks until either the byte is read, the end of the stream is detected, or an exception is thrown.
byte
.
java.io.EOFException
- if this input stream has reached the end.
java.io.IOException
- if an I/O error occurs.public final short readShort() throws java.io.IOException
b1
and b2
,
where each of the two values is between 0
and
255
, inclusive, then the result is equal to:
(short)((b1 << 8) | b2)
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
java.io.EOFException
- if this input stream reaches the end before
reading two bytes.
java.io.IOException
- if an I/O error occurs.public final char readChar() throws java.io.IOException
b1
and b2
,
where 0 <= b1
,
b1
<= 255, then the result is equal to:
(char)((b1 << 8) | b2)
This method blocks until either the two bytes are read, the end of the stream is detected, or an exception is thrown.
java.io.EOFException
- if this input stream reaches the end before
reading two bytes.
java.io.IOException
- if an I/O error occurs.public final int readInt() throws java.io.IOException
b1
, b2
,
b3
, and b4
, where
0 <= b1
, b2
,
b3
, b4
<= 255, then the
result is equal to:
(b1 << 24) | (b2 << 16) + (b3 << 8) +b4
This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
int
.
java.io.EOFException
- if this input stream reaches the end before
reading four bytes.
java.io.IOException
- if an I/O error occurs.public final long readLong() throws java.io.IOException
b1
, b2
,
b3
, b4
, b5
,
b6
, b7
, and b8
, where
0 <= b1, b2, b3, b4, b5, b6, b7, b8 <= 255,
then the result is equal to:
((long)b1 << 56) + ((long)b2 << 48) + ((long)b3 << 40) + ((long)b4 << 32) + ((long)b5 << 24) + (b6 << 16) + (b7 << 8) + b8
This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
long
.
java.io.EOFException
- if this input stream reaches the end before
reading eight bytes.
java.io.IOException
- if an I/O error occurs.public final float readFloat() throws java.io.IOException
float
from this data input stream. This
method reads an int
value as if by the
readInt
method and then converts that
int
to a float
using the
intBitsToFloat
method in class Float
.
This method blocks until the four bytes are read, the end of the
stream is detected, or an exception is thrown.
float
.
java.io.EOFException
- if this input stream reaches the end before
reading four bytes.
java.io.IOException
- if an I/O error occurs.public final double readDouble() throws java.io.IOException
double
from this data input stream. This
method reads a long
value as if by the
readLong
method and then converts that
long
to a double
using the
longBitsToDouble
method in class Double
.
This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
double
.
java.io.EOFException
- if this input stream reaches the end before
reading eight bytes.
java.io.IOException
- if an I/O error occurs.public final void flush()
public final boolean checkError()
public final void write(int c)
public final void write(char[] buf, int off, int len)
public final void write(char[] buf)
public final void write(java.lang.String s, int off, int len)
public final void write(java.lang.String s)
public final void print(boolean b)
String.valueOf(boolean)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the write(int)
method.
b
- The boolean
to be printedpublic final void print(char c)
write(int)
method.
c
- The char
to be printedpublic final void print(int i)
String.valueOf(int)
is translated into bytes according
to the platform's default character encoding, and these bytes are
written in exactly the manner of the write(int)
method.
i
- The int
to be printedInteger.toString(int)
public final void print(long l)
String.valueOf(long)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the write(int)
method.
l
- The long
to be printedLong.toString(long)
public final void print(float f)
String.valueOf(float)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the write(int)
method.
f
- The float
to be printedFloat.toString(float)
public final void print(double d)
String.valueOf(double)
is translated into
bytes according to the platform's default character encoding, and these
bytes are written in exactly the manner of the write(int)
method.
d
- The double
to be printedDouble.toString(double)
public final void print(char[] s)
write(int)
method.
s
- The array of chars to be printed
java.lang.NullPointerException
- If s
is null
public final void print(java.lang.String s)
null
then the string
"null"
is printed. Otherwise, the string's characters are
converted into bytes according to the platform's default character
encoding, and these bytes are written in exactly the manner of the
write(int)
method.
s
- The String
to be printedpublic final void print(java.lang.Object obj)
String.valueOf(Object)
method is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the write(int)
method.
obj
- The Object
to be printedObject.toString()
public final void println()
line.separator
, and is not necessarily a single newline
character ('\n'
).
public final void println(boolean x)
print(boolean)
and then
println()
.
public final void println(char x)
print(char)
and then println()
.
public final void println(int x)
print(int)
and then println()
.
public final void println(long x)
print(long)
and then
println()
.
public final void println(float x)
print(float)
and then
println()
.
public final void println(double x)
print(double)
and then println()
.
public final void println(char[] x)
print(char[])
and then
println()
.
public final void println(java.lang.String x)
print(String)
and then
println()
.
public final void println(java.lang.Object x)
print(Object)
and then
println()
.
public static final void main(java.lang.String[] args)
args
- An array of input and output filename.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |