|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.ac.starlink.fits.MappedFile
Provides mapped access to a data buffer, compatible with nom.tam.util classes. This class implements the nom.tam.util ArrayDataInput, ArrayDataOutput and RandomAccess interfaces in the same way that nom.tam.util.BufferedFile does. Hence it can be used as a drop-in replacement for BufferedFile. Unlike BufferedFile however, it does mapped access to files (using java.nio.Buffer objects). This may be moderately more efficient for sequential access to a file, but is dramatically more efficient if very random access is required. This is because BufferedFile effectively always assumes that you are going to read sequentially, so that accessing a single datum distant from (or before) the last datum accessed always results in filling a whole buffer.
The ArrayDataInput interface contains a lot of methods declared like
int read(type[]) throws IOException;whose behaviour is not documented - when do they throw an exception and what do they return? The behaviour implemented here follows that of the nom.tam.util.BufferedFile implementation (which is similarly undocumented). It is as follows:
Consult the BufferedFile
documentation for
more details.
Nested Class Summary | |
static class |
MappedFile.FileTooLongException
Exception indicating that a file is too long to map. |
Constructor Summary | |
MappedFile(ByteBuffer buf)
Constructs a MappedFile object from a byte buffer. |
|
MappedFile(String filename)
Constructs a MappedFile object by mapping the whole of an existing file using read-only mode. |
|
MappedFile(String filename,
String mode)
Constructs a MappedFile object by mapping the whole of an existing file with a given mode. |
|
MappedFile(String filename,
String mode,
long start,
int size)
Constructs a MappedFile object by mapping part of an existing file with a given mode. |
Method Summary | |
void |
close()
|
void |
flush()
|
long |
getFilePointer()
|
int |
length()
Returns the length of the file. |
int |
read(boolean[] buf)
|
int |
read(boolean[] buf,
int start,
int length)
|
int |
read(byte[] buf)
|
int |
read(byte[] buf,
int start,
int length)
|
int |
read(char[] buf)
|
int |
read(char[] buf,
int start,
int length)
|
int |
read(double[] buf)
|
int |
read(double[] buf,
int start,
int length)
|
int |
read(float[] buf)
|
int |
read(float[] buf,
int start,
int length)
|
int |
read(int[] buf)
|
int |
read(int[] buf,
int start,
int length)
|
int |
read(long[] buf)
|
int |
read(long[] buf,
int start,
int length)
|
int |
read(short[] buf)
|
int |
read(short[] buf,
int start,
int length)
|
int |
readArray(Object o)
|
boolean |
readBoolean()
|
byte |
readByte()
|
char |
readChar()
|
double |
readDouble()
|
float |
readFloat()
|
void |
readFully(byte[] buf)
|
void |
readFully(byte[] buf,
int start,
int len)
Reads a specified number of bytes into an array. |
int |
readInt()
|
String |
readLine()
Deprecated. see DataInputStream.readLine() |
long |
readLong()
|
short |
readShort()
|
int |
readUnsignedByte()
|
int |
readUnsignedShort()
|
String |
readUTF()
|
void |
seek(long offsetFromStart)
|
long |
skip(long offset)
|
int |
skipBytes(int toSkip)
|
void |
write(boolean[] buf)
|
void |
write(boolean[] buf,
int start,
int length)
|
void |
write(byte[] buf)
|
void |
write(byte[] buf,
int start,
int length)
|
void |
write(char[] buf)
|
void |
write(char[] buf,
int start,
int length)
|
void |
write(double[] buf)
|
void |
write(double[] buf,
int start,
int length)
|
void |
write(float[] buf)
|
void |
write(float[] buf,
int start,
int length)
|
void |
write(int val)
|
void |
write(int[] buf)
|
void |
write(int[] buf,
int start,
int length)
|
void |
write(long[] buf)
|
void |
write(long[] buf,
int start,
int length)
|
void |
write(short[] buf)
|
void |
write(short[] buf,
int start,
int length)
|
void |
write(String[] strings)
|
void |
write(String[] strings,
int start,
int length)
|
void |
writeArray(Object o)
|
void |
writeBoolean(boolean val)
|
void |
writeByte(int val)
|
void |
writeBytes(String s)
|
void |
writeChar(int val)
|
void |
writeChars(String s)
|
void |
writeDouble(double val)
|
void |
writeFloat(float val)
|
void |
writeInt(int val)
|
void |
writeLong(long val)
|
void |
writeShort(int val)
|
void |
writeUTF(String str)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MappedFile(ByteBuffer buf)
buf
- byte bufferpublic MappedFile(String filename) throws IOException
filename
- name of the file to map
MappedFile.FileTooLongException
- if the file is too long to map
IOException
public MappedFile(String filename, String mode) throws IOException
filename
- name of the file to mapmode
- mode
MappedFile.FileTooLongException
- if the file is too long to map
IOException
public MappedFile(String filename, String mode, long start, int size) throws IOException
filename
- name of the file to mapmode
- modestart
- offset of region to mapsize
- length of region to mapMethod Detail |
public void seek(long offsetFromStart) throws IOException
seek
in interface RandomAccess
IOException
public long skip(long offset)
skip
in interface ArrayDataInput
public long getFilePointer()
getFilePointer
in interface RandomAccess
public int skipBytes(int toSkip)
skipBytes
in interface DataInput
public int length()
public void close()
close
in interface ArrayDataInput
public void flush()
flush
in interface ArrayDataOutput
public boolean readBoolean() throws EOFException
readBoolean
in interface DataInput
EOFException
public byte readByte() throws EOFException
readByte
in interface DataInput
EOFException
public short readShort() throws EOFException
readShort
in interface DataInput
EOFException
public char readChar() throws EOFException
readChar
in interface DataInput
EOFException
public int readInt() throws EOFException
readInt
in interface DataInput
EOFException
public long readLong() throws EOFException
readLong
in interface DataInput
EOFException
public float readFloat() throws EOFException
readFloat
in interface DataInput
EOFException
public double readDouble() throws EOFException
readDouble
in interface DataInput
EOFException
public int readUnsignedByte() throws EOFException
readUnsignedByte
in interface DataInput
EOFException
public int readUnsignedShort() throws EOFException
readUnsignedShort
in interface DataInput
EOFException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public String readLine() throws IOException
DataInputStream.readLine()
readLine
in interface DataInput
UnsupportedOperationException
IOException
public void readFully(byte[] buf, int start, int len) throws EOFException
readFully
in interface DataInput
buf
- the byte buffer into which to readstart
- the index in buf at which to start putting byteslen
- the number of bytes which must be read
EOFException
- if there are fewer than len bytes leftpublic int read(byte[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(boolean[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(short[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(char[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(int[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(long[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(float[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(double[] buf, int start, int length) throws EOFException
read
in interface ArrayDataInput
EOFException
public void readFully(byte[] buf) throws EOFException
readFully
in interface DataInput
EOFException
public int read(byte[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(boolean[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(short[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(char[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(int[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(long[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(float[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int read(double[] buf) throws EOFException
read
in interface ArrayDataInput
EOFException
public int readArray(Object o) throws EOFException
readArray
in interface ArrayDataInput
EOFException
public void writeBoolean(boolean val) throws IOException
writeBoolean
in interface DataOutput
IOException
public void writeByte(int val) throws IOException
writeByte
in interface DataOutput
IOException
public void writeShort(int val) throws IOException
writeShort
in interface DataOutput
IOException
public void writeChar(int val) throws IOException
writeChar
in interface DataOutput
IOException
public void writeInt(int val) throws IOException
writeInt
in interface DataOutput
IOException
public void writeLong(long val) throws IOException
writeLong
in interface DataOutput
IOException
public void writeFloat(float val) throws IOException
writeFloat
in interface DataOutput
IOException
public void writeDouble(double val) throws IOException
writeDouble
in interface DataOutput
IOException
public void write(byte[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(boolean[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(short[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(char[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(int[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(long[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(float[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(double[] buf, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(String[] strings, int start, int length) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(int val) throws IOException
write
in interface DataOutput
IOException
public void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
IOException
public void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
public void writeUTF(String str) throws IOException
writeUTF
in interface DataOutput
IOException
public void write(byte[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(boolean[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(short[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(char[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(int[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(long[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(float[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(double[] buf) throws IOException
write
in interface ArrayDataOutput
IOException
public void write(String[] strings) throws IOException
write
in interface ArrayDataOutput
IOException
public void writeArray(Object o) throws IOException
writeArray
in interface ArrayDataOutput
IOException
|
Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |