public class BufferedFile extends java.lang.Object implements ArrayDataInput, ArrayDataOutput, RandomAccess
Constructor and Description |
---|
BufferedFile(java.io.File file)
Create a buffered file from a File descriptor
|
BufferedFile(java.io.File file,
java.lang.String mode)
Create a buffered file from a File descriptor
|
BufferedFile(java.io.File file,
java.lang.String mode,
int bufferSize)
Create a buffered file from a file descriptor
|
BufferedFile(java.lang.String filename)
Create a read-only buffered file
|
BufferedFile(java.lang.String filename,
java.lang.String mode)
Create a buffered file with the given mode.
|
BufferedFile(java.lang.String filename,
java.lang.String mode,
int bufferSize)
Create a buffered file with the given mode and a specified
buffer size.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the file
|
protected void |
finalize()
Clear up any pending output at cleanup.
|
void |
flush()
Flush output buffer if necessary.
|
java.nio.channels.FileChannel |
getChannel()
Get the channel associated with
this file.
|
java.io.FileDescriptor |
getFD()
Get the file descriptor associated with
this stream.
|
long |
getFilePointer()
Get the current offset into the file.
|
protected void |
initialize(java.io.File file,
java.lang.String mode,
int bufferSize) |
long |
length()
Get the current length of the file.
|
protected long |
primitiveArrayRecurse(java.lang.Object o) |
int |
read()
Read a byte
|
int |
read(boolean[] b) |
int |
read(boolean[] b,
int start,
int length) |
int |
read(byte[] buf)
Create a buffered file using a mapped
/** Read an entire byte array.
|
int |
read(byte[] buf,
int offset,
int len)
Read into a segment of a byte array.
|
int |
read(char[] c) |
int |
read(char[] c,
int start,
int length) |
int |
read(double[] d) |
int |
read(double[] d,
int start,
int length) |
int |
read(float[] f) |
int |
read(float[] f,
int start,
int length) |
int |
read(int[] i) |
int |
read(int[] i,
int start,
int length) |
int |
read(long[] l) |
int |
read(long[] l,
int start,
int length) |
int |
read(short[] s) |
int |
read(short[] s,
int start,
int length) |
int |
readArray(java.lang.Object o)
Deprecated.
The readLArray(Object) routine should be used to
ensure that large arrays which read more than
two-gigabytes return the proper value.
|
boolean |
readBoolean()
Read a boolean
|
byte |
readByte()
Read a byte
|
char |
readChar()
Read a char
|
double |
readDouble()
Read a double.
|
float |
readFloat()
Read a float.
|
void |
readFully(byte[] b)
Read a byte array fully.
|
void |
readFully(byte[] b,
int off,
int len)
Read a byte array fully.
|
int |
readInt()
Read an int
|
long |
readLArray(java.lang.Object o)
This routine provides efficient reading of arrays of any primitive
type.
|
java.lang.String |
readLine()
Read a line of input.
|
long |
readLong()
Read a long.
|
short |
readShort()
Read a short
|
int |
readUnsignedByte()
Read an unsigned byte.
|
int |
readUnsignedShort()
Read an unsigned short.
|
java.lang.String |
readUTF()
Read a string encoded as a UTF.
|
void |
seek(long offsetFromStart)
Move to the current offset from the beginning of the file.
|
void |
setLength(long newLength)
Set the length of the file.
|
long |
skip(long offset)
Skip from the current position.
|
int |
skipBytes(int toSkip)
Skip the number of bytes.
|
long |
skipBytes(long toSkip) |
void |
write(boolean[] b)
Write an array of booleans.
|
void |
write(boolean[] b,
int start,
int length) |
void |
write(byte[] buf) |
void |
write(byte[] buf,
int offset,
int length) |
void |
write(char[] c)
Write an array of char's.
|
void |
write(char[] c,
int start,
int length) |
void |
write(double[] d)
Write an array of doubles.
|
void |
write(double[] d,
int start,
int length) |
void |
write(float[] f)
Write an array of floats.
|
void |
write(float[] f,
int start,
int length) |
void |
write(int buf) |
void |
write(int[] i)
Write an array of int's.
|
void |
write(int[] i,
int start,
int length) |
void |
write(long[] l)
Write an array of longs.
|
void |
write(long[] l,
int start,
int length) |
void |
write(short[] s)
Write an array of shorts.
|
void |
write(short[] s,
int start,
int length) |
void |
write(java.lang.String[] s)
Write an array of Strings -- equivalent to calling writeBytes for each string.
|
void |
write(java.lang.String[] s,
int start,
int length) |
void |
writeArray(java.lang.Object o)
This routine provides efficient writing of arrays of any primitive type.
|
void |
writeBoolean(boolean b)
Write a boolean value
|
void |
writeByte(int b)
Write a byte value.
|
void |
writeBytes(java.lang.String s)
Write a string using the local protocol to convert char's to bytes.
|
void |
writeChar(int c)
Write a char value.
|
void |
writeChars(java.lang.String s)
Write a string as an array of chars.
|
void |
writeDouble(double d)
Write a double value.
|
void |
writeFloat(float f)
Write a float value.
|
void |
writeInt(int i)
Write an integer value.
|
void |
writeLong(long l)
Write a long value.
|
void |
writeShort(int s)
Write a short value.
|
void |
writeUTF(java.lang.String s)
Write a string as a UTF.
|
public BufferedFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public BufferedFile(java.lang.String filename, java.lang.String mode) throws java.io.IOException
filename
- The file to be accessed.mode
- A string composed of "r" and "w" for
read and write access.java.io.IOException
public BufferedFile(java.io.File file) throws java.io.IOException
java.io.IOException
public BufferedFile(java.io.File file, java.lang.String mode) throws java.io.IOException
java.io.IOException
public BufferedFile(java.lang.String filename, java.lang.String mode, int bufferSize) throws java.io.IOException
filename
- The file to be accessed.mode
- A string composed of "r" and "w" indicating
read or write access.bufferSize
- The buffer size to be used. This should be
substantially larger than 100 bytes and
defaults to 32768 bytes in the other
constructors.java.io.IOException
public BufferedFile(java.io.File file, java.lang.String mode, int bufferSize) throws java.io.IOException
java.io.IOException
protected void initialize(java.io.File file, java.lang.String mode, int bufferSize) throws java.io.IOException
java.io.IOException
public int read(byte[] buf) throws java.io.IOException
read
in interface ArrayDataInput
buf
- The array to be filled.java.io.IOException
public int read(byte[] buf, int offset, int len) throws java.io.IOException
read
in interface ArrayDataInput
buf
- The array to be filled.offset
- The starting location for input.len
- The number of bytes to be read. Fewer bytes
will be read if an EOF is reached.java.io.IOException
public int read() throws java.io.IOException
java.io.IOException
public long skip(long offset) throws java.io.IOException
skip
in interface ArrayDataInput
offset
- The number of bytes from the
current position. This may
be negative.java.io.IOException
public void seek(long offsetFromStart) throws java.io.IOException
seek
in interface RandomAccess
java.io.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
public int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
public int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] b) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] b, int off, int len) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public int skipBytes(int toSkip) throws java.io.IOException
skipBytes
in interface java.io.DataInput
java.io.IOException
public long skipBytes(long toSkip) throws java.io.IOException
skipBytes
in interface ArrayDataInput
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public int readArray(java.lang.Object o) throws java.io.IOException
readArray
in interface ArrayDataInput
o
- The object to be read. It must be an array of a primitive type,
or an array of Object's.java.io.IOException
public long readLArray(java.lang.Object o) throws java.io.IOException
readLArray
in interface ArrayDataInput
o
- The object to be read. It must be an arraof of a primtive type
(or any dimension), or an array of Objects which contains
pointers to primitive arrays or other object arrays.java.io.IOException
protected long primitiveArrayRecurse(java.lang.Object o) throws java.io.IOException
java.io.IOException
public int read(boolean[] b) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(boolean[] b, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(short[] s) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(short[] s, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(char[] c) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(char[] c, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(int[] i) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(int[] i, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(long[] l) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(long[] l, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(float[] f) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(float[] f, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(double[] d) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(double[] d, int start, int length) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public void write(int buf) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] buf) throws java.io.IOException
write
in interface java.io.DataOutput
write
in interface ArrayDataOutput
java.io.IOException
public void write(byte[] buf, int offset, int length) throws java.io.IOException
write
in interface java.io.DataOutput
write
in interface ArrayDataOutput
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface ArrayDataOutput
java.io.IOException
protected void finalize()
finalize
in class java.lang.Object
public void writeBoolean(boolean b) throws java.io.IOException
writeBoolean
in interface java.io.DataOutput
b
- The value to be written. Externally true is represented as
a byte of 1 and false as a byte value of 0.java.io.IOException
public void writeByte(int b) throws java.io.IOException
writeByte
in interface java.io.DataOutput
java.io.IOException
public void writeInt(int i) throws java.io.IOException
writeInt
in interface java.io.DataOutput
java.io.IOException
public void writeShort(int s) throws java.io.IOException
writeShort
in interface java.io.DataOutput
java.io.IOException
public void writeChar(int c) throws java.io.IOException
writeChar
in interface java.io.DataOutput
java.io.IOException
public void writeLong(long l) throws java.io.IOException
writeLong
in interface java.io.DataOutput
java.io.IOException
public void writeFloat(float f) throws java.io.IOException
writeFloat
in interface java.io.DataOutput
java.io.IOException
public void writeDouble(double d) throws java.io.IOException
writeDouble
in interface java.io.DataOutput
java.io.IOException
public void writeBytes(java.lang.String s) throws java.io.IOException
writeBytes
in interface java.io.DataOutput
s
- The string to be written.java.io.IOException
public void writeChars(java.lang.String s) throws java.io.IOException
writeChars
in interface java.io.DataOutput
java.io.IOException
public void writeUTF(java.lang.String s) throws java.io.IOException
writeUTF
in interface java.io.DataOutput
java.io.IOException
public void writeArray(java.lang.Object o) throws java.io.IOException
writeArray
in interface ArrayDataOutput
o
- The object to be written. It must be an array of a primitive
type, Object, or String.java.io.IOException
- if the argument is not of the proper typepublic void write(boolean[] b) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(boolean[] b, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(short[] s) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(short[] s, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(char[] c) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(char[] c, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(int[] i) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(int[] i, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(long[] l) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(long[] l, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(float[] f) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(float[] f, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(double[] d) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(double[] d, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(java.lang.String[] s) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void write(java.lang.String[] s, int start, int length) throws java.io.IOException
write
in interface ArrayDataOutput
java.io.IOException
public void close() throws java.io.IOException
close
in interface ArrayDataInput
close
in interface ArrayDataOutput
java.io.IOException
public java.io.FileDescriptor getFD() throws java.io.IOException
java.io.IOException
public java.nio.channels.FileChannel getChannel()
public long length() throws java.io.IOException
java.io.IOException
public long getFilePointer()
getFilePointer
in interface RandomAccess
public void setLength(long newLength) throws java.io.IOException
newLength
- The number of bytes at which the file
is set.java.io.IOException