|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectGiciStream.BufferedDataInputStream
public class BufferedDataInputStream
This class provides a wrapper for abstracting from the data source, which can be a file or a buffer. The data source is choosed with the class's constructor. If the data source is a file, then, data from file are buffered for a better efficiency in reading.
Field Summary | |
---|---|
(package private) byte[] |
buf
An array of bytes used to buffer the input/output data. |
(package private) int |
count
The index one greater than the last valid byte in the buffer. |
private static int |
DEFAULT_BUFFER_SIZE
It is the default size for the buffer when this was not passed |
(package private) boolean |
EOFInBuffer
Indicates, when data source is a file, if the End Of File mark is reached. |
(package private) java.io.RandomAccessFile |
file
|
(package private) long |
filePos
Indicates the offset of the file where data are from. |
(package private) int |
mode
It is the buffer access. |
(package private) int |
offset
Indicates the first available data in the buffer. |
(package private) int |
pos
The index of the next byte to read/write from/to the buffer. |
(package private) boolean |
readFromFile
Indicates the data source, whether data is readed from file or no. |
Constructor Summary | |
---|---|
BufferedDataInputStream(byte[] buf)
|
|
BufferedDataInputStream(byte[] buf,
int offset)
|
|
BufferedDataInputStream(java.io.File file)
|
|
BufferedDataInputStream(int sz)
|
|
BufferedDataInputStream(java.io.RandomAccessFile file)
|
|
BufferedDataInputStream(java.lang.String name)
|
Method Summary | |
---|---|
long |
available()
Returns the number of bytes that can be read from this buffer without blocking. |
void |
close()
|
int |
getCapacity()
|
long |
getPos()
|
long |
length()
Returns the number of bytes that can be read from this buffer, taking into account any buffering. |
int |
read()
Reads the next byte of data from the input stream. |
private int |
read1()
Reads the next byte of data from this input stream. |
boolean |
readBoolean()
|
private void |
readBuffer()
|
byte |
readByte()
See the general contract of the readByte
method of DataInput . |
char |
readChar()
|
double |
readDouble()
See the general contract of the readDouble
method of DataInput . |
float |
readFloat()
See the general contract of the readFloat
method of DataInput . |
void |
readFully(byte[] b)
See the general contract of the readFully
method of DataInput . |
void |
readFully(byte[] b,
int off,
int len)
See the general contract of the readFully
method of DataInput . |
int |
readInt()
|
java.lang.String |
readLine()
|
long |
readLong()
|
short |
readShort()
Reads two input bytes and returns a short value. |
int |
readUnsignedByte()
Reads one input byte, zero-extends it to type int , and returns
the result, which is therefore in the range
0
through 255 . |
int |
readUnsignedShort()
|
java.lang.String |
readUTF()
|
void |
seek(long pos)
|
int |
skipBytes(int n)
|
long |
skipBytes(long n)
|
java.lang.String |
toString()
For debugging purpose. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
volatile byte[] buf
buf[0]
through buf[count-1]
are the
only bytes that can ever be read/write from/to the
buffer; element buf[pos]
is
the next byte to be read/write.
int pos
offset
and not larger than the value of count
. The next byte to be
read/write from/to the buffer will be buf[pos]
.
int count
buf
.
It is one greater than the position of
the last byte within buf
that
can ever be read/write from/to the buffer.
int offset
java.io.RandomAccessFile file
long filePos
boolean EOFInBuffer
buf
contains the last bytes of the file.
int mode
boolean readFromFile
private static int DEFAULT_BUFFER_SIZE
Constructor Detail |
---|
public BufferedDataInputStream(int sz)
sz
- buffer sizepublic BufferedDataInputStream(byte[] buf)
buf
- public BufferedDataInputStream(byte[] buf, int offset)
buf
- offset
- public BufferedDataInputStream(java.lang.String name) throws java.io.FileNotFoundException
name
-
java.io.FileNotFoundException
public BufferedDataInputStream(java.io.File file) throws java.io.FileNotFoundException
file
-
java.io.FileNotFoundException
public BufferedDataInputStream(java.io.RandomAccessFile file) throws java.io.FileNotFoundException
file
-
java.io.FileNotFoundException
Method Detail |
---|
public int read() throws java.io.EOFException, java.io.IOException
int
in the range 0
to
255
. If no byte is available because the end of the stream
has been reached, the value -1
is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.
A subclass must provide an implementation of this method.
-1
if the end of the
stream is reached.
java.io.IOException
java.io.EOFException
java.io.IOException
- if an I/O error occurs.public void readFully(byte[] b) throws java.io.IOException
readFully
method of DataInput
.
Bytes for this operation are read from the contained input stream.
readFully
in interface java.io.DataInput
b
- the buffer into which the data is read.
java.io.EOFException
- if this input stream reaches the end before
reading all the bytes.
java.io.IOException
- if an I/O error occurs.FilterInputStream.in
public void readFully(byte[] b, int off, int len) throws java.io.EOFException, java.io.IOException
readFully
method of DataInput
.
Bytes for this operation are read from the contained input stream.
readFully
in interface java.io.DataInput
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the number of bytes to read.
java.io.EOFException
java.io.EOFException
- if this input stream reaches the end before
reading all the bytes.
java.io.IOException
- if an I/O error occurs.FilterInputStream.in
public int skipBytes(int n) throws java.io.IOException
skipBytes
in interface java.io.DataInput
java.io.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public byte readByte() throws java.io.EOFException, java.io.IOException
readByte
method of DataInput
.
Bytes for this operation are read from the contained stream.
readByte
in interface java.io.DataInput
byte
.
java.io.IOException
java.io.IOException
- if an I/O error occurs.
java.io.EOFException
public int readUnsignedByte() throws java.io.EOFException, java.io.IOException
int
, and returns
the result, which is therefore in the range
0
through 255
.
This method is suitable for reading
the byte written by the writeByte
method of interface DataOutput
if the argument to writeByte
was intended to be a value in the range
0
through 255
.
readUnsignedByte
in interface java.io.DataInput
java.io.EOFException
- if this stream reaches the end before reading
all the bytes.
java.io.IOException
- if an I/O error occurs.public short readShort() throws java.io.EOFException, java.io.IOException
short
value. Let a
be the first byte read and b
be the second byte. The value
returned
is:
(short)((a << 8) | (b & 0xff))
This method
is suitable for reading the bytes written
by the writeShort
method of
interface DataOutput
.
readShort
in interface java.io.DataInput
java.io.EOFException
- if this stream reaches the end before reading
all the bytes.
java.io.IOException
- if an I/O error occurs.public int readUnsignedShort() throws java.io.EOFException, java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.EOFException
java.io.IOException
public char readChar() throws java.io.EOFException, java.io.IOException
readChar
in interface java.io.DataInput
java.io.EOFException
java.io.IOException
public int readInt() throws java.io.EOFException, java.io.IOException
readInt
in interface java.io.DataInput
java.io.EOFException
java.io.IOException
public long readLong() throws java.io.EOFException, java.io.IOException
readLong
in interface java.io.DataInput
java.io.EOFException
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
method of DataInput
.
Bytes for this operation are read from the contained input stream.
readFloat
in interface java.io.DataInput
float
.
java.io.EOFException
- if this input stream reaches the end before
reading four bytes.
java.io.IOException
- if an I/O error occurs.DataInputStream.readInt()
,
Float.intBitsToFloat(int)
public double readDouble() throws java.io.IOException
readDouble
method of DataInput
.
Bytes for this operation are read from the contained input stream.
readDouble
in interface java.io.DataInput
double
.
java.io.EOFException
- if this input stream reaches the end before
reading eight bytes.
java.io.IOException
- if an I/O error occurs.DataInputStream.readLong()
,
Double.longBitsToDouble(long)
public java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public void seek(long pos) throws java.io.IOException
pos
-
java.io.IOException
public long getPos()
public long skipBytes(long n) throws java.io.IOException
n
-
java.io.EOFException
java.io.IOException
public int getCapacity()
public long available() throws java.io.IOException
count - pos
, which
is the number of bytes remaining to be read from the input buffer.
java.io.IOException
public long length()
public void close() throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
private final int read1() throws java.io.IOException, java.io.EOFException
int
in the range
0
to 255
. If no byte is available
because the end of the stream has been reached, the value
-1
is returned.
This read
method cannot block.
int
.
java.io.EOFException
- if this input stream has reached the end.
java.io.IOException
- if an I/O error occurs.private void readBuffer() throws java.io.EOFException, java.io.IOException
java.io.EOFException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |