|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectuk.ac.starlink.fits.AbstractArrayDataIO
uk.ac.starlink.fits.MappedFile
public class MappedFile
Provides mapped access to a data buffer using a single mapped byte 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.
| 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()
|
protected byte |
get()
Reads one byte from the current position. |
protected void |
get(byte[] buf,
int offset,
int length)
Reads bytes into a buffer from the current position. |
long |
getFilePointer()
|
long |
length()
Returns the size of this buffer. |
protected void |
put(byte b)
Writes a single byte at the current position. |
protected void |
put(byte[] buf,
int offset,
int length)
Writes bytes from a buffer to the current position. |
protected long |
remaining()
Returns the number of bytes remaining between the current position and the end of the file. |
void |
seek(long offsetFromStart)
|
long |
skip(long offset)
|
int |
skipBytes(int toSkip)
|
| Methods inherited from class uk.ac.starlink.fits.AbstractArrayDataIO |
|---|
read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, readArray, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, writeArray, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface nom.tam.util.ArrayDataInput |
|---|
read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, readArray |
| Methods inherited from interface java.io.DataInput |
|---|
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF |
| Constructor Detail |
|---|
public MappedFile(ByteBuffer buf)
buf - byte buffer
public 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 map
IOException| Method Detail |
|---|
public void seek(long offsetFromStart)
throws IOException
seek in interface nom.tam.util.RandomAccessIOExceptionpublic long skip(long offset)
skip in interface nom.tam.util.ArrayDataInputpublic long getFilePointer()
getFilePointer in interface nom.tam.util.RandomAccesspublic int skipBytes(int toSkip)
skipBytes in interface DataInput
protected byte get()
throws IOException
AbstractArrayDataIO
get in class AbstractArrayDataIOIOException
protected void get(byte[] buf,
int offset,
int length)
throws IOException
AbstractArrayDataIO
get in class AbstractArrayDataIObuf - destination bufferoffset - offset of first byte in buf to be writtenlength - maximum number of bytes to be written to
buf
IOException
protected void put(byte b)
throws IOException
AbstractArrayDataIO
put in class AbstractArrayDataIOb - output byte
IOException
protected void put(byte[] buf,
int offset,
int length)
throws IOException
AbstractArrayDataIO
put in class AbstractArrayDataIObuf - source bufferoffset - offset of first byte in buf to be readlength - number of bytes from buf to be read
IOExceptionpublic long length()
AbstractArrayDataIO
length in class AbstractArrayDataIOprotected long remaining()
AbstractArrayDataIOLong.MAX_VALUE;
remaining in class AbstractArrayDataIOpublic void close()
close in interface nom.tam.util.ArrayDataInputclose in interface nom.tam.util.ArrayDataOutputpublic void flush()
flush in interface nom.tam.util.ArrayDataOutput
|
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 | ||||||||