2004-12-08 jrandom
* Revised the buffering when reading from the SAM client and writing to the stream. Also added a thread (sigh) so we don't block the SAM client from giving us more messages for abnormally long periods of time. * Display the router version in the logs on startup (oft requested) * Fix a race during the closing of a messageOutputStream
This commit is contained in:
@ -18,6 +18,7 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class ByteArray implements Serializable, Comparable {
|
||||
private byte[] _data;
|
||||
private int _valid;
|
||||
|
||||
public ByteArray() {
|
||||
this(null);
|
||||
@ -25,6 +26,7 @@ public class ByteArray implements Serializable, Comparable {
|
||||
|
||||
public ByteArray(byte[] data) {
|
||||
_data = data;
|
||||
_valid = 0;
|
||||
}
|
||||
|
||||
public final byte[] getData() {
|
||||
@ -34,6 +36,14 @@ public class ByteArray implements Serializable, Comparable {
|
||||
public void setData(byte[] data) {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* how many of the bytes in the array are 'valid'?
|
||||
* this property does not necessarily have meaning for all byte
|
||||
* arrays.
|
||||
*/
|
||||
public final int getValid() { return _valid; }
|
||||
public final void setValid(int valid) { _valid = valid; }
|
||||
|
||||
public final boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
|
@ -658,12 +658,14 @@ public class DataHelper {
|
||||
}
|
||||
|
||||
public static int read(InputStream in, byte target[]) throws IOException {
|
||||
int cur = 0;
|
||||
while (cur < target.length) {
|
||||
int numRead = in.read(target, cur, target.length - cur);
|
||||
return read(in, target, 0, target.length);
|
||||
}
|
||||
public static int read(InputStream in, byte target[], int offset, int length) throws IOException {
|
||||
int cur = offset;
|
||||
while (cur < length) {
|
||||
int numRead = in.read(target, cur, length - cur);
|
||||
if (numRead == -1) {
|
||||
if (cur == 0) return -1; // throw new EOFException("EOF Encountered during reading");
|
||||
|
||||
if (cur == offset) return -1; // throw new EOFException("EOF Encountered during reading");
|
||||
return cur;
|
||||
}
|
||||
cur += numRead;
|
||||
@ -671,6 +673,7 @@ public class DataHelper {
|
||||
return cur;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a newline delimited line from the stream, returning the line (without
|
||||
* the newline), or null if EOF reached before the newline was found
|
||||
|
Reference in New Issue
Block a user