|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sentilla.io.ByteBuffer
public class ByteBuffer
A stream access wrapper around a byte array. Tracks the size of the array contents and allows for platform-independent reading and writing of primitive types and Objects using stream access methods.
Field Summary | |
---|---|
byte[] |
data
Data buffer |
int |
end
End of the data in data |
int |
start
Start of the data in data |
Constructor Summary | |
---|---|
ByteBuffer()
Create a new zero-length byte buffer with no associated data
array. |
|
ByteBuffer(byte[] data,
int start,
int end)
Wrap an existing byte array into a ByteBuffer. |
|
ByteBuffer(int maxlength)
Create (allocate) a new byte buffer of specified length. |
Method Summary | |
---|---|
int |
available()
Get the available number of remaining bytes in the byte buffer stream. |
void |
clear()
Empty the buffer. |
void |
close()
Close the byte buffer stream. |
int |
cmp(ByteBuffer b)
Check if a given ByteBuffer is equal to this byte buffer. |
void |
flush()
Flush the stream writes (commit). |
byte[] |
getData()
Return a copy of the current buffer contents as a byte array. |
byte |
read()
Read a byte. |
int |
read(byte[] b)
Read bytes from the byte buffer stream into a byte array. |
int |
read(byte[] b,
int offset,
int length)
Read a specified length of bytes from the byte buffer stream into a byte array starting at a given offset in the destination array. |
int |
read(ByteBuffer b,
int length)
Read a specified length of bytes from the byte buffer stream into another ByteBuffer |
boolean |
readBoolean()
Read a boolean value from the buffer. |
byte |
readByte()
Read a byte value from the buffer. |
char |
readChar()
Read a char value from the buffer. |
double |
readDouble()
Read a double value from the buffer. |
float |
readFloat()
Read a float value from the buffer. |
int |
readInt()
Read an int value from the buffer. |
long |
readLong()
Read a long value from the buffer. |
Object |
readObject()
Read a serialized object from the byte buffer. |
short |
readShort()
Read a short value from the buffer. |
int |
readUnsignedByte()
Read an unsigned byte value from the buffer. |
String |
readUTF()
Read a String value from the buffer. |
void |
skip(int n)
Skip bytes in the byte buffer stream. |
void |
write(byte[] b)
Write bytes into the byte buffer. |
void |
write(byte[] b,
int offset,
int length)
Write bytes into the byte buffer. |
void |
write(ByteBuffer b)
Write bytes into the byte buffer. |
void |
write(ByteBuffer b,
int length)
Write bytes into the byte buffer. |
void |
write(int b)
Write a byte into the byte buffer. |
void |
writeBoolean(boolean a)
Write a boolean value to the buffer. |
void |
writeByte(int a)
Write a byte value to the buffer. |
void |
writeChar(int a)
Write a char value to the buffer. |
void |
writeDouble(double a)
Write a double value to the buffer. |
void |
writeFloat(float a)
Write a float value to the buffer. |
void |
writeInt(int a)
Write an int value to the buffer. |
void |
writeLong(long a)
Write a long value to the buffer. |
void |
writeObject(Object o)
Write a serialized representation of the object into the byte buffer. |
void |
writeShort(int a)
Write a short value to the buffer. |
void |
writeUTF(String s)
Write a String object to the buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int start
data
public int end
data
public byte[] data
Constructor Detail |
---|
public ByteBuffer()
data
array.
public ByteBuffer(int maxlength)
maxlength
- Length of the buffer.public ByteBuffer(byte[] data, int start, int end)
data
- existing byte arraystart
- start buffer positionend
- end buffer positionMethod Detail |
---|
public void clear()
data
array.
public byte[] getData()
public void close()
close
in interface Input
close
in interface Output
public int available()
available
in interface InputStream
public void skip(int n) throws IORuntimeException
skip
in interface Input
n
- number of bytes to skip
IORuntimeException
- if the number of bytes to skip is more than the available bytes in the streampublic byte read() throws IORuntimeException
read
in interface Input
IORuntimeException
- if the stream cannot be read or is at the endpublic int read(byte[] b) throws IORuntimeException
read
in interface Input
b
- array to read bytes into from the stream
IORuntimeException
- if an error occurs during the read processpublic int read(ByteBuffer b, int length) throws IORuntimeException
b
- byte read destinationlength
- number of bytes to read
IORuntimeException
- if an error occurs during the read processpublic int read(byte[] b, int offset, int length) throws IORuntimeException
read
in interface Input
b
- byte read destinationoffset
- position to start in the destination array b
length
- number of bytes to read
IORuntimeException
- if an error occurs during the read processpublic void write(int b) throws IORuntimeException
write
in interface Output
b
- byte to write
IORuntimeException
- if the write exceeds the maximum size of the bufferpublic void write(byte[] b) throws IORuntimeException
write
in interface Output
b
- byte array to write
IORuntimeException
- if the write exceeds the maximum size of the bufferpublic void write(ByteBuffer b, int length) throws IORuntimeException
b
- ByteBuffer to writelength
- number of bytes to write
IORuntimeException
- if the write exceeds the maximum size of the bufferpublic void write(ByteBuffer b) throws IORuntimeException
b
- ByteBuffer to write, b.available()
bytes will be written
IORuntimeException
- if the write exceeds the maximum size of the bufferpublic void write(byte[] b, int offset, int length) throws IORuntimeException
write
in interface Output
b
- byte array to writeoffset
- offset in input array b
where the write should startlength
- number of bytes to write
IORuntimeException
- if the write exceeds the maximum size of the bufferpublic void flush() throws IORuntimeException
flush
in interface Output
IORuntimeException
- if an error occurs during the flushpublic boolean readBoolean() throws IORuntimeException
boolean
value from the buffer.
readBoolean
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic byte readByte() throws IORuntimeException
byte
value from the buffer.
readByte
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic int readInt() throws IORuntimeException
int
value from the buffer.
readInt
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic long readLong() throws IORuntimeException
long
value from the buffer.
readLong
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic short readShort() throws IORuntimeException
short
value from the buffer.
readShort
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic int readUnsignedByte() throws IORuntimeException
byte
value from the buffer.
readUnsignedByte
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic char readChar() throws IORuntimeException
char
value from the buffer.
readChar
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic float readFloat() throws IORuntimeException
float
value from the buffer.
readFloat
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic double readDouble() throws IORuntimeException
double
value from the buffer.
readDouble
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic String readUTF() throws IORuntimeException
String
value from the buffer.
readUTF
in interface DataInput
IORuntimeException
- if no value can be read or the end of the buffer is reachedpublic void writeBoolean(boolean a) throws IORuntimeException
boolean
value to the buffer.
writeBoolean
in interface DataOutput
a
- boolean value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeByte(int a) throws IORuntimeException
byte
value to the buffer.
writeByte
in interface DataOutput
a
- byte value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeInt(int a) throws IORuntimeException
int
value to the buffer.
writeInt
in interface DataOutput
a
- int value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeLong(long a) throws IORuntimeException
long
value to the buffer.
writeLong
in interface DataOutput
a
- long value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeShort(int a) throws IORuntimeException
short
value to the buffer.
writeShort
in interface DataOutput
a
- short value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeChar(int a) throws IORuntimeException
char
value to the buffer.
writeChar
in interface DataOutput
a
- char value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeFloat(float a) throws IORuntimeException
float
value to the buffer.
writeFloat
in interface DataOutput
a
- float value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeDouble(double a) throws IORuntimeException
double
value to the buffer.
writeDouble
in interface DataOutput
a
- double value
IORuntimeException
- if the write operation exceeds the length of the bufferpublic void writeUTF(String s) throws IORuntimeException
String
object to the buffer.
writeUTF
in interface DataOutput
s
- String object
IORuntimeException
- if the write operation exceeds the length of the bufferpublic int cmp(ByteBuffer b)
b
- buffer to compare
public void writeObject(Object o)
writeObject
in interface ObjectOutput
writeObject
in interface ObjectOutputStream
o
- Object to write must implement java.io.Serializablepublic Object readObject()
readObject
in interface ObjectInput
readObject
in interface ObjectInputStream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |