public abstract class StreamHandle extends Object implements IRandomAccess
IRandomAccess
Modifier and Type | Class and Description |
---|---|
static class |
StreamHandle.Settings |
Modifier and Type | Field and Description |
---|---|
protected String |
file
Name of the open stream.
|
protected long |
fp
Current position within the stream.
|
protected long |
length
Length of the stream.
|
protected long |
mark
Marked position within the stream.
|
protected ByteOrder |
order
Byte ordering of this stream.
|
protected DataOutputStream |
outStream
OutputStream to be used for writing.
|
protected DataInputStream |
stream
InputStream to be used for reading.
|
Constructor and Description |
---|
StreamHandle()
Construct a new StreamHandle.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this random access stream and releases
any system resources associated with the stream.
|
boolean |
exists()
Returns whether this refers to a valid object
|
long |
getFilePointer()
Returns the current offset in this stream.
|
ByteOrder |
getOrder()
Returns the current order (endianness) of the stream.
|
long |
length()
Returns the length of this stream.
|
int |
read(byte[] b)
Reads up to b.length bytes of data
from this stream into an array of bytes.
|
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this stream into an array of bytes.
|
int |
read(ByteBuffer buffer)
Reads up to buffer.capacity() bytes of data
from this stream into a ByteBuffer.
|
int |
read(ByteBuffer buffer,
int off,
int len)
Reads up to len bytes of data from this stream into a ByteBuffer.
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
protected abstract void |
resetStream()
Close and reopen the stream; the stream pointer and mark should be
reset to 0.
|
void |
seek(long pos)
Sets the stream pointer offset, measured from the beginning
of this stream, at which the next read or write occurs.
|
void |
setOrder(ByteOrder order)
Sets the byte order (endianness) of the stream.
|
int |
skipBytes(int n) |
long |
skipBytes(long n)
A
long variant of DataInput.skipBytes(int) . |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(ByteBuffer buf)
Writes up to buffer.capacity() bytes of data from the given
ByteBuffer to this stream.
|
void |
write(ByteBuffer buf,
int off,
int len)
Writes up to len bytes of data from the given ByteBuffer to this
stream.
|
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(int v) |
void |
writeBytes(String s) |
void |
writeChar(int v) |
void |
writeChars(String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(String str) |
protected String file
protected DataInputStream stream
protected DataOutputStream outStream
protected long length
protected long fp
protected long mark
protected ByteOrder order
public StreamHandle()
public void close() throws IOException
IRandomAccess
close
in interface IRandomAccess
IOException
- if the underlying stream(s) could not be closedpublic long getFilePointer() throws IOException
IRandomAccess
getFilePointer
in interface IRandomAccess
IOException
- if the offset cannot be retrievedpublic boolean exists() throws IOException
IRandomAccess
exists
in interface IRandomAccess
IOException
- if unable to determine whether the object is validpublic long length() throws IOException
IRandomAccess
length
in interface IRandomAccess
IOException
- if the length cannot be retrievedpublic int read(byte[] b) throws IOException
IRandomAccess
read
in interface IRandomAccess
b
- the array to fill from this streamIOException
- if reading is not possiblepublic int read(byte[] b, int off, int len) throws IOException
IRandomAccess
read
in interface IRandomAccess
b
- the array to fill from this streamoff
- the offset in b
from which to start filling;
expected to be non-negative and no greater than
b.length - len
len
- the number of bytes to read; expected to be positive and
no greater than b.length - offset
IOException
- if reading is not possiblepublic int read(ByteBuffer buffer) throws IOException
IRandomAccess
read
in interface IRandomAccess
buffer
- the ByteBuffer to fill from this streamIOException
- if reading is not possiblepublic int read(ByteBuffer buffer, int off, int len) throws IOException
IRandomAccess
read
in interface IRandomAccess
buffer
- the ByteBuffer to fill from this streamoff
- the offset in b
from which to start filling;
expected to be non-negative and no greater than
buffer.capacity() - len
len
- the number of bytes to read; expected to be positive and
no greater than buffer.capacity() - offset
IOException
- if reading is not possiblepublic void seek(long pos) throws IOException
IRandomAccess
seek
in interface IRandomAccess
pos
- new byte offset (pointer) in the current stream.
Unless otherwise noted, may be larger or smaller than the
current pointer, but must be non-negative and less than the
value of #length()IOException
- if pos
is invalid or the seek failsIRandomAccess.getFilePointer()
public void write(ByteBuffer buf) throws IOException
IRandomAccess
write
in interface IRandomAccess
buf
- the ByteBuffer containing bytes to write to this streamIOException
- if writing is not possiblepublic void write(ByteBuffer buf, int off, int len) throws IOException
IRandomAccess
write
in interface IRandomAccess
buf
- the ByteBuffer containing bytes to write to this streamoff
- the offset in b
from which to start writing;
expected to be non-negative and no greater than
buf.capacity() - len
len
- the number of bytes to write; expected to be positive and
no greater than buf.capacity() - offset
IOException
- if writing is not possiblepublic ByteOrder getOrder()
IRandomAccess
getOrder
in interface IRandomAccess
public void setOrder(ByteOrder order)
IRandomAccess
setOrder
in interface IRandomAccess
order
- Order to set.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 void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public String readLine() throws IOException
readLine
in interface DataInput
IOException
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
IRandomAccess
long
variant of DataInput.skipBytes(int)
.skipBytes
in interface IRandomAccess
n
- the number of bytes to skipIOException
- if the operation failedpublic void write(byte[] b) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in interface DataOutput
IOException
public void write(int b) throws IOException
write
in interface DataOutput
IOException
public void writeBoolean(boolean v) throws IOException
writeBoolean
in interface DataOutput
IOException
public void writeByte(int v) throws IOException
writeByte
in interface DataOutput
IOException
public void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
IOException
public void writeChar(int v) throws IOException
writeChar
in interface DataOutput
IOException
public void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
public void writeDouble(double v) throws IOException
writeDouble
in interface DataOutput
IOException
public void writeFloat(float v) throws IOException
writeFloat
in interface DataOutput
IOException
public void writeInt(int v) throws IOException
writeInt
in interface DataOutput
IOException
public void writeLong(long v) throws IOException
writeLong
in interface DataOutput
IOException
public void writeShort(int v) throws IOException
writeShort
in interface DataOutput
IOException
public void writeUTF(String str) throws IOException
writeUTF
in interface DataOutput
IOException
protected abstract void resetStream() throws IOException
IOException
- if the stream cannot be resetCopyright © 2005–2018 Open Microscopy Environment. All rights reserved.