public class BufferedFile extends java.lang.Object implements ArrayDataOutput, RandomAccess
BITS_OF_1_BYTE, BITS_OF_2_BYTES, BITS_OF_3_BYTES, BITS_OF_4_BYTES, BITS_OF_5_BYTES, BITS_OF_6_BYTES, BITS_OF_7_BYTES, BYTE_1_OF_LONG_MASK, BYTE_2_OF_LONG_MASK, BYTE_3_OF_LONG_MASK, BYTE_4_OF_LONG_MASK, BYTE_MASK, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_FLOAT, BYTES_IN_INTEGER, BYTES_IN_LONG, BYTES_IN_SHORT, HIGH_INTEGER_MASK, INTEGER_MASK, SHORT_MASK, SHORT_OF_LONG_MASK
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
dataBuffer.buffer size.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
void |
flush()
Flush the output buffer
|
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.
|
long |
length() |
void |
mark(int readlimit)
See the general contract of the
mark method of
InputStream . |
int |
read() |
int |
read(boolean[] b)
Read an array of boolean's.
|
int |
read(boolean[] b,
int start,
int length)
Read a segment of an array of boolean's.
|
int |
read(byte[] buf)
Read an array of byte's.
|
int |
read(byte[] buf,
int offset,
int len)
Read a segment of an array of byte's.
|
int |
read(char[] c)
Read an array of char's.
|
int |
read(char[] c,
int start,
int length)
Read a segment of an array of char's.
|
int |
read(double[] d)
Read an array of double's.
|
int |
read(double[] d,
int start,
int length)
Read a segment of an array of double's.
|
int |
read(float[] f)
Read an array of float's.
|
int |
read(float[] f,
int start,
int length)
Read a segment of an array of float's.
|
int |
read(int[] i)
Read an array of int's.
|
int |
read(int[] i,
int start,
int length)
Read a segment of an array of int's.
|
int |
read(long[] l)
Read a segment of an array of long's.
|
int |
read(long[] l,
int start,
int length)
Read a segment of an array of long's.
|
int |
read(short[] s)
Read an array of short's.
|
int |
read(short[] s,
int start,
int length)
Read a segment of an array of short's.
|
int |
readArray(java.lang.Object o)
Deprecated.
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len)
Read a buffer and signal an EOF if the requested elements cannot be read.
|
int |
readInt() |
long |
readLArray(java.lang.Object o)
Read an object.
|
java.lang.String |
readLine()
Read a line of input.
|
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
java.lang.String |
readUTF() |
void |
reset()
See the general contract of the
reset method of
InputStream . |
void |
seek(long offsetFromStart)
Move to a specified location in the stream.
|
void |
setLength(long newLength)
Set the length of the file.
|
long |
skip(long offset)
Skip the number of bytes.
|
void |
skipAllBytes(int toSkip)
Skip the number of bytes.
|
void |
skipAllBytes(long toSkip)
Skip the number of bytes.
|
int |
skipBytes(int n) |
void |
write(boolean[] b)
Write an array of boolean's.
|
void |
write(boolean[] b,
int start,
int length)
Write a segment of an array of boolean's.
|
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)
Write a segment of an array of char's.
|
void |
write(double[] d)
Write an array of double's.
|
void |
write(double[] d,
int start,
int length)
Write a segment of an array of double's.
|
void |
write(float[] f)
Write an array of float's.
|
void |
write(float[] f,
int start,
int length)
Write a segment of an array of float's.
|
void |
write(int buf) |
void |
write(int[] i)
Write an array of int's.
|
void |
write(int[] i,
int start,
int length)
Write a segment of an array of int's.
|
void |
write(long[] l)
Write an array of longs.
|
void |
write(long[] l,
int start,
int length)
Write a segment of an array of longs.
|
void |
write(short[] s)
Write an array of shorts.
|
void |
write(short[] s,
int start,
int length)
Write a segment of an array of shorts.
|
void |
write(java.lang.String[] s)
Write an array of Strings.
|
void |
write(java.lang.String[] s,
int start,
int length)
Write a segment of an array of Strings.
|
void |
writeArray(java.lang.Object o)
This routine provides efficient writing of arrays of any primitive type.
|
void |
writeBoolean(boolean b) |
void |
writeByte(int b) |
void |
writeBytes(java.lang.String s) |
void |
writeChar(int c) |
void |
writeChars(java.lang.String s) |
void |
writeDouble(double d) |
void |
writeFloat(float f) |
void |
writeInt(int i) |
void |
writeLong(long l) |
void |
writeShort(int s) |
void |
writeUTF(java.lang.String s) |
public BufferedFile(java.io.File file) throws java.io.IOException
file
- the file to open.java.io.IOException
- if the file could not be openedpublic BufferedFile(java.io.File file, java.lang.String mode) throws java.io.IOException
file
- the file to open.mode
- the mode to open the file injava.io.IOException
- if the file could not be openedpublic BufferedFile(java.io.File file, java.lang.String mode, int bufferSize) throws java.io.IOException
file
- the file to open.mode
- the mode to open the file inbufferSize
- the dataBuffer.buffer size to usejava.io.IOException
- if the file could not be openedpublic BufferedFile(java.lang.String filename) throws java.io.IOException
filename
- the name of the file to openjava.io.IOException
- if the file could not be openedpublic 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
- if the file could not be openedpublic 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 dataBuffer.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
- if the file could not be openedpublic void close() throws java.io.IOException
protected void finalize()
finalize
in class java.lang.Object
public void flush() throws java.io.IOException
ArrayDataOutput
flush
in interface ArrayDataOutput
java.io.IOException
- if the flush of the underlying stream failedpublic java.nio.channels.FileChannel getChannel()
public java.io.FileDescriptor getFD() throws java.io.IOException
java.io.IOException
- if the descriptor could not be accessed.public long getFilePointer()
getFilePointer
in interface RandomAccess
public long length() throws java.io.IOException
java.io.IOException
- if the operation failedpublic void mark(int readlimit) throws java.io.IOException
ArrayDataInput
mark
method of
InputStream
.mark
in interface ArrayDataInput
readlimit
- the maximum limit of bytes that can be read before the mark
position becomes invalid.java.io.IOException
- if the operation failedBufferedInputStream.reset()
public int read() throws java.io.IOException
java.io.IOException
- if the underlying read operation failspublic int read(boolean[] b) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
b
- array of boolean's.java.io.IOException
- if one of the underlying read operations failedpublic int read(boolean[] b, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
b
- array of boolean's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedpublic int read(byte[] buf) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
buf
- array of byte's.java.io.IOException
- if one of the underlying read operations failedDataInput.readFully(byte[])
public int read(byte[] buf, int offset, int len) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
buf
- array of byte's.offset
- start index in the arraylen
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedArrayDataInput.readFully(byte[], int, int)
public int read(char[] c) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
c
- array of char's.java.io.IOException
- if one of the underlying read operations failedpublic int read(char[] c, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
c
- array of char's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedpublic int read(double[] d) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
d
- array of double's.java.io.IOException
- if one of the underlying read operations failedpublic int read(double[] d, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
d
- array of double's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedpublic int read(float[] f) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
f
- array of float's.java.io.IOException
- if one of the underlying read operations failedpublic int read(float[] f, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
f
- array of float's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedpublic int read(int[] i) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
i
- array of int's.java.io.IOException
- if one of the underlying read operations failedpublic int read(int[] i, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
i
- array of int's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedpublic int read(long[] l) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
l
- array of long's.java.io.IOException
- if one of the underlying read operations failedpublic int read(long[] l, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
l
- array of long's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failedpublic int read(short[] s) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
s
- array of short's.java.io.IOException
- if one of the underlying read operations failedpublic int read(short[] s, int start, int length) throws java.io.IOException
ArrayDataInput
read
in interface ArrayDataInput
s
- array of short's.start
- start index in the arraylength
- number of array elements to readjava.io.IOException
- if one of the underlying read operations failed@Deprecated public int readArray(java.lang.Object o) throws java.io.IOException
ArrayDataInput
The ArrayDataInput classes do not support String input since it is unclear how one would read in an Array of strings.
readArray
in interface ArrayDataInput
o
- A [multidimensional] primitive (or Object) array.java.io.IOException
- if the underlying stream failedpublic 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 char readChar() throws java.io.IOException
readChar
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 float readFloat() throws java.io.IOException
readFloat
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
ArrayDataInput
readFully
in interface java.io.DataInput
readFully
in interface ArrayDataInput
b
- The input buffer.off
- The requested offset into the buffer.len
- The number of bytes requested.java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public long readLArray(java.lang.Object o) throws java.io.IOException
ArrayDataInput
readLArray
in interface ArrayDataInput
o
- The object to be read. This object should be a primitive
(possibly multi-dimensional) array.java.io.IOException
- if the underlying stream failedpublic java.lang.String readLine() throws java.io.IOException
readLine
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 short readShort() throws java.io.IOException
readShort
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 readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public void reset() throws java.io.IOException
ArrayDataInput
reset
method of
InputStream
.
If markpos
is -1
(no mark has been set or the
mark has been invalidated), an IOException
is thrown.
Otherwise, pos
is set equal to markpos
.
reset
in interface ArrayDataInput
java.io.IOException
- if this stream has not been marked or, if the mark has
been invalidated, or the stream has been closed by
invoking its FitsIO.close()
method, or an I/O error
occurs.BufferedInputStream.mark(int)
public void seek(long offsetFromStart) throws java.io.IOException
RandomAccess
seek
in interface RandomAccess
offsetFromStart
- set the offset messured from the startjava.io.IOException
- if the operation failspublic void setLength(long newLength) throws java.io.IOException
newLength
- The number of bytes at which the file is set.java.io.IOException
- if the resizing of the underlying stream failspublic long skip(long offset) throws java.io.IOException
ArrayDataInput
skip
in interface ArrayDataInput
offset
- the number of bytes to skipjava.io.IOException
- if the underlying stream failedpublic void skipAllBytes(int toSkip) throws java.io.IOException
ArrayDataInput
skipAllBytes
in interface ArrayDataInput
toSkip
- the number of bytes to skipjava.io.IOException
- if the underlying stream failedpublic void skipAllBytes(long toSkip) throws java.io.IOException
ArrayDataInput
skipAllBytes
in interface ArrayDataInput
toSkip
- the number of bytes to skipjava.io.IOException
- if the underlying stream failedpublic int skipBytes(int n) throws java.io.IOException
skipBytes
in interface java.io.DataInput
java.io.IOException
public void write(boolean[] b) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
b
- array of boolean's.java.io.IOException
- if one of the underlying write operations failedpublic void write(boolean[] b, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
b
- array of boolean's.start
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(byte[] buf) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] buf, int offset, int length) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(char[] c) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
c
- array of char's.java.io.IOException
- if one of the underlying write operations failedpublic void write(char[] c, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
c
- array of char's.start
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(double[] d) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
d
- array of double's.java.io.IOException
- if one of the underlying write operations failedpublic void write(double[] d, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
d
- array of double's.start
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(float[] f) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
f
- array of float's.java.io.IOException
- if one of the underlying write operations failedpublic void write(float[] f, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
f
- array of float's.start
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(int buf) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(int[] i) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
i
- array of int'sjava.io.IOException
- if one of the underlying write operations failedpublic void write(int[] i, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
i
- array of int'sstart
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(long[] l) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
l
- array of longsjava.io.IOException
- if one of the underlying write operations failedpublic void write(long[] l, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
l
- array of longsstart
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(short[] s) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
s
- the value to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(short[] s, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
s
- the value to writestart
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(java.lang.String[] s) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
s
- the array to writejava.io.IOException
- if one of the underlying write operations failedpublic void write(java.lang.String[] s, int start, int length) throws java.io.IOException
ArrayDataOutput
write
in interface ArrayDataOutput
s
- the array to writestart
- start index in the arraylength
- number of array elements to writejava.io.IOException
- if one of the underlying write operations failedpublic void writeArray(java.lang.Object o) throws java.io.IOException
ArrayDataOutput
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 one of the underlying write operations failedpublic void writeBoolean(boolean b) throws java.io.IOException
writeBoolean
in interface java.io.DataOutput
java.io.IOException
public void writeByte(int b) throws java.io.IOException
writeByte
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
java.io.IOException
public void writeChar(int c) throws java.io.IOException
writeChar
in interface java.io.DataOutput
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 writeDouble(double d) throws java.io.IOException
writeDouble
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 writeInt(int i) throws java.io.IOException
writeInt
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 writeShort(int s) throws java.io.IOException
writeShort
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