|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectCADI.Common.io.BufferedDataIOStream
public class BufferedDataIOStream
| Field Summary | |
|---|---|
private byte[] |
buf
An array of bytes used to buffer the input/output data. |
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 |
private boolean |
EOFInBuffer
Indicates, when data source is a file, if the End Of File mark is reached. |
private java.io.RandomAccessFile |
file
|
private long |
filePos
Indicates the offset of the file where data are from. |
(package private) boolean |
isChangedBuf
Indicates if the buf has been changed since the last time it was written in the file. |
(package private) boolean |
isResizeAllowed
Indicates if the buffer size can be resized. |
private int |
mode
It is the buffer access. |
private static int |
MODE_R
|
private static int |
MODE_RW
|
private static int |
MODE_RWU
|
private int |
offset
Indicates the first available data in the buffer. |
private int |
pos
The index of the next byte to read/write from/to the buffer. |
private boolean |
useFile
Indicates the data source, whether data is readed from file or no. |
| Constructor Summary | |
|---|---|
BufferedDataIOStream(java.io.File file,
java.lang.String mode)
|
|
BufferedDataIOStream(int sz,
java.lang.String mode)
Constructor. |
|
BufferedDataIOStream(java.io.RandomAccessFile file)
|
|
BufferedDataIOStream(java.lang.String name,
java.lang.String mode)
|
|
| Method Summary | |
|---|---|
long |
available()
Returns the number of bytes that can be read from this buffer without blocking. |
void |
close()
|
void |
flush()
Data stored in the buff must be written in a file. |
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()
|
private void |
resizeBuffer(int newSize)
|
void |
seek(long pos)
|
private void |
setMode(java.lang.String mode)
|
void |
setResizable(boolean isResizeAllowed)
Sets if buffer can be resized or not. |
int |
skipBytes(int n)
|
long |
skipBytes(long n)
|
java.lang.String |
toString()
For debugging purpose. |
void |
write(byte[] b)
Writes to the output stream all the bytes in array b. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from array
b, in order, to
the output stream. |
void |
write(int b)
Writes to the output stream the eight low-order bits of the argument b. |
void |
writeBoolean(boolean v)
Writes a boolean to the underlying output stream as
a 1-byte value. |
void |
writeByte(int v)
|
void |
writeBytes(java.lang.String s)
|
void |
writeChar(int v)
|
void |
writeChars(java.lang.String s)
|
void |
writeDouble(double v)
|
void |
writeFloat(float v)
|
void |
writeInt(int v)
|
void |
writeLong(long v)
|
void |
writeShort(int v)
|
void |
writeUTF(java.lang.String s)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private 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.
private 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].
private 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.
private int offset
private java.io.RandomAccessFile file
private long filePos
private boolean EOFInBuffer
buf contains the last bytes of the file.
private int mode
private static int MODE_R
private static int MODE_RW
private static int MODE_RWU
private boolean useFile
boolean isChangedBuf
boolean isResizeAllowed
writeToFile is false.
private static int DEFAULT_BUFFER_SIZE
| Constructor Detail |
|---|
public BufferedDataIOStream(int sz,
java.lang.String mode)
sz - buffer size
public BufferedDataIOStream(java.lang.String name,
java.lang.String mode)
throws java.io.FileNotFoundException
name -
java.io.FileNotFoundException
public BufferedDataIOStream(java.io.File file,
java.lang.String mode)
throws java.io.FileNotFoundException
file -
java.io.FileNotFoundException
public BufferedDataIOStream(java.io.RandomAccessFile file)
throws java.io.FileNotFoundException
file -
java.io.FileNotFoundException| Method Detail |
|---|
public void setResizable(boolean isResizeAllowed)
isResizeAllowed -
public void write(int b)
throws java.io.IOException
b.
The 24 high-order bits of b
are ignored.
write in interface java.io.DataOutputb - the byte to be written.
java.io.IOException - if an I/O error occurs.
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 write(byte[] b)
throws java.io.IOException
b.
If b is null,
a NullPointerException is thrown.
If b.length is zero, then
no bytes are written. Otherwise, the byte
b[0] is written first, then
b[1], and so on; the last byte
written is b[b.length-1].
write in interface java.io.DataOutputb - the data.
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.DataInputb - 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 write(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes from array
b, in order, to
the output stream. If b
is null, a NullPointerException
is thrown. If off is negative,
or len is negative, or off+len
is greater than the length of the array
b, then an IndexOutOfBoundsException
is thrown. If len is zero,
then no bytes are written. Otherwise, the
byte b[off] is written first,
then b[off+1], and so on; the
last byte written is b[off+len-1].
write in interface java.io.DataOutputb - 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 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.DataInputb - 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.DataInputjava.io.IOException
public void writeBoolean(boolean v)
throws java.io.IOException
boolean to the underlying output stream 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. If no exception is
thrown, the counter written is incremented by
1.
writeBoolean in interface java.io.DataOutputv - a boolean value to be written.
java.io.IOException - if an I/O error occurs.FilterOutputStream.out
public boolean readBoolean()
throws java.io.IOException
readBoolean in interface java.io.DataInputjava.io.IOException
public void writeByte(int v)
throws java.io.IOException
writeByte in interface java.io.DataOutputjava.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.DataInputbyte.
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.DataInputjava.io.EOFException - if this stream reaches the end before reading
all the bytes.
java.io.IOException - if an I/O error occurs.
public void writeShort(int v)
throws java.io.IOException
writeShort in interface java.io.DataOutputjava.io.IOException
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.DataInputjava.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.DataInputjava.io.EOFException
java.io.IOException
public void writeChar(int v)
throws java.io.IOException
writeChar in interface java.io.DataOutputjava.io.IOException
public char readChar()
throws java.io.EOFException,
java.io.IOException
readChar in interface java.io.DataInputjava.io.EOFException
java.io.IOException
public void writeInt(int v)
throws java.io.IOException
writeInt in interface java.io.DataOutputjava.io.IOException
public int readInt()
throws java.io.EOFException,
java.io.IOException
readInt in interface java.io.DataInputjava.io.EOFException
java.io.IOException
public void writeLong(long v)
throws java.io.IOException
writeLong in interface java.io.DataOutputjava.io.IOException
public long readLong()
throws java.io.EOFException,
java.io.IOException
readLong in interface java.io.DataInputjava.io.EOFException
java.io.IOException
public void writeFloat(float v)
throws java.io.IOException
writeFloat in interface java.io.DataOutputjava.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.DataInputfloat.
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 void writeDouble(double v)
throws java.io.IOException
writeDouble in interface java.io.DataOutputjava.io.IOException
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.DataInputdouble.
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 void writeBytes(java.lang.String s)
throws java.io.IOException
writeBytes in interface java.io.DataOutputjava.io.IOException
public void writeChars(java.lang.String s)
throws java.io.IOException
writeChars in interface java.io.DataOutputjava.io.IOException
public void writeUTF(java.lang.String s)
throws java.io.IOException
writeUTF in interface java.io.DataOutputjava.io.IOException
public java.lang.String readLine()
throws java.io.IOException
readLine in interface java.io.DataInputjava.io.IOException
public java.lang.String readUTF()
throws java.io.IOException
readUTF in interface java.io.DataInputjava.io.IOException
public void seek(long pos)
throws java.io.IOException
pos -
java.io.IOExceptionpublic long getPos()
public long skipBytes(long n)
throws java.io.IOException
n -
java.io.EOFException
java.io.IOExceptionpublic 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.IOExceptionpublic long length()
public final void flush()
throws java.io.IOException
buff must be written in a file.
Buffer is reseted to its initial state.
java.io.IOException - If an I/O error ocurred.
public void close()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectprivate void setMode(java.lang.String mode)
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.IOExceptionprivate void resizeBuffer(int newSize)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||