public class NIOInputStream extends InputStream implements DataInput
| Modifier and Type | Field and Description |
|---|---|
protected Channel |
channel
The file channel backed by the random access file.
|
protected static int |
DEFAULT_BLOCK_SIZE
Block size to use when searching through the stream.
|
protected File |
file
The file.
|
protected String |
filename
The file name.
|
protected boolean |
isLittleEndian
Endianness of the stream.
|
protected static int |
MAX_SEARCH_SIZE
Maximum number of bytes to search when searching through the stream.
|
protected IRandomAccess |
raf |
| Constructor and Description |
|---|
NIOInputStream(byte[] array)
Constructs a random access stream around the given byte array.
|
NIOInputStream(IRandomAccess handle)
Constructs a random access stream around the given handle.
|
NIOInputStream(String filename)
Constructs an NIOInputStream 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()
Gets the current (absolute) file pointer.
|
DataInputStream |
getInputStream()
Returns the underlying InputStream.
|
boolean |
isLittleEndian()
Gets the endianness of the stream.
|
long |
length()
Gets the number of bytes in the file.
|
void |
mark(int readLimit) |
boolean |
markSupported() |
void |
order(boolean isLittleEndian)
Sets the endianness of the stream.
|
int |
read()
Alias for readByte().
|
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.
|
boolean |
readBoolean()
Read an input byte and return true if the byte is nonzero.
|
byte |
readByte()
Read one byte and return it.
|
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 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.
|
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 |
setExtend(int extend)
Sets the number of bytes by which to extend the stream.
|
int |
skipBytes(int n)
Skip n bytes within the stream.
|
skipprotected static final int DEFAULT_BLOCK_SIZE
protected static final int MAX_SEARCH_SIZE
protected IRandomAccess raf
protected String filename
protected File file
protected Channel channel
protected boolean isLittleEndian
public NIOInputStream(String filename) throws IOException
IOExceptionpublic NIOInputStream(IRandomAccess handle)
public NIOInputStream(byte[] array)
public DataInputStream getInputStream()
public void setExtend(int extend)
public void seek(long pos)
throws IOException
IOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionpublic long length()
throws IOException
IOExceptionpublic long getFilePointer()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic void order(boolean isLittleEndian)
public boolean isLittleEndian()
public String readString(String lastChars) throws IOException
IOExceptionfindString(String...)public String findString(String... terminators) throws IOException
terminators - The strings for which to search.IOExceptionpublic 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.IOExceptionpublic 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 boolean readBoolean()
throws IOException
readBoolean in interface DataInputIOExceptionpublic byte readByte()
throws IOException
readByte in interface DataInputIOExceptionpublic char readChar()
throws IOException
readChar in interface DataInputIOExceptionpublic double readDouble()
throws IOException
readDouble in interface DataInputIOExceptionpublic float readFloat()
throws IOException
readFloat in interface DataInputIOExceptionpublic int readInt()
throws IOException
readInt in interface DataInputIOExceptionpublic String readLine() throws IOException
readLine in interface DataInputIOExceptionpublic String readCString() throws IOException
IOExceptionpublic String readString(int n) throws IOException
IOExceptionpublic long readLong()
throws IOException
readLong in interface DataInputIOExceptionpublic short readShort()
throws IOException
readShort in interface DataInputIOExceptionpublic int readUnsignedByte()
throws IOException
readUnsignedByte in interface DataInputIOExceptionpublic int readUnsignedShort()
throws IOException
readUnsignedShort in interface DataInputIOExceptionpublic String readUTF() throws IOException
readUTF in interface DataInputIOExceptionpublic int skipBytes(int n)
throws IOException
skipBytes in interface DataInputIOExceptionpublic int read(byte[] array)
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] array,
int offset,
int n)
throws IOException
read in class InputStreamIOExceptionpublic void readFully(byte[] array)
throws IOException
readFully in interface DataInputIOExceptionpublic void readFully(byte[] array,
int offset,
int n)
throws IOException
readFully in interface DataInputIOExceptionpublic int available()
throws IOException
available in class InputStreamIOExceptionpublic void mark(int readLimit)
mark in class InputStreampublic boolean markSupported()
markSupported in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOExceptionCopyright © 2015 Open Microscopy Environment