|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.mines.jtk.io.DataFile
public class DataFile
A data file has the capabilities of a RandomAccessFile,
and more. For example, a data file has methods for efficiently reading
and writing arrays of primitive values, such as ints and floats. Also,
data files may be read or written with BIG_ENDIAN or LITTLE_ENDIAN byte
orders. In other words, a data file is a better random access file.
A data file implements the interfaces DataInput and
DataOutput. Those interfaces specify methods for reading
single primitive values; e.g., DataInput.readFloat().
Similar methods are specified for writing single primitive values. When
reading or writing arrays of primitive values, calling those methods
for each array element can be inefficient. Therefore, this class also
provides methods that read and write arrays of primitive values in one
call.
For efficiency, some software systems read and write primitive values using the native byte order of the hardware. That byte order may be BIG_ENDIAN or LITTLE_ENDIAN, and may be specified when constructing a data file.
| Nested Class Summary | |
|---|---|
static class |
DataFile.ByteOrder
The byte order of the file. |
| Constructor Summary | |
|---|---|
DataFile(java.io.File file,
java.lang.String mode)
Constructs a data file with specified file and access mode. |
|
DataFile(java.io.File file,
java.lang.String mode,
DataFile.ByteOrder order)
Constructs a data file with specified file, access mode, and byte order. |
|
DataFile(java.lang.String name,
java.lang.String mode)
Constructs a data file with specified name and access mode. |
|
DataFile(java.lang.String name,
java.lang.String mode,
DataFile.ByteOrder order)
Constructs a data file with specified name, access mode, and byte order. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this data file, releasing any associated system resources. |
DataFile.ByteOrder |
getByteOrder()
Gets the byte order for this data file. |
java.nio.channels.FileChannel |
getChannel()
Gets the file channel for this data file. |
java.io.FileDescriptor |
getFD()
Gets the file descripter for this data file. |
long |
getFilePointer()
Gets the file pointer (byte offset) for this file. |
long |
length()
Returns the length of this file. |
static DataFile.ByteOrder |
nativeByteOrder()
Returns the native byte order for the platform with this file. |
int |
read()
Reads a byte value from this file. |
int |
read(byte[] b)
Reads up to b.length bytes from this file. |
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes from this file. |
boolean |
readBoolean()
|
byte |
readByte()
|
void |
readBytes(byte[] v)
Reads byte elements into a specified array. |
void |
readBytes(byte[][] v)
Reads byte elements into a specified array. |
void |
readBytes(byte[][][] v)
Reads byte elements into a specified array. |
void |
readBytes(byte[] v,
int k,
int n)
Reads byte elements into a specified array. |
char |
readChar()
|
void |
readChars(char[] v)
Reads char elements into a specified array. |
void |
readChars(char[][] v)
Reads char elements into a specified array. |
void |
readChars(char[][][] v)
Reads char elements into a specified array. |
void |
readChars(char[] v,
int k,
int n)
Reads char elements into a specified array. |
double |
readDouble()
|
void |
readDoubles(double[] v)
Reads double elements into a specified array. |
void |
readDoubles(double[][] v)
Reads double elements into a specified array. |
void |
readDoubles(double[][][] v)
Reads double elements into a specified array. |
void |
readDoubles(double[] v,
int k,
int n)
Reads double elements into a specified array. |
float |
readFloat()
|
void |
readFloats(float[] v)
Reads float elements into a specified array. |
void |
readFloats(float[][] v)
Reads float elements into a specified array. |
void |
readFloats(float[][][] v)
Reads float elements into a specified array. |
void |
readFloats(float[] v,
int k,
int n)
Reads float elements into a specified array. |
void |
readFully(byte[] b)
|
void |
readFully(byte[] b,
int off,
int len)
|
int |
readInt()
|
void |
readInts(int[] v)
Reads int elements into a specified array. |
void |
readInts(int[][] v)
Reads int elements into a specified array. |
void |
readInts(int[][][] v)
Reads int elements into a specified array. |
void |
readInts(int[] v,
int k,
int n)
Reads int elements into a specified array. |
java.lang.String |
readLine()
|
long |
readLong()
|
void |
readLongs(long[] v)
Reads long elements into a specified array. |
void |
readLongs(long[][] v)
Reads long elements into a specified array. |
void |
readLongs(long[][][] v)
Reads long elements into a specified array. |
void |
readLongs(long[] v,
int k,
int n)
Reads long elements into a specified array. |
short |
readShort()
|
void |
readShorts(short[] v)
Reads short elements into a specified array. |
void |
readShorts(short[][] v)
Reads short elements into a specified array. |
void |
readShorts(short[][][] v)
Reads short elements into a specified array. |
void |
readShorts(short[] v,
int k,
int n)
Reads short elements into a specified array. |
int |
readUnsignedByte()
|
int |
readUnsignedShort()
|
java.lang.String |
readUTF()
|
void |
seek(long off)
Sets the file pointer (byte offset) for this file. |
void |
setLength(long newLength)
Sets the length of this file. |
int |
skipBytes(int n)
|
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
void |
writeBoolean(boolean v)
|
void |
writeByte(int v)
|
void |
writeBytes(byte[] v)
Writes byte elements from a specified array. |
void |
writeBytes(byte[][] v)
Writes byte elements from a specified array. |
void |
writeBytes(byte[][][] v)
Writes byte elements from a specified array. |
void |
writeBytes(byte[] v,
int k,
int n)
Writes byte elements from a specified array. |
void |
writeBytes(java.lang.String s)
|
void |
writeChar(int v)
|
void |
writeChars(char[] v)
Writes char elements from a specified array. |
void |
writeChars(char[][] v)
Writes char elements from a specified array. |
void |
writeChars(char[][][] v)
Writes char elements from a specified array. |
void |
writeChars(char[] v,
int k,
int n)
Writes char elements from a specified array. |
void |
writeChars(java.lang.String s)
|
void |
writeDouble(double v)
|
void |
writeDoubles(double[] v)
Writes double elements from a specified array. |
void |
writeDoubles(double[][] v)
Writes double elements from a specified array. |
void |
writeDoubles(double[][][] v)
Writes double elements from a specified array. |
void |
writeDoubles(double[] v,
int k,
int n)
Writes double elements from a specified array. |
void |
writeFloat(float v)
|
void |
writeFloats(float[] v)
Writes float elements from a specified array. |
void |
writeFloats(float[][] v)
Writes float elements from a specified array. |
void |
writeFloats(float[][][] v)
Writes float elements from a specified array. |
void |
writeFloats(float[] v,
int k,
int n)
Writes float elements from a specified array. |
void |
writeInt(int v)
|
void |
writeInts(int[] v)
Writes int elements from a specified array. |
void |
writeInts(int[][] v)
Writes int elements from a specified array. |
void |
writeInts(int[][][] v)
Writes int elements from a specified array. |
void |
writeInts(int[] v,
int k,
int n)
Writes int elements from a specified array. |
void |
writeLong(long v)
|
void |
writeLongs(long[] v)
Writes long elements from a specified array. |
void |
writeLongs(long[][] v)
Writes long elements from a specified array. |
void |
writeLongs(long[][][] v)
Writes long elements from a specified array. |
void |
writeLongs(long[] v,
int k,
int n)
Writes long elements from a specified array. |
void |
writeShort(int v)
|
void |
writeShorts(short[] v)
Writes shorts elements from a specified array. |
void |
writeShorts(short[][] v)
Writes short elements from a specified array. |
void |
writeShorts(short[][][] v)
Writes short elements from a specified array. |
void |
writeShorts(short[] v,
int k,
int n)
Writes short elements from a specified array. |
void |
writeUTF(java.lang.String s)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DataFile(java.lang.String name,
java.lang.String mode)
throws java.io.FileNotFoundException
name - the file name.mode - the access mode; "r", "rw", "rws", or "rwd".
java.io.FileNotFoundException
public DataFile(java.io.File file,
java.lang.String mode)
throws java.io.FileNotFoundException
file - the file.mode - the access mode; "r", "rw", "rws", or "rwd".
java.io.FileNotFoundException
public DataFile(java.lang.String name,
java.lang.String mode,
DataFile.ByteOrder order)
throws java.io.FileNotFoundException
name - the file name.mode - the access mode; "r", "rw", "rws", or "rwd".order - the byte order.
java.io.FileNotFoundException
public DataFile(java.io.File file,
java.lang.String mode,
DataFile.ByteOrder order)
throws java.io.FileNotFoundException
file - the file.mode - the access mode; "r", "rw", "rws", or "rwd".order - the byte order.
java.io.FileNotFoundException| Method Detail |
|---|
public static DataFile.ByteOrder nativeByteOrder()
public final java.io.FileDescriptor getFD()
throws java.io.IOException
java.io.IOExceptionpublic final java.nio.channels.FileChannel getChannel()
public DataFile.ByteOrder getByteOrder()
public int read()
throws java.io.IOException
java.io.IOException
public int read(byte[] b)
throws java.io.IOException
b - array into which to read bytes.
java.io.IOException
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
b - array into which to read bytes.off - array index of first byte to read.len - the number of bytes to read.
java.io.IOException
public void readFully(byte[] b)
throws java.io.IOException
readFully in interface java.io.DataInputjava.io.IOException
public void readFully(byte[] b,
int off,
int len)
throws java.io.IOException
readFully in interface java.io.DataInputjava.io.IOException
public int skipBytes(int n)
throws java.io.IOException
skipBytes in interface java.io.DataInputjava.io.IOException
public void write(int b)
throws java.io.IOException
write in interface java.io.DataOutputjava.io.IOException
public void write(byte[] b)
throws java.io.IOException
write in interface java.io.DataOutputjava.io.IOException
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in interface java.io.DataOutputjava.io.IOException
public long getFilePointer()
throws java.io.IOException
java.io.IOException
public void seek(long off)
throws java.io.IOException
The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not increase the file length. The file length increases only by writing beyond the end of the file.
off - the file pointer, the offset in bytes from the
beginning of the file.
java.io.IOException
public long length()
throws java.io.IOException
java.io.IOException
public void setLength(long newLength)
throws java.io.IOException
If the current file length is less than the specified new length, then this file will extended. The content of the extended portion is undefined.
newLength - the new length.
java.io.IOException
public void close()
throws java.io.IOException
close in interface java.io.Closeablejava.io.IOException
public final boolean readBoolean()
throws java.io.IOException
readBoolean in interface java.io.DataInputjava.io.IOException
public final byte readByte()
throws java.io.IOException
readByte in interface java.io.DataInputjava.io.IOException
public final int readUnsignedByte()
throws java.io.IOException
readUnsignedByte in interface java.io.DataInputjava.io.IOException
public final short readShort()
throws java.io.IOException
readShort in interface java.io.DataInputjava.io.IOException
public final int readUnsignedShort()
throws java.io.IOException
readUnsignedShort in interface java.io.DataInputjava.io.IOException
public final char readChar()
throws java.io.IOException
readChar in interface java.io.DataInputjava.io.IOException
public final int readInt()
throws java.io.IOException
readInt in interface java.io.DataInputjava.io.IOException
public final long readLong()
throws java.io.IOException
readLong in interface java.io.DataInputjava.io.IOException
public final float readFloat()
throws java.io.IOException
readFloat in interface java.io.DataInputjava.io.IOException
public final double readDouble()
throws java.io.IOException
readDouble in interface java.io.DataInputjava.io.IOException
public final java.lang.String readLine()
throws java.io.IOException
readLine in interface java.io.DataInputjava.io.IOException
public final java.lang.String readUTF()
throws java.io.IOException
readUTF in interface java.io.DataInputjava.io.IOException
public void writeBoolean(boolean v)
throws java.io.IOException
writeBoolean in interface java.io.DataOutputjava.io.IOException
public void writeByte(int v)
throws java.io.IOException
writeByte in interface java.io.DataOutputjava.io.IOException
public void writeShort(int v)
throws java.io.IOException
writeShort in interface java.io.DataOutputjava.io.IOException
public void writeChar(int v)
throws java.io.IOException
writeChar in interface java.io.DataOutputjava.io.IOException
public void writeInt(int v)
throws java.io.IOException
writeInt in interface java.io.DataOutputjava.io.IOException
public void writeLong(long v)
throws java.io.IOException
writeLong in interface java.io.DataOutputjava.io.IOException
public void writeFloat(float v)
throws java.io.IOException
writeFloat in interface java.io.DataOutputjava.io.IOException
public void writeDouble(double v)
throws java.io.IOException
writeDouble in interface java.io.DataOutputjava.io.IOException
public void writeBytes(java.lang.String s)
throws java.io.IOException
writeBytes in interface java.io.DataOutputjava.io.IOException
public void writeChars(java.lang.String s)
throws java.io.IOException
writeChars in interface java.io.DataOutputjava.io.IOException
public void writeUTF(java.lang.String s)
throws java.io.IOException
writeUTF in interface java.io.DataOutputjava.io.IOException
public void readBytes(byte[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readBytes(byte[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readBytes(byte[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readBytes(byte[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readChars(char[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readChars(char[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readChars(char[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readChars(char[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readShorts(short[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readShorts(short[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readShorts(short[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readShorts(short[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readInts(int[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readInts(int[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readInts(int[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readInts(int[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readLongs(long[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readLongs(long[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readLongs(long[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readLongs(long[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readFloats(float[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readFloats(float[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readFloats(float[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readFloats(float[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readDoubles(double[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to read.n - the number of elements to read.
java.io.IOException
public void readDoubles(double[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readDoubles(double[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void readDoubles(double[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeBytes(byte[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeBytes(byte[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeBytes(byte[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeBytes(byte[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeChars(char[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeChars(char[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeChars(char[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeChars(char[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeShorts(short[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeShorts(short[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeShorts(short[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeShorts(short[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeInts(int[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeInts(int[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeInts(int[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeInts(int[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeLongs(long[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeLongs(long[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeLongs(long[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeLongs(long[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeFloats(float[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeFloats(float[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeFloats(float[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeFloats(float[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeDoubles(double[] v,
int k,
int n)
throws java.io.IOException
v - the array.k - the index of the first element to write.n - the number of elements to write.
java.io.IOException
public void writeDoubles(double[] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeDoubles(double[][] v)
throws java.io.IOException
v - the array.
java.io.IOException
public void writeDoubles(double[][][] v)
throws java.io.IOException
v - the array.
java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||