ucar.unidata.io
Class MMapRandomAccessFile

java.lang.Object
  extended by ucar.unidata.io.RandomAccessFile
      extended by ucar.unidata.io.MMapRandomAccessFile
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput

public class MMapRandomAccessFile
extends RandomAccessFile

Use NIO MappedByteBuffer to implement a RandomAccessFile. Limited to 2G size.

Author:
john

Field Summary
 
Fields inherited from class ucar.unidata.io.RandomAccessFile
BIG_ENDIAN, bigEndian, buffer, bufferStart, cached, dataEnd, dataSize, debugAccess, debugLeaks, defaultBufferSize, endOfFile, file, filePosition, LITTLE_ENDIAN, location, openFiles, readonly
 
Constructor Summary
MMapRandomAccessFile(java.lang.String location, java.lang.String mode)
          Constructor for in-memory "files"
 
Method Summary
 void close()
          Close the file, and release any associated system resources.
 void flush()
          Copy the contents of the buffer to the disk.
 long length()
          Get the length of the file.
 int read()
          Read a byte of data from the file, blocking until data is available.
protected  int readBytes(byte[] dst, int offset, int length)
          Read up to len bytes into an array, at a specified offset.
 void seek(long pos)
          Set the position in the file for the next read or write.
 void unread()
          Unread the last byte read.
 void write(int b)
          Write a byte to the file.
 void writeBytes(byte[] dst, int offset, int length)
          Write len bytes from an array to the file.
 
Methods inherited from class ucar.unidata.io.RandomAccessFile
getFD, getFilePointer, getLocation, getRandomAccessFile, isAtEndOfFile, isCached, order, read_, read, read, readBoolean, readByte, readChar, readDouble, readDouble, readFloat, readFloat, readFully, readFully, readInt, readInt, readIntUnbuffered, readLine, readLong, readLong, readShort, readShort, readString, readUnsignedByte, readUnsignedShort, readUTF, setCached, setDebugAccess, setDebugLeaks, setExtendMode, setMinLength, skipBytes, synch, toString, write, write, writeBoolean, writeBoolean, writeByte, writeBytes, writeBytes, writeChar, writeChar, writeChars, writeDouble, writeDouble, writeFloat, writeFloat, writeInt, writeInt, writeLong, writeLong, writeShort, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MMapRandomAccessFile

public MMapRandomAccessFile(java.lang.String location,
                            java.lang.String mode)
                     throws java.io.IOException
Constructor for in-memory "files"

Parameters:
location - used as a name
mode - the open mode
Throws:
java.io.IOException - on error
Method Detail

flush

public void flush()
           throws java.io.IOException
Description copied from class: RandomAccessFile
Copy the contents of the buffer to the disk.

Overrides:
flush in class RandomAccessFile
Throws:
java.io.IOException - if an I/O error occurrs.

close

public void close()
           throws java.io.IOException
Description copied from class: RandomAccessFile
Close the file, and release any associated system resources.

Overrides:
close in class RandomAccessFile
Throws:
java.io.IOException - if an I/O error occurrs.

length

public long length()
Description copied from class: RandomAccessFile
Get the length of the file. The data in the buffer (which may not have been written the disk yet) is taken into account.

Overrides:
length in class RandomAccessFile
Returns:
the length of the file in bytes.

seek

public void seek(long pos)
Description copied from class: RandomAccessFile
Set the position in the file for the next read or write.

Overrides:
seek in class RandomAccessFile
Parameters:
pos - the offset (in bytes) from the start of the file.

unread

public void unread()
Description copied from class: RandomAccessFile
Unread the last byte read. This method should not be used more than once between reading operations, or strange things might happen.

Overrides:
unread in class RandomAccessFile

read

public int read()
         throws java.io.IOException
Description copied from class: RandomAccessFile
Read a byte of data from the file, blocking until data is available.

Overrides:
read in class RandomAccessFile
Returns:
the next byte of data, or -1 if the end of the file is reached.
Throws:
java.io.IOException - if an I/O error occurrs.

readBytes

protected int readBytes(byte[] dst,
                        int offset,
                        int length)
                 throws java.io.IOException
Description copied from class: RandomAccessFile
Read up to len bytes into an array, at a specified offset. This will block until at least one byte has been read.

Overrides:
readBytes in class RandomAccessFile
Parameters:
dst - the byte array to receive the bytes.
offset - the offset in the array where copying will start.
length - the number of bytes to copy.
Returns:
the actual number of bytes read, or -1 if there is not more data due to the end of the file being reached.
Throws:
java.io.IOException - if an I/O error occurrs.

write

public void write(int b)
           throws java.io.IOException
Description copied from class: RandomAccessFile
Write a byte to the file. If the file has not been opened for writing, an IOException will be raised only when an attempt is made to write the buffer to the file.

Caveat: the effects of seek( )ing beyond the end of the file are undefined.

Specified by:
write in interface java.io.DataOutput
Overrides:
write in class RandomAccessFile
Parameters:
b - _more_
Throws:
java.io.IOException - if an I/O error occurrs.

writeBytes

public void writeBytes(byte[] dst,
                       int offset,
                       int length)
                throws java.io.IOException
Description copied from class: RandomAccessFile
Write len bytes from an array to the file.

Overrides:
writeBytes in class RandomAccessFile
Parameters:
dst - the array containing the data.
offset - the offset in the array to the data.
length - the length of the data.
Throws:
java.io.IOException - if an I/O error occurrs.