Package ucar.unidata.io
Class InMemoryRandomAccessFile
- java.lang.Object
-
- ucar.unidata.io.RandomAccessFile
-
- ucar.unidata.io.InMemoryRandomAccessFile
-
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
,FileCacheable
public class InMemoryRandomAccessFile extends RandomAccessFile
A RandomAccessFile stored entirely in memory as a byte array.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InMemoryRandomAccessFile.Provider
Hook for service provider interface RandomAccessFileProvider
-
Field Summary
-
Fields inherited from class ucar.unidata.io.RandomAccessFile
allFiles, BIG_ENDIAN, bigEndian, buffer, bufferModified, bufferStart, dataEnd, dataSize, debugAccess, debugLeaks, defaultBufferSize, endOfFile, file, fileChannel, filePosition, LITTLE_ENDIAN, location, openFiles, readonly, showOpen, showRead
-
-
Constructor Summary
Constructors Constructor Description InMemoryRandomAccessFile(String name, byte[] data)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
length()
Get the length of the file.protected int
read_(long pos, byte[] b, int offset, int len)
Read directly from file, without going through the buffer.long
readToByteChannel(WritableByteChannel dest, long offset, long nbytes)
Readnbytes
bytes, at the specified file offset, send to a WritableByteChannel.void
setBufferSize(int bufferSize)
Set the buffer size.-
Methods inherited from class ucar.unidata.io.RandomAccessFile
acquire, acquire, close, eject, enableDefaultGlobalFileCache, flush, getAllFiles, getBufferSize, getDebugLeaks, getDebugNbytes, getDebugNseeks, getFilePointer, getGlobalFileCache, getLastModified, getLocation, getMaxOpenFileCount, getOpenFileCount, getOpenFiles, getRandomAccessFile, isAtEndOfFile, isDirectory, order, order, reacquire, read, read, read, readBoolean, readBuffer, readByte, readBytes, readBytes, readChar, readDouble, readDouble, readFloat, readFloat, readFully, readFully, readInt, readInt, readIntUnbuffered, readLine, readLine, readLong, readLong, readShort, readShort, readString, readString, readStringMax, readStringMax, readUnsignedByte, readUnsignedShort, readUTF, release, searchForward, seek, setDebugAccess, setDebugLeaks, setExtendMode, setFileCache, setGlobalFileCache, setMinLength, shutdown, skipBytes, skipBytes, toString, unread, write, write, write, writeBoolean, writeBoolean, writeByte, writeBytes, writeBytes, writeBytes, writeChar, writeChar, writeChar, writeChar, writeChar, writeChar, writeChars, writeChars, writeChars, writeDouble, writeDouble, writeDouble, writeDouble, writeDouble, writeDouble, writeFloat, writeFloat, writeFloat, writeFloat, writeFloat, writeFloat, writeInt, writeInt, writeInt, writeInt, writeInt, writeInt, writeLong, writeLong, writeLong, writeLong, writeLong, writeLong, writeShort, writeShort, writeShort, writeShort, writeShort, writeShort, writeUTF
-
-
-
-
Constructor Detail
-
InMemoryRandomAccessFile
public InMemoryRandomAccessFile(String name, byte[] data)
Constructor.- Parameters:
name
- used as the locationdata
- the complete data file
-
-
Method Detail
-
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 classRandomAccessFile
- Returns:
- the length of the file in bytes.
-
setBufferSize
public void setBufferSize(int bufferSize)
Description copied from class:RandomAccessFile
Set the buffer size. If writing, call flush() first.- Overrides:
setBufferSize
in classRandomAccessFile
- Parameters:
bufferSize
- length in bytes
-
read_
protected int read_(long pos, byte[] b, int offset, int len)
Description copied from class:RandomAccessFile
Read directly from file, without going through the buffer. All reading goes through here or readToByteChannel;- Overrides:
read_
in classRandomAccessFile
- Parameters:
pos
- start here in the fileb
- put data into this bufferoffset
- buffer offsetlen
- this number of bytes- Returns:
- actual number of bytes read, -1 if underlying random access file was closed
-
readToByteChannel
public long readToByteChannel(WritableByteChannel dest, long offset, long nbytes) throws IOException
Description copied from class:RandomAccessFile
Readnbytes
bytes, at the specified file offset, send to a WritableByteChannel. This will block until all bytes are read. This uses the underlying file channel directly, bypassing all user buffers.- Overrides:
readToByteChannel
in classRandomAccessFile
- Parameters:
dest
- write to this WritableByteChannel.offset
- the offset in the file where copying will start.nbytes
- the number of bytes to read.- Returns:
- the actual number of bytes read and transfered
- Throws:
IOException
- if an I/O error occurs.
-
-