|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.bigzip.plugin.compression.io.AbstractStream
Instances of this class support both reading and writing to a random access file. An application can modify the position in the file at which the next read or write occurs. This class provides a sense of security by offering methods that allow specified mode accesses of read-only or read-write to files.
Field Summary | |
protected AbstractStream |
clientStream
Should be set in the constructor and represents the underlying Randomly accessible Stream |
Constructor Summary | |
AbstractStream()
|
Method Summary | |
void |
close()
Closes this random access file stream and releases any system resources associated with the stream. |
void |
ensureOpen()
Check to make sure that this stream has not been closed |
void |
finish()
Used as a means to flush any data before either closing or performing a new operation. |
long |
getFilePointer()
Returns the current offset in this file. |
boolean |
isClosed()
|
long |
length()
Returns the length of this file. |
int |
read()
Reads a byte of data from this file. |
int |
read(byte[] b)
Reads up to b.length bytes of data from this file
into an array of bytes. |
abstract int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this file into an
array of bytes. |
boolean |
readBoolean()
Reads a boolean from this file. |
byte |
readByte()
Reads a signed 8-bit value from this file. |
char |
readChar()
Reads a Unicode character from this file. |
int |
readDirect(byte[] b)
|
int |
readDirect(byte[] b,
int off,
int len)
|
double |
readDouble()
Reads a double from this file. |
float |
readFloat()
Reads a float from this file. |
void |
readFully(byte[] b,
int off,
int len)
Reads exactly len bytes from this file into the byte
array. |
int |
readInt()
Reads a signed 32 or 16-bit integer from this file. |
int |
readInt(byte[] b,
int off)
Reads a signed 32/16-bit integer from a buffer. |
java.lang.String |
readLine()
Reads the next line of text from this file. |
long |
readLong()
Reads a signed 64 or 32-bit integer from this file. |
long |
readLong(byte[] b,
int off)
Reads a signed 64/32-bit long from a buffer. |
short |
readShort()
Reads a signed 16-bit number from this file. |
int |
readUnsignedByte()
Reads an unsigned 8-bit number from this file. |
int |
readUnsignedShort()
Reads an unsigned 16-bit number from this file. |
java.lang.String |
readUTF()
Reads in a string from this file. |
void |
seek(long pos)
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. |
void |
setClientStream(AbstractStream clientStream)
Assigns a new stream client |
void |
setClosed(boolean b)
Sets the closed status of the file. |
int |
skipBytes(int n)
Skips exactly n bytes of input. |
void |
write(byte[] b)
Writes b.length bytes from the specified byte array
starting at offset off to this file. |
abstract void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array
starting at offset off to this file. |
abstract void |
write(int b)
Writes the specified byte to this file. |
void |
writeBoolean(boolean v)
Writes a boolean to the file as a 1-byte value. |
void |
writeByte(int v)
Writes a byte to the file as a 1-byte value. |
void |
writeBytes(java.lang.String s)
Writes the string to the file as a sequence of bytes. |
void |
writeChar(int v)
Writes a char to the file as a 2-byte value, high
byte first. |
void |
writeChars(java.lang.String s)
Writes a string to the file as a sequence of characters. |
void |
writeDirect(byte[] b)
|
void |
writeDirect(byte[] b,
int off,
int len)
|
void |
writeDouble(double v)
Converts the double argument to a long using the
doubleToLongBits method in class Double ,
and then writes that long value to the file as an
8 or 4-byte quantity, high byte first. |
void |
writeFloat(float v)
Converts the float argument to an int using the
floatToIntBits method in class Float ,
and then writes that int value to the file as a
4 or 2-byte quantity, high byte first. |
void |
writeFully(byte[] b,
int off,
int len)
Writes len bytes from the specified
byte array starting at offset off to
this random access stream. |
void |
writeInt(int v)
Writes an int to the file as four bytes, high byte first. |
void |
writeLong(long v)
Writes a long to the file as eight bytes, high byte first. |
void |
writeShort(int v)
Writes a short to the file as two bytes, high byte first. |
void |
writeUTF(java.lang.String str)
Writes a string to the file using UTF-8 encoding in a machine-independent manner. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected AbstractStream clientStream
Constructor Detail |
public AbstractStream()
Method Detail |
public boolean isClosed()
public void setClosed(boolean b)
b
- closed status.public void ensureOpen() throws java.io.IOException
java.io.IOException
- If the stream is no longer openedpublic void setClientStream(AbstractStream clientStream)
AbstractStream
- the new stream client inherited
by Abstract streampublic int read() throws java.io.IOException
-1
if the end of the
file is reached.public abstract int read(byte[] b, int off, int len) throws java.io.IOException
len
bytes of data from this file into an
array of bytes. This method blocks until at least one byte of input
is available.b
- the buffer into which the data is read.off
- the start offset of the data.len
- the maximum number of bytes read.-1
if there is no more data because the end of
the file has been reached.public int read(byte[] b) throws java.io.IOException
b.length
bytes of data from this file
into an array of bytes. This method blocks until at least one byte
of input is available.b
- the buffer into which the data is read.-1
if there is no more data because the end of
this file has been reached.public void readFully(byte[] b, int off, int len) throws java.io.IOException
len
bytes from this file into the byte
array. This method reads repeatedly from the file until all the
bytes are read. This method blocks until all the bytes are read,
the end of the stream is detected, or an exception is thrown.b
- the buffer into which the data is read.off
- the start offset of the data.len
- the number of bytes to read.public int readDirect(byte[] b) throws java.io.IOException
public int readDirect(byte[] b, int off, int len) throws java.io.IOException
public abstract void write(int b) throws java.io.IOException
b
- the byte
to be written.public void write(byte[] b) throws java.io.IOException
b.length
bytes from the specified byte array
starting at offset off
to this file.b
- the data.public abstract void write(byte[] b, int off, int len) throws java.io.IOException
len
bytes from the specified byte array
starting at offset off
to this file.b
- the data.off
- the start offset in the data.len
- the number of bytes to write.public void writeFully(byte[] b, int off, int len) throws java.io.IOException
len
bytes from the specified
byte
array starting at offset off
to
this random access stream.
The write
method of IOStream
calls the write
method of one argument on each
byte
to output.
Note that this method does not call the write
method
of its underlying random access stream with the same arguments. Subclasses
of IOStream
should provide a more efficient
implementation of this method.
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.java.io.IOException
- if an I/O error occurs.public void writeDirect(byte[] b) throws java.io.IOException
public void writeDirect(byte[] b, int off, int len) throws java.io.IOException
public int skipBytes(int n) throws java.io.IOException
n
bytes of input.
This method blocks until all the bytes are skipped, the end of the stream is detected, or an exception is thrown.
n
- the number of bytes to be skipped.n
.public long getFilePointer() throws java.io.IOException
public void seek(long pos) throws java.io.IOException
pos
- the offset position, measured in bytes from the
beginning of the file, at which to set the file
pointer.public long length() throws java.io.IOException
public void close() throws java.io.IOException
public void finish() throws java.io.IOException
public boolean readBoolean() throws java.io.IOException
boolean
from this file. This method reads a
single byte from the file. A value of 0
represents
false
. Any other value represents true
.
This method blocks until the byte is read, the end of the stream
is detected, or an exception is thrown.boolean
value read.public byte readByte() throws java.io.IOException
This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.
byte
.public int readUnsignedByte() throws java.io.IOException
This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.
public short readShort() throws java.io.IOException
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
public int readUnsignedShort() throws java.io.IOException
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
public char readChar() throws java.io.IOException
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
public int readInt() throws java.io.IOException
This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
int
.public int readInt(byte[] b, int off)
b
- The byte array containing the valueoff
- The starting position of the value in the arrayint
.public long readLong() throws java.io.IOException
This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
long
.public long readLong(byte[] b, int off)
b
- The byte array containing the valueoff
- The starting position of the value in the arraylong
.public float readFloat() throws java.io.IOException
float
from this file. This method reads an
int
value as if by the readInt
method
and then converts that int
to a float
using the intBitsToFloat
method in class
Float
.
This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
float
.public double readDouble() throws java.io.IOException
double
from this file. This method reads a
long
value as if by the readLong
method
and then converts that long
to a double
using the longBitsToDouble
method in
class Double
.
This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
double
.public java.lang.String readLine() throws java.io.IOException
This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the stream is detected, or an exception is thrown.
public java.lang.String readUTF() throws java.io.IOException
public void writeBoolean(boolean v) throws java.io.IOException
boolean
to the file as a 1-byte value. The
value true
is written out as the value
(byte)1
; the value false
is written out
as the value (byte)0
.v
- a boolean
value to be written.public void writeByte(int v) throws java.io.IOException
byte
to the file as a 1-byte value.v
- a byte
value to be written.public void writeShort(int v) throws java.io.IOException
short
to the file as two bytes, high byte first.v
- a short
to be written.public void writeChar(int v) throws java.io.IOException
char
to the file as a 2-byte value, high
byte first.v
- a char
value to be written.public void writeInt(int v) throws java.io.IOException
int
to the file as four bytes, high byte first.v
- an int
to be written.public void writeLong(long v) throws java.io.IOException
long
to the file as eight bytes, high byte first.v
- a long
to be written.public void writeFloat(float v) throws java.io.IOException
int
using the
floatToIntBits
method in class Float
,
and then writes that int
value to the file as a
4 or 2-byte quantity, high byte first.v
- a float
value to be written.public void writeDouble(double v) throws java.io.IOException
long
using the
doubleToLongBits
method in class Double
,
and then writes that long
value to the file as an
8 or 4-byte quantity, high byte first.v
- a double
value to be written.public void writeBytes(java.lang.String s) throws java.io.IOException
s
- a string of bytes to be written.public void writeChars(java.lang.String s) throws java.io.IOException
writeChar
method.s
- a String
value to be written.public void writeUTF(java.lang.String str) throws java.io.IOException
str
- a string to be written.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |