Methods Summary |
---|
public void | addByte(int b)Adds byte to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
checkSpace(1);
int where = CurrentSize;
CurrentSize++;
try {
putByte(where, b);
}
catch (BoundException e) {};
|
public void | addBytes(byte[] b, int start, int len)Adds a number of bytes to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
checkSpace(len);
int where = CurrentSize;
CurrentSize = CurrentSize + len;
try {
putBytes(where, b, start, len);
}
catch (BoundException e) {};
|
public void | addID(long l, int count)Adds an integer value (int, short, long)
to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
The value is stored in the little endian format.
checkSpace(count);
int where = CurrentSize;
CurrentSize = CurrentSize + count;
try {
putID(where, l, count);
}
catch (BoundException e) {};
|
public void | addInt(int b)Adds int to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
The value is stored in little endian format.
addID(b, 4);
|
public void | addLong(long l)Adds long to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
The value is stored in little endian format.
addID(l, 8);
|
public void | addShort(int b)Adds short to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
The value is stored in little endian format.
addID(b, 2);
|
public void | addString(java.lang.String s)Adds String to the end of the filled part of the buffer.
If there is no place to
store this data the buffer is automatically increased.
The value is stored in UTF-8 format.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try{
dos.writeUTF(s);
}catch(IOException e ){
System.err.println("Error creating the UTF-8 sring");
return;
}
byte[] buf = baos.toByteArray();
int len = ((buf[0] << 8) & 0xFF00) | (buf[1] & 0xFF);
addByte(0);
addByte(0);
addBytes(buf, 0, len + 2);
|
private void | checkSpace(int Space)Checks if the buffer is large enough to place the
specified number of bytes. If no, the buffer is
automatically increased to necessary size.
if (bytes.length >= CurrentSize + Space)
return;
int NewSize = bytes.length;
while (NewSize < CurrentSize + Space)
NewSize = NewSize + Delta;
byte[] NewData = new byte[NewSize];
for (int i = 0; i < CurrentSize; i++)
NewData[i] = bytes[i];
bytes = NewData;
|
public void | deleteBytes(int count)Deletes a few bytes from the beginning of the buffer and copies the
last part to the beginning of the buffer.
int j = 0;
while (count < CurrentSize)
bytes[j++] = bytes[count++];
CurrentSize = j;
|
public int | getByte()Tries to read next byte from the buffer. Byte is to read is one
that is pointed by reading marker. After completing the operation
the reading marker is incremented.
if (parseOffset >= CurrentSize)
throw new BoundException();
return (int) (bytes[parseOffset++] & 0xFF);
|
public int | getByte(int off)Tries to read a single byte from the buffer. Byte is to read is
located at specified index.
int old_offset = parseOffset;
parseOffset = off;
int r = getByte();
parseOffset = old_offset;
return r;
|
public long | getID(int count)Tries to read next integer value (short, int, long) from the buffer.
Value is read is one
that is pointed by reading marker. After completing the operation
the reading marker is incremented. The value is stored in little endian
format.
if ((count <= 0) || (count > 8))
throw new BoundException();
long l = 0;
for (int i = 0; i < count; i++)
l = (l * 0x100) + getByte();
return l;
|
public long | getID(int off, int count)Tries to read an integer value (short, int, long) from the buffer.
Value is to read is located at specified index. The value is stored in
little endian format.
int old_offset = parseOffset;
parseOffset = off;
long l = getID(count);
parseOffset = old_offset;
return l;
|
public int | getInt()Tries to read next int from the buffer.
Value is read is one
that is pointed by reading marker. After completing the operation
the reading marker is incremented. The value is stored in little endian
format.
return (int) getID(4);
|
public int | getInt(int off)Tries to read an int value from the buffer.
Value is to read is located at specified index. The value is stored in
little endian format.
return (int) getID(off, 4);
|
public long | getLong()Tries to read next long from the buffer.
Value is read is one
that is pointed by reading marker. After completing the operation
the reading marker is incremented. The value is stored in little endian
format.
return getID(8);
|
public long | getLong(int off)Tries to read an long value from the buffer.
Value is to read is located at specified index. The value is stored in
little endian format.
return getID(off, 8);
|
public int | getShort()Tries to read next short from the buffer.
Value is read is one
that is pointed by reading marker. After completing the operation
the reading marker is incremented. The value is stored in little endian
format.
return (int) getID(2);
|
public int | getShort(int off)Tries to read an short value from the buffer.
Value is to read is located at specified index. The value is stored in
little endian format.
return (int) getID(off, 2);
|
public java.lang.String | getString()Tries to read next string from the buffer.
Value is read is one
that is pointed by reading marker. After completing the operation
the reading marker is incremented. The value is stored in UTF-8
format.
int l = getInt();
if (l < 0)
throw new BoundException();
if (l == 0)
return "";
byte[] d = new byte[l+2];
d[0] = (byte)((l >> 8) & 0xFF);
d[1] = (byte)(l & 0xFF);
for (int i = 0; i < l; i++){
d[i+2] = (byte) getByte();
}
ByteArrayInputStream bais = new ByteArrayInputStream(d);
DataInputStream dis = new DataInputStream(bais);
try{
String res = dis.readUTF();
return res;
}catch(IOException e){
throw new BoundException(e.getMessage());
}
|
public java.lang.String | getString(int off)Tries to read a string from the buffer.
The string is to read is located at specified index. The value is stored
in UTF-8 format.
int old_offset = parseOffset;
parseOffset = off;
String s = getString();
parseOffset = old_offset;
return s;
|
public boolean | isParsed()Checks if reading marker points to the end of filled data of the
buffer. This method is analogue of eof method for the
files.
return (parseOffset == CurrentSize);
|
public int | length()Returns length of the filled part of the buffer
return CurrentSize;
|
public void | putByte(int off, int b)Stores byte at the specified index in the buffer. If specified index
is outside the filled area of the buffer BoundException
is raised.
if ((off < 0) || (off >= CurrentSize))
throw new BoundException();
bytes[off] = (byte) (b & 0xFF);
|
public void | putBytes(int off, byte[] b, int start, int len)Stores a number of bytes at the specified location of the buffer. If
at least one byte is to be stored outside the already filled area of the
buffer BoundException is raised.
for (int i = 0; i < len; i++)
putByte(off++, b[start++]);
|
public void | putID(int off, long l, int count)Stores an integer value (short, int, long) in the buffer. The value is
stored in Java (little endian) format. If at least one byte of the value
is to be placed outside the alrady filled area of the buffer
BoundException is raised
if ((count <= 0) || (count > 8))
throw new BoundException();
int shift = (count - 1) * 8;
for (int i = 0; i < count; i++) {
putByte(off++, (int) ((l >>> shift) & 0xFF));
shift = shift - 8;
}
|
public void | putInt(int off, int b)Stores int value in the buffer starting from specified
index. The value is stored in little endian format.
If at least one byte of the value
is to be placed outside the alrady filled area of the buffer
BoundException is raised.
putID(off, b, 4);
|
public void | putLong(int off, long l)Stores long value in the buffer starting from specified
index. The value is stored in little endian format.
If at least one byte of the value
is to be placed outside the alrady filled area of the buffer
BoundException is raised.
putID(off, l, 8);
|
public void | putShort(int off, int b)Stores short value in the buffer starting from specified
index. The value is stored in little endian format.
If at least one byte of the value
is to be placed outside the alrady filled area of the buffer
BoundException is raised.
putID(off, b, 2);
|
public void | resetBuffer()Clears the buffer by setting the size of the filled area to zero.
The reading marker's position is not affected by this method so if
the reading marker was not positioned to the beginning of the buffer
it'll become to be in invalid position.
CurrentSize = 0;
|
public void | resetParser()Moves the reading marker to the beginning of the buffer.
Typically the process of reading data from the buffer is
organized as follows: at first move the reading marker to the
some start position (for example, in the beginning of the buffer)
and then consequently read the data using get methods (for example,
getInt() ). So the process of reading data from the byte
buffer is looks like reading data from generic stream (for example,
from file).
parseOffset = 0;
|
public void | resetParser(int i)Move the reading marker to the specified position.
parseOffset = i;
|
public java.lang.String | toString(int start)Returns string representation of the contents of the buffer from
the specified index. This method is invoked by KJDB when JDWP reply
packet is not received (usually it's a fatal error)and this information
is useful for localizing the problem.
String Result = "", HexLine = "", DisplayLine = "";
int j = 0;
for (int i = start; i < length(); i++) {
HexLine = HexLine + Tools.Hex(bytes[i], 2) + " ";
if (bytes[i] >= 0 && bytes[i] < 32)
DisplayLine = DisplayLine + ".";
else
DisplayLine = DisplayLine + new String(bytes, i, 1);
if ((i == length() - 1) || (((i - start) & 0x0F) == 0x0F)) {
Result = Result +
Tools.Hex(j, 4) + ": " +
Tools.PadR(HexLine, 48) + " " +
DisplayLine + "\n";
HexLine = "";
DisplayLine = "";
j = j + 16;
}
}
return Result;
|
public java.lang.String | toString()Returns string representation of the object. Currently this method is
not used by KJDB but it may be useful for debugging purposes.
return toString(0);
|