Author: jfrederic.clere(a)jboss.com
Date: 2008-08-27 12:00:49 -0400 (Wed, 27 Aug 2008)
New Revision: 1770
Modified:
sandbox/mod_jk/TraceAna.java
Log:
Allow truncated messages to be analysed.
Modified: sandbox/mod_jk/TraceAna.java
===================================================================
--- sandbox/mod_jk/TraceAna.java 2008-08-19 17:04:24 UTC (rev 1769)
+++ sandbox/mod_jk/TraceAna.java 2008-08-27 16:00:49 UTC (rev 1770)
@@ -27,11 +27,13 @@
public class TraceAna {
private int pos = 0; /* position in the buffer */
+ private int size = 0; /* size of the received data */
private ByteBuffer buf; /* ByteBuffer to use */
TraceAna(int size) {
buf = ByteBuffer.allocate(size);
}
void putByte(byte b) {
+ size++;
buf.put(b);
}
private int getShort(int offset) {
@@ -57,9 +59,14 @@
return(getByte());
}
private byte getByte() {
- byte b1;
- b1 = buf.get(pos);
- pos++;
+ byte b1 =-1;
+ try {
+ b1 = buf.get(pos);
+ pos++;
+ } catch(IndexOutOfBoundsException ex) {
+ }
+ if (pos > size)
+ return -1; /* outside buffer... */
return b1;
}
private boolean isByteEgal(byte b) {
@@ -72,16 +79,29 @@
}
private String getString() {
int size;
+ boolean truncated = false;
size = getShort();
if ( size == 65535)
return("NULL");
+
+ /* prevent the size to be bigger than the read data */
+ if (this.size-pos <size) {
+ size = this.size - pos;
+ truncated = true;
+ }
byte [] buffet = new byte[size];
for (int i=0; i<size; i++) {
buffet[i] = buf.get(pos);
pos++;
}
pos++; // zero byte.
- return new String(buffet);
+ String ssize = String.valueOf(size);
+ ssize = ssize.concat(" ");
+ ssize = ssize.concat(new String(buffet));
+ if (truncated) {
+ ssize = ssize.concat(" [TRUNCATED!!!]");
+ }
+ return ssize;
}
private static int HexVal(char c) {
Show replies by date