|
|
@ -59,9 +59,9 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer() {
|
|
|
|
public serverByteBuffer() {
|
|
|
|
buffer = new byte[80];
|
|
|
|
buffer = new byte[80];
|
|
|
|
length = 0;
|
|
|
|
length = 0;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer(int initLength) {
|
|
|
|
public serverByteBuffer(int initLength) {
|
|
|
@ -71,72 +71,72 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer(byte[] bb) {
|
|
|
|
public serverByteBuffer(byte[] bb) {
|
|
|
|
buffer = bb;
|
|
|
|
buffer = bb;
|
|
|
|
length = bb.length;
|
|
|
|
length = bb.length;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer(byte[] bb, int initLength) {
|
|
|
|
public serverByteBuffer(byte[] bb, int initLength) {
|
|
|
|
this.buffer = new byte[initLength];
|
|
|
|
this.buffer = new byte[initLength];
|
|
|
|
System.arraycopy(bb, 0, buffer, 0, bb.length);
|
|
|
|
System.arraycopy(bb, 0, buffer, 0, bb.length);
|
|
|
|
length = bb.length;
|
|
|
|
length = bb.length;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer(byte[] bb, int of, int le) {
|
|
|
|
public serverByteBuffer(byte[] bb, int of, int le) {
|
|
|
|
if (of * 2 > bb.length) {
|
|
|
|
if (of * 2 > bb.length) {
|
|
|
|
buffer = new byte[le];
|
|
|
|
buffer = new byte[le];
|
|
|
|
System.arraycopy(bb, of, buffer, 0, le);
|
|
|
|
System.arraycopy(bb, of, buffer, 0, le);
|
|
|
|
length = le;
|
|
|
|
length = le;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
buffer = bb;
|
|
|
|
buffer = bb;
|
|
|
|
length = le;
|
|
|
|
length = le;
|
|
|
|
offset = of;
|
|
|
|
offset = of;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer(serverByteBuffer bb) {
|
|
|
|
public serverByteBuffer(serverByteBuffer bb) {
|
|
|
|
buffer = bb.buffer;
|
|
|
|
buffer = bb.buffer;
|
|
|
|
length = bb.length;
|
|
|
|
length = bb.length;
|
|
|
|
offset = bb.offset;
|
|
|
|
offset = bb.offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer(File f) throws IOException {
|
|
|
|
public serverByteBuffer(File f) throws IOException {
|
|
|
|
// initially fill the byte buffer with the content of a file
|
|
|
|
// initially fill the byte buffer with the content of a file
|
|
|
|
if (f.length() > (long) Integer.MAX_VALUE) throw new IOException("file is too large for buffering");
|
|
|
|
if (f.length() > (long) Integer.MAX_VALUE) throw new IOException("file is too large for buffering");
|
|
|
|
|
|
|
|
|
|
|
|
length = (int) f.length();
|
|
|
|
length = (int) f.length();
|
|
|
|
buffer = new byte[length];
|
|
|
|
buffer = new byte[length];
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
FileInputStream fis = new FileInputStream(f);
|
|
|
|
FileInputStream fis = new FileInputStream(f);
|
|
|
|
// byte[] buf = new byte[512];
|
|
|
|
// byte[] buf = new byte[512];
|
|
|
|
// int p = 0;
|
|
|
|
// int p = 0;
|
|
|
|
// while ((l = fis.read(buf)) > 0) {
|
|
|
|
// while ((l = fis.read(buf)) > 0) {
|
|
|
|
// System.arraycopy(buf, 0, buffer, p, l);
|
|
|
|
// System.arraycopy(buf, 0, buffer, p, l);
|
|
|
|
// p += l;
|
|
|
|
// p += l;
|
|
|
|
/*int l =*/ fis.read(buffer);
|
|
|
|
/*int l =*/ fis.read(buffer);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
fis.close();
|
|
|
|
fis.close();
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
throw new IOException("File not found: " + f.toString() + "; " + e.getMessage());
|
|
|
|
throw new IOException("File not found: " + f.toString() + "; " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int length() {
|
|
|
|
public int length() {
|
|
|
|
return length;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void grow() {
|
|
|
|
private void grow() {
|
|
|
|
int newsize = buffer.length * 2 + 1;
|
|
|
|
int newsize = buffer.length * 2 + 1;
|
|
|
|
if (newsize < 256) newsize = 256;
|
|
|
|
if (newsize < 256) newsize = 256;
|
|
|
|
byte[] tmp = new byte[newsize];
|
|
|
|
byte[] tmp = new byte[newsize];
|
|
|
|
System.arraycopy(buffer, offset, tmp, 0, length);
|
|
|
|
System.arraycopy(buffer, offset, tmp, 0, length);
|
|
|
|
buffer = tmp;
|
|
|
|
buffer = tmp;
|
|
|
|
tmp = null;
|
|
|
|
tmp = null;
|
|
|
|
offset = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void write(int b) {
|
|
|
|
public void write(int b) {
|
|
|
@ -145,7 +145,7 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
|
|
|
|
|
|
|
|
public void write(byte b) {
|
|
|
|
public void write(byte b) {
|
|
|
|
if (offset + length + 1 > buffer.length) grow();
|
|
|
|
if (offset + length + 1 > buffer.length) grow();
|
|
|
|
buffer[offset + length++] = b;
|
|
|
|
buffer[offset + length++] = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void write(byte[] bb) {
|
|
|
|
public void write(byte[] bb) {
|
|
|
@ -154,18 +154,18 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
|
|
|
|
|
|
|
|
public void write(byte[] bb, int of, int le) {
|
|
|
|
public void write(byte[] bb, int of, int le) {
|
|
|
|
while (offset + length + le > buffer.length) grow();
|
|
|
|
while (offset + length + le > buffer.length) grow();
|
|
|
|
System.arraycopy(bb, of, buffer, offset + length, le);
|
|
|
|
System.arraycopy(bb, of, buffer, offset + length, le);
|
|
|
|
length += le;
|
|
|
|
length += le;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(byte b) {
|
|
|
|
public serverByteBuffer append(byte b) {
|
|
|
|
write(b);
|
|
|
|
write(b);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(int i) {
|
|
|
|
public serverByteBuffer append(int i) {
|
|
|
|
write((byte) (i & 0xFF));
|
|
|
|
write((byte) (i & 0xFF));
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(byte[] bb) {
|
|
|
|
public serverByteBuffer append(byte[] bb) {
|
|
|
@ -174,16 +174,16 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(byte[] bb, int of, int le) {
|
|
|
|
public serverByteBuffer append(byte[] bb, int of, int le) {
|
|
|
|
write(bb, of, le);
|
|
|
|
write(bb, of, le);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(String s) {
|
|
|
|
public serverByteBuffer append(String s) {
|
|
|
|
return append(s.getBytes());
|
|
|
|
return append(s.getBytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(serverByteBuffer bb) {
|
|
|
|
public serverByteBuffer append(serverByteBuffer bb) {
|
|
|
|
return append(bb.buffer, bb.offset, bb.length);
|
|
|
|
return append(bb.buffer, bb.offset, bb.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer append(Object o) {
|
|
|
|
public serverByteBuffer append(Object o) {
|
|
|
@ -193,66 +193,66 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte byteAt(int pos) {
|
|
|
|
public byte byteAt(int pos) {
|
|
|
|
if (pos > length) return -1;
|
|
|
|
if (pos > length) return -1;
|
|
|
|
return buffer[offset + pos];
|
|
|
|
return buffer[offset + pos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int indexOf(byte b) {
|
|
|
|
public int indexOf(byte b) {
|
|
|
|
return indexOf(b, 0);
|
|
|
|
return indexOf(b, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int indexOf(byte b, int start) {
|
|
|
|
public int indexOf(byte b, int start) {
|
|
|
|
if (start >= length) return -1;
|
|
|
|
if (start >= length) return -1;
|
|
|
|
for (int i = start; i < length; i++) if (buffer[offset + i] == b) return i;
|
|
|
|
for (int i = start; i < length; i++) if (buffer[offset + i] == b) return i;
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int lastIndexOf(byte b) {
|
|
|
|
public int lastIndexOf(byte b) {
|
|
|
|
for (int i = length - 1; i >= 0; i--) if (buffer[offset + i] == b) return i;
|
|
|
|
for (int i = length - 1; i >= 0; i--) if (buffer[offset + i] == b) return i;
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] getBytes() {
|
|
|
|
public byte[] getBytes() {
|
|
|
|
return getBytes(0);
|
|
|
|
return getBytes(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] getBytes(int start) {
|
|
|
|
public byte[] getBytes(int start) {
|
|
|
|
return getBytes(start, length);
|
|
|
|
return getBytes(start, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] getBytes(int start, int end) {
|
|
|
|
public byte[] getBytes(int start, int end) {
|
|
|
|
// start is inclusive, end is exclusive
|
|
|
|
// start is inclusive, end is exclusive
|
|
|
|
if (end > length) throw new IndexOutOfBoundsException("getBytes: end > length");
|
|
|
|
if (end > length) throw new IndexOutOfBoundsException("getBytes: end > length");
|
|
|
|
if (start > length) throw new IndexOutOfBoundsException("getBytes: start > length");
|
|
|
|
if (start > length) throw new IndexOutOfBoundsException("getBytes: start > length");
|
|
|
|
byte[] tmp = new byte[end - start];
|
|
|
|
byte[] tmp = new byte[end - start];
|
|
|
|
System.arraycopy(buffer, offset + start, tmp, 0, end - start);
|
|
|
|
System.arraycopy(buffer, offset + start, tmp, 0, end - start);
|
|
|
|
return tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
private serverByteBuffer trim(int start) {
|
|
|
|
private serverByteBuffer trim(int start) {
|
|
|
|
if (start > length) throw new IndexOutOfBoundsException("trim: start > length");
|
|
|
|
if (start > length) throw new IndexOutOfBoundsException("trim: start > length");
|
|
|
|
offset = offset + start;
|
|
|
|
offset = offset + start;
|
|
|
|
length = length - start;
|
|
|
|
length = length - start;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
private serverByteBuffer trim(int start, int end) {
|
|
|
|
private serverByteBuffer trim(int start, int end) {
|
|
|
|
// the end value is outside (+1) of the wanted target array
|
|
|
|
// the end value is outside (+1) of the wanted target array
|
|
|
|
if (start > length) throw new IndexOutOfBoundsException("trim: start > length");
|
|
|
|
if (start > length) throw new IndexOutOfBoundsException("trim: start > length");
|
|
|
|
if (end > length) throw new IndexOutOfBoundsException("trim: end > length");
|
|
|
|
if (end > length) throw new IndexOutOfBoundsException("trim: end > length");
|
|
|
|
if (start > end) throw new IndexOutOfBoundsException("trim: start > end");
|
|
|
|
if (start > end) throw new IndexOutOfBoundsException("trim: start > end");
|
|
|
|
offset = offset + start;
|
|
|
|
offset = offset + start;
|
|
|
|
length = end - start;
|
|
|
|
length = end - start;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public serverByteBuffer trim() {
|
|
|
|
public serverByteBuffer trim() {
|
|
|
|
int l = 0; while ((l < length) && (buffer[offset + l] <= 32)) l++;
|
|
|
|
int l = 0; while ((l < length) && (buffer[offset + l] <= 32)) l++;
|
|
|
|
int r = length; while ((r > 0) && (buffer[offset + r - 1] <= 32)) r--;
|
|
|
|
int r = length; while ((r > 0) && (buffer[offset + r - 1] <= 32)) r--;
|
|
|
|
if (l > r) r = l;
|
|
|
|
if (l > r) r = l;
|
|
|
|
return trim(l, r);
|
|
|
|
return trim(l, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
public String toString() {
|
|
|
@ -260,54 +260,55 @@ public final class serverByteBuffer extends OutputStream {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Properties propParser() {
|
|
|
|
public Properties propParser() {
|
|
|
|
// extract a=b or a="b" - relations from the buffer
|
|
|
|
// extract a=b or a="b" - relations from the buffer
|
|
|
|
int pos = offset;
|
|
|
|
int pos = offset;
|
|
|
|
int start;
|
|
|
|
int start;
|
|
|
|
String key;
|
|
|
|
String key;
|
|
|
|
Properties p = new Properties();
|
|
|
|
Properties p = new Properties();
|
|
|
|
// eat up spaces at beginning
|
|
|
|
// eat up spaces at beginning
|
|
|
|
while ((pos < length) && (buffer[pos] <= 32)) pos++;
|
|
|
|
while ((pos < length) && (buffer[pos] <= 32)) pos++;
|
|
|
|
while (pos < length) {
|
|
|
|
while (pos < length) {
|
|
|
|
// pos is at start of next key
|
|
|
|
// pos is at start of next key
|
|
|
|
start = pos;
|
|
|
|
start = pos;
|
|
|
|
while ((pos < length) && (buffer[pos] != equal)) pos++;
|
|
|
|
while ((pos < length) && (buffer[pos] != equal)) pos++;
|
|
|
|
if (pos >= length) break; // this is the case if we found no equal
|
|
|
|
if (pos >= length) break; // this is the case if we found no equal
|
|
|
|
key = new String(buffer, start, pos - start).trim().toLowerCase();
|
|
|
|
key = new String(buffer, start, pos - start).trim().toLowerCase();
|
|
|
|
// we have a key
|
|
|
|
// we have a key
|
|
|
|
pos++;
|
|
|
|
pos++;
|
|
|
|
// find start of value
|
|
|
|
// find start of value
|
|
|
|
while ((pos < length) && (buffer[pos] <= 32)) pos++;
|
|
|
|
while ((pos < length) && (buffer[pos] <= 32)) pos++;
|
|
|
|
// doublequotes are obligatory. However, we want to be fuzzy if they are ommittet
|
|
|
|
// doublequotes are obligatory. However, we want to be fuzzy if they
|
|
|
|
if (pos >= length) {
|
|
|
|
// are ommittet
|
|
|
|
// error case: input ended too early
|
|
|
|
if (pos >= length) {
|
|
|
|
break;
|
|
|
|
// error case: input ended too early
|
|
|
|
} else if (buffer[pos] == doublequote) {
|
|
|
|
break;
|
|
|
|
// search next doublequote
|
|
|
|
} else if (buffer[pos] == doublequote) {
|
|
|
|
pos++;
|
|
|
|
// search next doublequote
|
|
|
|
start = pos;
|
|
|
|
pos++;
|
|
|
|
while ((pos < length) && (buffer[pos] != doublequote)) pos++;
|
|
|
|
start = pos;
|
|
|
|
if (pos >= length) break; // this is the case if we found no parent doublequote
|
|
|
|
while ((pos < length) && (buffer[pos] != doublequote)) pos++;
|
|
|
|
p.setProperty(key, new String(buffer, start, pos - start).trim());
|
|
|
|
if (pos >= length) break; // this is the case if we found no parent doublequote
|
|
|
|
pos++;
|
|
|
|
p.setProperty(key, new String(buffer, start, pos - start).trim());
|
|
|
|
} else if (buffer[pos] == singlequote) {
|
|
|
|
pos++;
|
|
|
|
// search next singlequote
|
|
|
|
} else if (buffer[pos] == singlequote) {
|
|
|
|
pos++;
|
|
|
|
// search next singlequote
|
|
|
|
start = pos;
|
|
|
|
pos++;
|
|
|
|
while ((pos < length) && (buffer[pos] != singlequote)) pos++;
|
|
|
|
start = pos;
|
|
|
|
if (pos >= length) break; // this is the case if we found no parent singlequote
|
|
|
|
while ((pos < length) && (buffer[pos] != singlequote)) pos++;
|
|
|
|
p.setProperty(key, new String(buffer, start, pos - start).trim());
|
|
|
|
if (pos >= length) break; // this is the case if we found no parent singlequote
|
|
|
|
pos++;
|
|
|
|
p.setProperty(key, new String(buffer, start, pos - start).trim());
|
|
|
|
} else {
|
|
|
|
pos++;
|
|
|
|
// search next whitespace
|
|
|
|
} else {
|
|
|
|
start = pos;
|
|
|
|
// search next whitespace
|
|
|
|
while ((pos < length) && (buffer[pos] > 32)) pos++;
|
|
|
|
start = pos;
|
|
|
|
p.setProperty(key, new String(buffer, start, pos - start).trim());
|
|
|
|
while ((pos < length) && (buffer[pos] > 32)) pos++;
|
|
|
|
}
|
|
|
|
p.setProperty(key, new String(buffer, start, pos - start).trim());
|
|
|
|
// pos should point now to a whitespace: eat up spaces
|
|
|
|
}
|
|
|
|
while ((pos < length) && (buffer[pos] <= 32)) pos++;
|
|
|
|
// pos should point now to a whitespace: eat up spaces
|
|
|
|
// go on with next loop
|
|
|
|
while ((pos < length) && (buffer[pos] <= 32)) pos++;
|
|
|
|
}
|
|
|
|
// go on with next loop
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean equals(byte[] buffer, byte[] pattern) {
|
|
|
|
public static boolean equals(byte[] buffer, byte[] pattern) {
|
|
|
|