public class BufferedFile extends Object implements ArrayDataInput, ArrayDataOutput, RandomAccess
Constructor and Description |
---|
BufferedFile(String filename)
Create a read-only buffered file
|
BufferedFile(String filename,
String mode)
Create a buffered file with the given mode.
|
BufferedFile(String filename,
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
|
void |
flush()
Flush output buffer if necessary.
|
FileChannel |
getChannel()
Return the FileChannel associated with the file.
|
FileDescriptor |
getFD()
Get the file descriptor associated with
this stream.
|
long |
getFilePointer()
Get the current offset into the file.
|
long |
length()
Get the current length of the file.
|
protected int |
primitiveArrayRecurse(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(Object o)
This routine provides efficient reading of arrays of any primitive type.
|
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
|
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.
|
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.
|
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(String[] s)
Write an array of Strings -- equivalent to calling writeBytes for each string.
|
void |
write(String[] s,
int start,
int length) |
void |
writeArray(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(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(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(String s)
Write a string as a UTF.
|
public BufferedFile(String filename) throws IOException
IOException
public BufferedFile(String filename, String mode) throws IOException
filename
- The file to be accessed.mode
- A string composed of "r" and "w" for
read and write access.IOException
public BufferedFile(String filename, String mode, int bufferSize) throws IOException
filename
- The file to be accessed.mode
- A string composed of "r" and "w" indicating
read or write access.buffer
- The buffer size to be used. This should be
substantially larger than 100 bytes and
defaults to 32768 bytes in the other
constructors.IOException
public int read(byte[] buf) throws IOException
read
in interface ArrayDataInput
buf
- The array to be filled.IOException
public int read(byte[] buf, int offset, int len) throws IOException
read
in interface ArrayDataInput
buf
- The array to be filled.offset
- The starting location for input.length
- The number of bytes to be read. Fewer bytes
will be read if an EOF is reached.IOException
public int read() throws IOException
IOException
public long skip(long offset) throws IOException
skip
in interface ArrayDataInput
offset
- The number of bytes from the
current position. This may
be negative.IOException
public void seek(long offsetFromStart) throws IOException
seek
in interface RandomAccess
IOException
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public int skipBytes(int toSkip) throws IOException
skipBytes
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public String readLine() throws IOException
readLine
in interface DataInput
IOException
public int readArray(Object o) throws 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.IOException
protected int primitiveArrayRecurse(Object o) throws IOException
IOException
public int read(boolean[] b) throws IOException
read
in interface ArrayDataInput
IOException
public int read(boolean[] b, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public int read(short[] s) throws IOException
read
in interface ArrayDataInput
IOException
public int read(short[] s, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public int read(char[] c) throws IOException
read
in interface ArrayDataInput
IOException
public int read(char[] c, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public int read(int[] i) throws IOException
read
in interface ArrayDataInput
IOException
public int read(int[] i, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public int read(long[] l) throws IOException
read
in interface ArrayDataInput
IOException
public int read(long[] l, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public int read(float[] f) throws IOException
read
in interface ArrayDataInput
IOException
public int read(float[] f, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public int read(double[] d) throws IOException
read
in interface ArrayDataInput
IOException
public int read(double[] d, int start, int length) throws IOException
read
in interface ArrayDataInput
IOException
public void write(int buf) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] buf) throws IOException
write
in interface DataOutput
write
in interface ArrayDataOutput
IOException
public void write(byte[] buf, int offset, int length) throws IOException
write
in interface DataOutput
write
in interface ArrayDataOutput
IOException
public void flush() throws IOException
flush
in interface ArrayDataOutput
IOException
public void writeBoolean(boolean b) throws IOException
writeBoolean
in interface DataOutput
b
- The value to be written. Externally true is represented as
a byte of 1 and false as a byte value of 0.IOException
public void writeByte(int b) throws IOException
writeByte
in interface DataOutput
IOException
public void writeInt(int i) throws IOException
writeInt
in interface DataOutput
IOException
public void writeShort(int s) throws IOException
writeShort
in interface DataOutput
IOException
public void writeChar(int c) throws IOException
writeChar
in interface DataOutput
IOException
public void writeLong(long l) throws IOException
writeLong
in interface DataOutput
IOException
public void writeFloat(float f) throws IOException
writeFloat
in interface DataOutput
IOException
public void writeDouble(double d) throws IOException
writeDouble
in interface DataOutput
IOException
public void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
s
- The string to be written.IOException
public void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
public void writeUTF(String s) throws IOException
writeUTF
in interface DataOutput
IOException
public void writeArray(Object o) throws IOException
writeArray
in interface ArrayDataOutput
o
- The object to be written. It must be an array of a primitive
type, Object, or String.IOException
- if the argument is not of the proper typepublic void write(boolean[] b) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(boolean[] b, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(short[] s) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(short[] s, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(char[] c) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(char[] c, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(int[] i) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(int[] i, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(long[] l) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(long[] l, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(float[] f) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(float[] f, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(double[] d) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(double[] d, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(String[] s) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(String[] s, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void close() throws IOException
close
in interface ArrayDataInput
close
in interface ArrayDataOutput
IOException
public FileDescriptor getFD() throws IOException
IOException
public FileChannel getChannel()
public long length() throws IOException
IOException
public long getFilePointer()
getFilePointer
in interface RandomAccess
public void setLength(long newLength) throws IOException
newLength
- The number of bytes at which the file
is set.IOException
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.