public class RandomAccessInputStream extends InputStream implements DataInput, Closeable, com.esotericsoftware.kryo.KryoSerializable
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_BLOCK_SIZE
Block size to use when searching through the stream.
|
protected String |
encoding |
protected String |
file
The file name.
|
protected long |
length |
protected long |
markedPos |
protected static int |
MAX_OVERHEAD
Maximum size of the buffer used by the DataInputStream.
|
protected static int |
MAX_SEARCH_SIZE
Maximum number of bytes to search when searching through the stream.
|
protected IRandomAccess |
raf |
Constructor and Description |
---|
RandomAccessInputStream(byte[] array)
Constructs a random access stream around the given byte array.
|
RandomAccessInputStream(IRandomAccess handle)
Constructs a random access stream around the given handle.
|
RandomAccessInputStream(IRandomAccess handle,
String file)
Constructs a random access stream around the given handle,
and with the associated file path.
|
RandomAccessInputStream(String file)
Constructs a hybrid RandomAccessFile/DataInputStream
around the given file.
|
RandomAccessInputStream(String file,
int bufferSize)
Constructs a hybrid RandomAccessFile/DataInputStream
around the given file.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close()
Closes the streams.
|
String |
findString(boolean saveString,
int blockSize,
String... terminators)
Reads or skips a string ending with one of the given terminating
substrings, using the specified block size for buffering.
|
String |
findString(boolean saveString,
String... terminators)
Reads or skips a string ending with
one of the given terminating substrings.
|
String |
findString(int blockSize,
String... terminators)
Reads a string ending with one of the given terminating
substrings, using the specified block size for buffering.
|
String |
findString(String... terminators)
Reads a string ending with one of the given terminating substrings.
|
long |
getFilePointer() |
boolean |
isBitOnByteBoundary()
Checks if the current position is on a byte boundary, that is the next
bit in the byte array is the first bit in a byte.
|
boolean |
isLittleEndian()
Gets the endianness of the stream.
|
long |
length() |
void |
mark(int readLimit) |
boolean |
markSupported() |
void |
order(boolean little)
Sets the endianness of the stream.
|
int |
read() |
int |
read(byte[] array)
Read bytes from the stream into the given array.
|
int |
read(byte[] array,
int offset,
int n)
Read n bytes from the stream into the given array at the specified offset.
|
int |
read(ByteBuffer buf)
Read bytes from the stream into the given buffer.
|
int |
read(ByteBuffer buf,
int offset,
int n)
Read n bytes from the stream into the given buffer at the specified offset.
|
void |
read(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Input in) |
int |
readBits(int bitsToRead)
Returns an int value representing the value of the bits read from
the byte array, from the current position.
|
boolean |
readBoolean()
Read an input byte and return true if the byte is nonzero.
|
byte |
readByte()
Read one byte and return it.
|
String |
readByteToString(int n)
Reads a byte array of the given length byte by byte.
|
char |
readChar()
Read an input char.
|
String |
readCString()
Read a string of arbitrary length, terminated by a null char.
|
double |
readDouble()
Read eight bytes and return a double value.
|
float |
readFloat()
Read four bytes and return a float value.
|
void |
readFully(byte[] array)
Read bytes from the stream into the given array.
|
void |
readFully(byte[] array,
int offset,
int n)
Read n bytes from the stream into the given array at the specified offset.
|
int |
readInt()
Read four input bytes and return an int value.
|
String |
readLine()
Read the next line of text from the input stream.
|
long |
readLong()
Read eight input bytes and return a long value.
|
short |
readShort()
Read two input bytes and return a short value.
|
String |
readString(int n)
Read a string of up to length n.
|
String |
readString(String lastChars)
Reads a string ending with one of the characters in the given string.
|
int |
readUnsignedByte()
Read an input byte and zero extend it appropriately.
|
long |
readUnsignedInt()
Read four input bytes and return an unsigned value.
|
int |
readUnsignedShort()
Read two bytes and return an int in the range 0 through 65535.
|
String |
readUTF()
Read a string that has been encoded using a modified UTF-8 format.
|
void |
reset() |
void |
seek(long pos)
Seeks to the given offset within the stream.
|
void |
setEncoding(String encoding)
Sets the native encoding of the stream.
|
void |
setLength(long newLength)
Sets the length of the stream.
|
void |
skipBits(long bits)
Skips a number of bits in the BitBuffer.
|
int |
skipBytes(int n)
Skip n bytes within the stream.
|
long |
skipBytes(long n)
Skip n bytes within the stream.
|
void |
write(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Output out) |
skip
protected static final int MAX_OVERHEAD
protected static final int DEFAULT_BLOCK_SIZE
protected static final int MAX_SEARCH_SIZE
protected IRandomAccess raf
protected String file
protected long length
protected long markedPos
protected String encoding
public RandomAccessInputStream(String file) throws IOException
file
- a name that can be passed to Location.getHandle(String)
IOException
- if the name is invalidpublic RandomAccessInputStream(String file, int bufferSize) throws IOException
file
- a name that can be passed to Location.getHandle(String)
bufferSize
- the size of the caching buffer in bytesIOException
- if the name is invalidpublic RandomAccessInputStream(IRandomAccess handle) throws IOException
handle
- the IRandomAccess
to be wrappedIOException
- if the handle is invalidpublic RandomAccessInputStream(IRandomAccess handle, String file) throws IOException
handle
- the IRandomAccess
to be wrappedfile
- the name associated with the handle. Can be null.IOException
- if the handle is invalidpublic RandomAccessInputStream(byte[] array) throws IOException
array
- the byte array to be wrapped via ByteArrayHandle
IOException
- if the ByteArrayHandle
cannot be createdpublic void setEncoding(String encoding)
encoding
- the name of a standard charset to use when
working with stringsConstants.ENCODING
,
Charset
public void seek(long pos) throws IOException
pos
- the new byte offsetIOException
- if the seek failspublic long length() throws IOException
IOException
- if the length cannot be retrievedpublic void setLength(long newLength) throws IOException
newLength
- the new stream length as defined aboveIOException
- if the original stream length cannot be retrievedpublic long getFilePointer() throws IOException
IOException
- if the current pointer cannot be retrievedpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public void order(boolean little)
little
- true if the stream ordering should be little-endianpublic boolean isLittleEndian()
public String readString(String lastChars) throws IOException
lastChars
- each character is a possible terminatorIOException
- If the maximum search length (512 MB) is exceeded.findString(String...)
public String findString(String... terminators) throws IOException
terminators
- The strings for which to search.IOException
- If the maximum search length (512 MB) is exceeded.public String findString(boolean saveString, String... terminators) throws IOException
saveString
- Whether to collect the string from the current file
pointer to the terminating bytes, and return it. If false, returns null.terminators
- The strings for which to search.IOException
- If saveString flag is set
and the maximum search length (512 MB) is exceeded.public String findString(int blockSize, String... terminators) throws IOException
blockSize
- The block size to use when reading bytes in chunks.terminators
- The strings for which to search.IOException
- If the maximum search length (512 MB) is exceeded.public String findString(boolean saveString, int blockSize, String... terminators) throws IOException
saveString
- Whether to collect the string from the current file
pointer to the terminating bytes, and return it. If false, returns null.blockSize
- The block size to use when reading bytes in chunks.terminators
- The strings for which to search.IOException
- If saveString flag is set
and the maximum search length (512 MB) is exceeded.public void skipBits(long bits) throws IOException
bits
- Number of bits to skipIllegalArgumentException
- if bits is negativeIOException
- if an error occurs while skippingpublic int readBits(int bitsToRead) throws IOException
The current position is modified by this call.
Bits are pushed into the int from the right, endianness is not considered by the method on its own. So, if 5 bits were read from the buffer "10101", the int would be the integer representation of 000...0010101 on the target machine.
In general, this also means the result will be positive unless a full 32 bits are read.
Requesting more than 32 bits is allowed, but only up to 32 bits worth of data will be returned (the last 32 bits read).
bitsToRead
- the number of bits to read from the bit bufferIllegalArgumentException
- if bits is negativeIOException
- if an error occurs while skippingpublic boolean isBitOnByteBoundary()
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public long readUnsignedInt() throws IOException
IOException
- if there is an error during readingpublic String readLine() throws IOException
readLine
in interface DataInput
IOException
public String readCString() throws IOException
IOException
- if there is an error during readingpublic String readByteToString(int n) throws IOException
n
- The length of the array.IOException
- Thrown if an error occurred while reading the data.setEncoding(String)
public String readString(int n) throws IOException
n
- the number of bytes to readIOException
- if an error occurred during readingsetEncoding(String)
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
public long skipBytes(long n) throws IOException
IOException
public int read(byte[] array) throws IOException
read
in class InputStream
IOException
public int read(byte[] array, int offset, int n) throws IOException
read
in class InputStream
IOException
public int read(ByteBuffer buf) throws IOException
buf
- the ByteBuffer
to fill. buf.capacity()
determines the number of bytes to readIOException
- if an error occurred during readingpublic int read(ByteBuffer buf, int offset, int n) throws IOException
buf
- the ByteBuffer
to filloffset
- the offset to the first byte in the buffern
- the number of bytes to readIOException
- if an error occurred during readingpublic void readFully(byte[] array) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] array, int offset, int n) throws IOException
readFully
in interface DataInput
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void mark(int readLimit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input in)
read
in interface com.esotericsoftware.kryo.KryoSerializable
public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output out)
write
in interface com.esotericsoftware.kryo.KryoSerializable
Copyright © 2005–2019 Open Microscopy Environment. All rights reserved.