|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--br.usp.ime.jbase.Buffer
Memory buffer with methods for reading/writing Java primitive types from/to a specified position of the buffer.
A Buffer has a constant-sized data area (a byte
array) and offers methods that allow an application to
Buffer, and
Buffer.
java.io.DataInput interface, with an additional parameter that
specifies the Buffer position to read.
Most write methods are similar to the ones of the
java.io.DataOutput interface, with an additional parameter that
specifies the Buffer position to write.
| Constructor Summary | |
Buffer(byte[] buf)
Constructor that takes a byte array
to be used as data area. |
|
Buffer(int size)
Constructor that takes the size of the data area. |
|
| Method Summary | |
byte[] |
data()
Gets the data area. |
static int |
getSizeUTF(java.lang.String s)
Returns how many bytes the string s takes when written
to a Buffer through a writeUTF call. |
void |
read(int pos,
byte[] b)
Reads b.length bytes from position pos
of this Buffer into the array b. |
void |
read(int pos,
byte[] b,
int off,
int len)
Reads len bytes from position pos
of this Buffer into offset off of
b. |
boolean |
readBoolean(int pos)
Reads a boolean value from position pos
of this Buffer. |
byte |
readByte(int pos)
Reads and returns one byte
from position pos of this Buffer. |
char |
readChar(int pos)
Reads two bytes starting at position pos of this
Buffer and returns a char value. |
double |
readDouble(int pos)
Reads eight bytes starting at position pos of this
Buffer and returns a double value. |
float |
readFloat(int pos)
Reads four bytes starting at position pos of this
Buffer and returns a float value. |
int |
readInt(int pos)
Reads four bytes starting at position pos of this
Buffer and returns an int value. |
long |
readLong(int pos)
Reads eight bytes starting at position pos of this
Buffer and returns a long value. |
java.lang.Object |
readObject(int pos,
IntHolder size)
Reads an object from this Buffer, starting at position
pos of the Buffer. |
short |
readShort(int pos)
Reads two bytes starting at position pos of this
Buffer and returns a short value. |
int |
readUnsignedByte(int pos)
Reads one byte from position pos of this
Buffer, zero-extends it an int in the range
0 through 255, and returns the result. |
int |
readUnsignedShort(int pos)
Reads two bytes starting at position pos of this
Buffer and returns an int in the range
0 through 65535. |
java.lang.String |
readUTF(int pos)
Reads a UTF-encoded String starting at position
pos of this Buffer. |
java.lang.String |
readUTF(int pos,
IntHolder size)
Reads a UTF-encoded String starting at position
pos of this Buffer. |
int |
size()
Gets the size of the data area. |
void |
write(int pos,
byte[] b)
Writes to this Buffer, starting at position
pos, all the bytes in array b. |
void |
write(int pos,
byte[] b,
int off,
int len)
Writes to this Buffer, starting at position
pos, len bytes copied from
offset off of array b. |
void |
writeBoolean(int pos,
boolean v)
Writes a boolean value to position pos
of this Buffer. |
void |
writeByte(int pos,
int v)
Writes to position pos of this Buffer
the eight low-order bits of the parameter v. |
void |
writeBytes(int pos,
java.lang.String s)
Writes to this Buffer, starting at position
pos, the low-order bytes of all chars of
a string. |
void |
writeChar(int pos,
int v)
Writes to this Buffer, starting at position
pos, two bytes that comprise a char value. |
void |
writeChars(int pos,
java.lang.String s)
Writes to this Buffer, starting at position
pos, every character in the string s,
in order, two bytes per character. |
void |
writeDouble(int pos,
double v)
Writes to this Buffer, starting at position
pos, eight bytes that comprise a double value. |
void |
writeFloat(int pos,
float v)
Writes to this Buffer, starting at position
pos, four bytes that comprise a float value. |
void |
writeInt(int pos,
int v)
Writes to this Buffer, starting at position
pos, four bytes that comprise an int value. |
void |
writeLong(int pos,
long v)
Writes to this Buffer, starting at position
pos, eight bytes that comprise a long value. |
int |
writeObject(int pos,
int maxCount,
java.lang.Object obj)
Writes an object to this Buffer, starting at position
pos of the Buffer and writing at most
maxCount bytes. |
void |
writeShort(int pos,
int v)
Writes to this Buffer, starting at position
pos, two bytes that comprise ashort value. |
int |
writeUTF(int pos,
int maxCount,
java.lang.String s)
Similar to the writeUTF(int pos, String s) method, but
with an upper limit on the number of bytes written. |
void |
writeUTF(int pos,
java.lang.String s)
Writes to this Buffer, starting at position
pos, two bytes of length information, followed
by the Java modified UTF-8 representation
of every character in the string s. |
| Methods inherited from class java.lang.Object |
|
| Constructor Detail |
public Buffer(int size)
size of the data area.size - length of byte array
to be created and used as data area.public Buffer(byte[] buf)
byte array
to be used as data area.buf - byte array to be used as data area.| Method Detail |
public byte[] data()
Buffer's byte array.public int size()
Buffer's
byte array.
public void read(int pos,
byte[] b,
int off,
int len)
len bytes from position pos
of this Buffer into offset off of
b.pos - the Buffer position where reading startsb - the array that gets the bytes readoff - the position of b that gets the first byte readlen - the number of bytes to read.
public void read(int pos,
byte[] b)
b.length bytes from position pos
of this Buffer into the array b.pos - the Buffer position where reading startsb - the array that gets the bytes readpublic boolean readBoolean(int pos)
boolean value from position pos
of this Buffer.pos - the Buffer position to readtrue if the byte at position pos
is nonzero; false otherwise.public byte readByte(int pos)
byte
from position pos of this Buffer.
The byte is treated as a signed value in
the range -128 through 127,
inclusive.pos - the Buffer position to readbyte read.public char readChar(int pos)
pos of this
Buffer and returns a char value.pos - the position of the first byte to readchar read.public double readDouble(int pos)
pos of this
Buffer and returns a double value.pos - the position of the first byte to readdouble value read.public float readFloat(int pos)
pos of this
Buffer and returns a float value.pos - the position of the first byte to readfloat value read.public int readInt(int pos)
pos of this
Buffer and returns an int value.pos - the position of the first byte to readint value read.public long readLong(int pos)
pos of this
Buffer and returns a long value.pos - the position of the first byte to readlong read.public short readShort(int pos)
pos of this
Buffer and returns a short value.pos - the position of the first byte to readshort value read.public int readUnsignedByte(int pos)
pos of this
Buffer, zero-extends it an int in the range
0 through 255, and returns the result.pos - the position of the first byte to readint value in the range
0 through 255.public int readUnsignedShort(int pos)
pos of this
Buffer and returns an int in the range
0 through 65535.pos - the position of the first byte to readint value in the range 0 through
65535.
public java.lang.String readUTF(int pos,
IntHolder size)
throws java.io.UTFDataFormatException
String starting at position
pos of this Buffer.
The String must have been written encoded in Java modified
UTF-8 format, typically through a call to a writeUTF
method.
For the specification of Java modified UTF-8 format, see the
writeUTF method of the interface
java.io.DataOutput and the
readUTF method of the interface
java.io.DataInput.
pos - the Buffer position where reading startssize - if this parameter is non null, its value field
will be updated with the number of bytes read from the
bufferString readjava.io.UTFDataFormatException - if the bytes starting at position pos do not
represent a valid UTF-8 encoding of a String.writeUTF(int pos, String s),
writeUTF(int pos, int maxCount, String s),
DataInput.readUTF(),
DataOutput.writeUTF(String s).
public java.lang.String readUTF(int pos)
throws java.io.UTFDataFormatException
String starting at position
pos of this Buffer.
The String must have been written encoded in Java modified
UTF-8 format, typically through a call to a writeUTF
method.
For the specification of Java modified UTF-8 format, see the
writeUTF method of the interface
java.io.DataOutput and the
readUTF method of the interface
java.io.DataInput.
pos - the Buffer position where reading startsString readjava.io.UTFDataFormatException - if the bytes starting at position pos do not
represent a valid UTF-8 encoding of a String.writeUTF(int pos, String s),
writeUTF(int pos, int maxCount, String s),
DataInput.readUTF(),
DataOutput.writeUTF(String s).
public java.lang.Object readObject(int pos,
IntHolder size)
throws java.io.IOException,
java.lang.ClassNotFoundException
Buffer, starting at position
pos of the Buffer. The object must have been
written by a call to
writeObject(int pos, int maxCount, Object obj).pos - the Buffer position where reading startssize - if this parameter is non null, its value field
will be updated with the number of bytes read from the
bufferjava.lang.ClassNotFoundException - class of a serialized object cannot be foundjava.io.InvalidClassException - something is wrong with a class used by serializationjava.io.StreamCorruptedException - control information in the stream is inconsistentjava.io.OptionalDataException - primitive data was found in the stream instead of an objectwriteObject(int pos, int maxCount, Object obj).
public void write(int pos,
byte[] b,
int off,
int len)
Buffer, starting at position
pos, len bytes copied from
offset off of array b.pos - the Buffer position where writing startsb - the array from which the bytes are copiedoff - the position of b from which
the first byte is copiedlen - the number of bytes to write.
public void write(int pos,
byte[] b)
Buffer, starting at position
pos, all the bytes in array b.pos - the Buffer position where writing startsb - the array from which the bytes are copied.
public void writeBoolean(int pos,
boolean v)
boolean value to position pos
of this Buffer.
If the parameter v is true, the value
(byte)1 is written; if v is
false, the value (byte)0 is written.
The byte written by this method may be read by the
readBoolean method, which will then return a
boolean equal to v.pos - the Buffer position to writen - the boolean value read.
public void writeByte(int pos,
int v)
pos of this Buffer
the eight low-order bits of the parameter v.
The 24 high-order bits of v
are ignored.
The byte written by this method may be read by the
readByte method, which will then return a
byte equal to (byte)v.pos - the Buffer position to writev - the byte value to be written.
public void writeBytes(int pos,
java.lang.String s)
Buffer, starting at position
pos, the low-order bytes of all chars of
a string.
For every character in the string
s, taken in order, one byte
is written to this Buffer. If
s is null, a NullPointerException
is thrown. If s.length
is zero, then no bytes are written. Otherwise,
the character s[0] is written
first, then s[1], and so on;
the last character written is s[s.length-1].
For each character, one byte is written,
the low-order byte, in exactly the manner
of the writeByte method . The
high-order eight bits of each character
in the string are ignored.
pos - the Buffer position where writing startss - the string with the bytes to be written.
public void writeChar(int pos,
int v)
Buffer, starting at position
pos, two bytes that comprise a char value.
The bytes written by this method may be
read by the readChar method, which
will then return a char equal
to (char)v.pos - the Buffer position where writing startsv - the char value to be written.
public void writeChars(int pos,
java.lang.String s)
Buffer, starting at position
pos, every character in the string s,
in order, two bytes per character. If
s is null, a NullPointerException
is thrown. If s.length
is zero, then no bytes are written. Otherwise,
the character s[0] is written
first, then s[1], and so on;
the last character written is s[s.length-1].
For each character, two bytes are actually written, in exactly the
manner of the writeChar method.
pos - the Buffer position where writing startss - the string to be written.
public void writeDouble(int pos,
double v)
Buffer, starting at position
pos, eight bytes that comprise a double value.
The bytes written by this method may be read by the
readDouble method, which will then return a
double equal to v.pos - the Buffer position where writing startsv - the double value to be written.
public void writeFloat(int pos,
float v)
Buffer, starting at position
pos, four bytes that comprise a float value.
The bytes written by this method may be read by the
readFloat method, which will then return a
float equal to v.pos - the Buffer position where writing startsv - the float value to be written.
public void writeInt(int pos,
int v)
Buffer, starting at position
pos, four bytes that comprise an int value.
The bytes written by this method may be read by the
readInt method, which will then return an
int equal to v.pos - the Buffer position where writing startsv - the int value to be written.
public void writeLong(int pos,
long v)
Buffer, starting at position
pos, eight bytes that comprise a long value.
The bytes written by this method may be read by the
readLong method, which will then return a
long equal to v.pos - the Buffer position where writing startsv - the long value to be written.
public void writeShort(int pos,
int v)
Buffer, starting at position
pos, two bytes that comprise ashort value.
The bytes written by this method may be read by the
readShort method, which will then return a
short equal to (short)v.pos - the Buffer position where writing startsv - the short value to be written.
public void writeUTF(int pos,
java.lang.String s)
throws java.io.UTFDataFormatException
Buffer, starting at position
pos, two bytes of length information, followed
by the Java modified UTF-8 representation
of every character in the string s.
If s is null,
a NullPointerException is thrown.
Each character in the string s
is converted to a group of one, two, or
three bytes, depending on the value of the
character. The bytes written by this method may be read
by the readUTF method, which will then
return a String equal to s.
For the specification of Java modified UTF-8 format, see the
writeUTF method of the interface
java.io.DataOutput and the
readUTF method of the interface
java.io.DataInput.
pos - the Buffer position where writing startss - the string value to be written.java.io.UTFDataFormatException - if the UTF lenght information does not fit in two bytes
(string too long)writeUTF(int pos, int maxCount, String s),
readUTF(int pos),
readUTF(int pos, IntHolder size),
DataInput.readUTF(),
DataOutput.writeUTF(String s).
public int writeUTF(int pos,
int maxCount,
java.lang.String s)
writeUTF(int pos, String s) method, but
with an upper limit on the number of bytes written.
Writes to this Buffer a sequence of at most
maxCount bytes, starting at position pos:
two bytes of length information, followed by the Java modified UTF-8
representation of every character in the string s.
Returns the number of bytes written (including the bytes of lenght
information), or zero if this number would exceed maxCount.
If s is null,
a NullPointerException is thrown.
Each character in the string s
is converted to a group of one, two, or
three bytes, depending on the value of the
character. The bytes written by this method may be read
by the readUTF method, which will then
return a String equal to s.
For the specification of Java modified UTF-8 format, see the
writeUTF method of the interface
java.io.DataOutput and the
readUTF method of the interface
java.io.DataInput.
pos - the Buffer position where writing startsmaxCount - an upper limit on the number of bytes written
(if maxCount is greater than
65535, an upper limit of 65535
is assumed)s - the string value to be writtenwriteUTF(int pos, String s),
readUTF(int pos),
readUTF(int pos, IntHolder size),
DataInput.readUTF(),
DataOutput.writeUTF(String s).
public int writeObject(int pos,
int maxCount,
java.lang.Object obj)
throws java.io.IOException
Buffer, starting at position
pos of the Buffer and writing at most
maxCount bytes.pos - the Buffer position where writing startsmaxCount - an upper limit on the number of bytes writtenobj - the object to be writtenjava.io.IOException - if it would take more than maxCount
bytes to write the object to the BufferreadObject(int pos, IntHolder size).public static int getSizeUTF(java.lang.String s)
s takes when written
to a Buffer through a writeUTF call.s - a stringwriteUTF(int pos, String s),
writeUTF(int pos, int maxCount, String s).
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||