public class ArrayFile extends java.lang.Object implements ArrayInput, ArrayOutput, java.io.Closeable
RandomAccessFile
.
Specifically, an array file has methods for efficiently reading and writing
arrays of primitive values, such as ints and floats. Also, array files may
be read or written with either BIG_ENDIAN or LITTLE_ENDIAN byte orders.
An array file implements the interfaces ArrayInput
and
ArrayOutput
, which extend the standard Java interfaces
DataInput
and DataOutput
, respectively.
An array file can be constructed by specifying a file name and access mode
(as for a RandomAccessFile
). Alternatively, an array file
can be constructed from an existing RandomAccessFile
.
Constructor and Description |
---|
ArrayFile(java.io.File file,
java.lang.String mode)
Constructs an array file with specified file and access mode.
|
ArrayFile(java.io.File file,
java.lang.String mode,
java.nio.ByteOrder bor,
java.nio.ByteOrder bow)
Constructs an array file with specified file, access mode, and byte orders.
|
ArrayFile(java.io.RandomAccessFile raf,
java.nio.ByteOrder bor,
java.nio.ByteOrder bow)
Constructs an array file for a specified random-access file
and byte orders.
|
ArrayFile(java.lang.String name,
java.lang.String mode)
Constructs an array file with specified name and access mode.
|
ArrayFile(java.lang.String name,
java.lang.String mode,
java.nio.ByteOrder bor,
java.nio.ByteOrder bow)
Constructs an array file with specified name, access mode, and byte orders.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this data file, releasing any associated system resources.
|
java.nio.ByteOrder |
getByteOrderRead()
Gets the byte order for reading data.
|
java.nio.ByteOrder |
getByteOrderWrite()
Gets the byte order for writing data.
|
long |
getFilePointer()
Gets the file pointer (byte offset) for this file.
|
long |
length()
Returns the length of 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) |
public ArrayFile(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 ArrayFile(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 ArrayFile(java.lang.String name, java.lang.String mode, java.nio.ByteOrder bor, java.nio.ByteOrder bow) throws java.io.FileNotFoundException
name
- the file name.mode
- the access mode; "r", "rw", "rws", or "rwd".bor
- the byte order for reading.bow
- the byte order for writing.java.io.FileNotFoundException
public ArrayFile(java.io.File file, java.lang.String mode, java.nio.ByteOrder bor, java.nio.ByteOrder bow) throws java.io.FileNotFoundException
file
- the file.mode
- the access mode; "r", "rw", "rws", or "rwd".bor
- the byte order for reading.bow
- the byte order for writing.java.io.FileNotFoundException
public ArrayFile(java.io.RandomAccessFile raf, java.nio.ByteOrder bor, java.nio.ByteOrder bow)
raf
- the random-access file.bor
- the byte order for reading.bow
- the byte order for writing.public java.nio.ByteOrder getByteOrderRead()
public java.nio.ByteOrder getByteOrderWrite()
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 ArrayInput
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 ArrayInput
readFully
in interface java.io.DataInput
java.io.IOException
public int skipBytes(int n) throws java.io.IOException
skipBytes
in interface ArrayInput
skipBytes
in interface java.io.DataInput
java.io.IOException
public void write(int b) throws java.io.IOException
write
in interface ArrayOutput
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in interface ArrayOutput
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in interface ArrayOutput
write
in interface java.io.DataOutput
java.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.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public final boolean readBoolean() throws java.io.IOException
readBoolean
in interface ArrayInput
readBoolean
in interface java.io.DataInput
java.io.IOException
public final byte readByte() throws java.io.IOException
readByte
in interface ArrayInput
readByte
in interface java.io.DataInput
java.io.IOException
public final int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface ArrayInput
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public final short readShort() throws java.io.IOException
readShort
in interface ArrayInput
readShort
in interface java.io.DataInput
java.io.IOException
public final int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface ArrayInput
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public final char readChar() throws java.io.IOException
readChar
in interface ArrayInput
readChar
in interface java.io.DataInput
java.io.IOException
public final int readInt() throws java.io.IOException
readInt
in interface ArrayInput
readInt
in interface java.io.DataInput
java.io.IOException
public final long readLong() throws java.io.IOException
readLong
in interface ArrayInput
readLong
in interface java.io.DataInput
java.io.IOException
public final float readFloat() throws java.io.IOException
readFloat
in interface ArrayInput
readFloat
in interface java.io.DataInput
java.io.IOException
public final double readDouble() throws java.io.IOException
readDouble
in interface ArrayInput
readDouble
in interface java.io.DataInput
java.io.IOException
public final java.lang.String readLine() throws java.io.IOException
readLine
in interface ArrayInput
readLine
in interface java.io.DataInput
java.io.IOException
public final java.lang.String readUTF() throws java.io.IOException
readUTF
in interface ArrayInput
readUTF
in interface java.io.DataInput
java.io.IOException
public void writeBoolean(boolean v) throws java.io.IOException
writeBoolean
in interface ArrayOutput
writeBoolean
in interface java.io.DataOutput
java.io.IOException
public void writeByte(int v) throws java.io.IOException
writeByte
in interface ArrayOutput
writeByte
in interface java.io.DataOutput
java.io.IOException
public void writeShort(int v) throws java.io.IOException
writeShort
in interface ArrayOutput
writeShort
in interface java.io.DataOutput
java.io.IOException
public void writeChar(int v) throws java.io.IOException
writeChar
in interface ArrayOutput
writeChar
in interface java.io.DataOutput
java.io.IOException
public void writeInt(int v) throws java.io.IOException
writeInt
in interface ArrayOutput
writeInt
in interface java.io.DataOutput
java.io.IOException
public void writeLong(long v) throws java.io.IOException
writeLong
in interface ArrayOutput
writeLong
in interface java.io.DataOutput
java.io.IOException
public void writeFloat(float v) throws java.io.IOException
writeFloat
in interface ArrayOutput
writeFloat
in interface java.io.DataOutput
java.io.IOException
public void writeDouble(double v) throws java.io.IOException
writeDouble
in interface ArrayOutput
writeDouble
in interface java.io.DataOutput
java.io.IOException
public void writeBytes(java.lang.String s) throws java.io.IOException
writeBytes
in interface ArrayOutput
writeBytes
in interface java.io.DataOutput
java.io.IOException
public void writeChars(java.lang.String s) throws java.io.IOException
writeChars
in interface ArrayOutput
writeChars
in interface java.io.DataOutput
java.io.IOException
public void writeUTF(java.lang.String s) throws java.io.IOException
writeUTF
in interface ArrayOutput
writeUTF
in interface java.io.DataOutput
java.io.IOException
public void readBytes(byte[] v, int k, int n) throws java.io.IOException
readBytes
in interface ArrayInput
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
readBytes
in interface ArrayInput
v
- the array.java.io.IOException
public void readBytes(byte[][] v) throws java.io.IOException
readBytes
in interface ArrayInput
v
- the array.java.io.IOException
public void readBytes(byte[][][] v) throws java.io.IOException
readBytes
in interface ArrayInput
v
- the array.java.io.IOException
public void readChars(char[] v, int k, int n) throws java.io.IOException
readChars
in interface ArrayInput
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
readChars
in interface ArrayInput
v
- the array.java.io.IOException
public void readChars(char[][] v) throws java.io.IOException
readChars
in interface ArrayInput
v
- the array.java.io.IOException
public void readChars(char[][][] v) throws java.io.IOException
readChars
in interface ArrayInput
v
- the array.java.io.IOException
public void readShorts(short[] v, int k, int n) throws java.io.IOException
readShorts
in interface ArrayInput
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
readShorts
in interface ArrayInput
v
- the array.java.io.IOException
public void readShorts(short[][] v) throws java.io.IOException
readShorts
in interface ArrayInput
v
- the array.java.io.IOException
public void readShorts(short[][][] v) throws java.io.IOException
readShorts
in interface ArrayInput
v
- the array.java.io.IOException
public void readInts(int[] v, int k, int n) throws java.io.IOException
readInts
in interface ArrayInput
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
readInts
in interface ArrayInput
v
- the array.java.io.IOException
public void readInts(int[][] v) throws java.io.IOException
readInts
in interface ArrayInput
v
- the array.java.io.IOException
public void readInts(int[][][] v) throws java.io.IOException
readInts
in interface ArrayInput
v
- the array.java.io.IOException
public void readLongs(long[] v, int k, int n) throws java.io.IOException
readLongs
in interface ArrayInput
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
readLongs
in interface ArrayInput
v
- the array.java.io.IOException
public void readLongs(long[][] v) throws java.io.IOException
readLongs
in interface ArrayInput
v
- the array.java.io.IOException
public void readLongs(long[][][] v) throws java.io.IOException
readLongs
in interface ArrayInput
v
- the array.java.io.IOException
public void readFloats(float[] v, int k, int n) throws java.io.IOException
readFloats
in interface ArrayInput
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
readFloats
in interface ArrayInput
v
- the array.java.io.IOException
public void readFloats(float[][] v) throws java.io.IOException
readFloats
in interface ArrayInput
v
- the array.java.io.IOException
public void readFloats(float[][][] v) throws java.io.IOException
readFloats
in interface ArrayInput
v
- the array.java.io.IOException
public void readDoubles(double[] v, int k, int n) throws java.io.IOException
readDoubles
in interface ArrayInput
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
readDoubles
in interface ArrayInput
v
- the array.java.io.IOException
public void readDoubles(double[][] v) throws java.io.IOException
readDoubles
in interface ArrayInput
v
- the array.java.io.IOException
public void readDoubles(double[][][] v) throws java.io.IOException
readDoubles
in interface ArrayInput
v
- the array.java.io.IOException
public void writeBytes(byte[] v, int k, int n) throws java.io.IOException
writeBytes
in interface ArrayOutput
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
writeBytes
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeBytes(byte[][] v) throws java.io.IOException
writeBytes
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeBytes(byte[][][] v) throws java.io.IOException
writeBytes
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeChars(char[] v, int k, int n) throws java.io.IOException
writeChars
in interface ArrayOutput
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
writeChars
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeChars(char[][] v) throws java.io.IOException
writeChars
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeChars(char[][][] v) throws java.io.IOException
writeChars
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeShorts(short[] v, int k, int n) throws java.io.IOException
writeShorts
in interface ArrayOutput
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
writeShorts
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeShorts(short[][] v) throws java.io.IOException
writeShorts
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeShorts(short[][][] v) throws java.io.IOException
writeShorts
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeInts(int[] v, int k, int n) throws java.io.IOException
writeInts
in interface ArrayOutput
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
writeInts
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeInts(int[][] v) throws java.io.IOException
writeInts
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeInts(int[][][] v) throws java.io.IOException
writeInts
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeLongs(long[] v, int k, int n) throws java.io.IOException
writeLongs
in interface ArrayOutput
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
writeLongs
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeLongs(long[][] v) throws java.io.IOException
writeLongs
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeLongs(long[][][] v) throws java.io.IOException
writeLongs
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeFloats(float[] v, int k, int n) throws java.io.IOException
writeFloats
in interface ArrayOutput
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
writeFloats
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeFloats(float[][] v) throws java.io.IOException
writeFloats
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeFloats(float[][][] v) throws java.io.IOException
writeFloats
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeDoubles(double[] v, int k, int n) throws java.io.IOException
writeDoubles
in interface ArrayOutput
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
writeDoubles
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeDoubles(double[][] v) throws java.io.IOException
writeDoubles
in interface ArrayOutput
v
- the array.java.io.IOException
public void writeDoubles(double[][][] v) throws java.io.IOException
writeDoubles
in interface ArrayOutput
v
- the array.java.io.IOException