mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Whitespace-only code formatting changes.
This commit is contained in:
@@ -48,7 +48,7 @@ class ReaderImpl implements Reader {
|
||||
assert !hasLookahead;
|
||||
// Read a lookahead byte
|
||||
int i = in.read();
|
||||
if(i == -1) {
|
||||
if (i == -1) {
|
||||
eof = true;
|
||||
return;
|
||||
}
|
||||
@@ -58,49 +58,49 @@ class ReaderImpl implements Reader {
|
||||
|
||||
private void consumeLookahead() throws IOException {
|
||||
assert hasLookahead;
|
||||
for(Consumer c : consumers) c.write(next);
|
||||
for (Consumer c : consumers) c.write(next);
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
private void readIntoBuffer(byte[] b, int length, boolean consume)
|
||||
throws IOException {
|
||||
int offset = 0;
|
||||
while(offset < length) {
|
||||
while (offset < length) {
|
||||
int read = in.read(b, offset, length - offset);
|
||||
if(read == -1) throw new FormatException();
|
||||
if (read == -1) throw new FormatException();
|
||||
offset += read;
|
||||
}
|
||||
if(consume) for(Consumer c : consumers) c.write(b, 0, length);
|
||||
if (consume) for (Consumer c : consumers) c.write(b, 0, length);
|
||||
}
|
||||
|
||||
private void readIntoBuffer(int length, boolean consume)
|
||||
throws IOException {
|
||||
if(buf.length < length) buf = new byte[length];
|
||||
if (buf.length < length) buf = new byte[length];
|
||||
readIntoBuffer(buf, length, consume);
|
||||
}
|
||||
|
||||
private void skip(int length) throws IOException {
|
||||
while(length > 0) {
|
||||
while (length > 0) {
|
||||
int read = in.read(buf, 0, Math.min(length, buf.length));
|
||||
if(read == -1) throw new FormatException();
|
||||
if (read == -1) throw new FormatException();
|
||||
length -= read;
|
||||
}
|
||||
}
|
||||
|
||||
private void skipObject() throws IOException {
|
||||
if(hasBoolean()) skipBoolean();
|
||||
else if(hasInteger()) skipInteger();
|
||||
else if(hasFloat()) skipFloat();
|
||||
else if(hasString()) skipString();
|
||||
else if(hasRaw()) skipRaw();
|
||||
else if(hasList()) skipList();
|
||||
else if(hasMap()) skipMap();
|
||||
else if(hasNull()) skipNull();
|
||||
if (hasBoolean()) skipBoolean();
|
||||
else if (hasInteger()) skipInteger();
|
||||
else if (hasFloat()) skipFloat();
|
||||
else if (hasString()) skipString();
|
||||
else if (hasRaw()) skipRaw();
|
||||
else if (hasList()) skipList();
|
||||
else if (hasMap()) skipMap();
|
||||
else if (hasNull()) skipNull();
|
||||
else throw new FormatException();
|
||||
}
|
||||
|
||||
public boolean eof() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if (!hasLookahead) readLookahead();
|
||||
return eof;
|
||||
}
|
||||
|
||||
@@ -113,56 +113,56 @@ class ReaderImpl implements Reader {
|
||||
}
|
||||
|
||||
public void removeConsumer(Consumer c) {
|
||||
if(!consumers.remove(c)) throw new IllegalArgumentException();
|
||||
if (!consumers.remove(c)) throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public boolean hasNull() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == NULL;
|
||||
}
|
||||
|
||||
public void readNull() throws IOException {
|
||||
if(!hasNull()) throw new FormatException();
|
||||
if (!hasNull()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
}
|
||||
|
||||
public void skipNull() throws IOException {
|
||||
if(!hasNull()) throw new FormatException();
|
||||
if (!hasNull()) throw new FormatException();
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasBoolean() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == FALSE || next == TRUE;
|
||||
}
|
||||
|
||||
public boolean readBoolean() throws IOException {
|
||||
if(!hasBoolean()) throw new FormatException();
|
||||
if (!hasBoolean()) throw new FormatException();
|
||||
boolean bool = next == TRUE;
|
||||
consumeLookahead();
|
||||
return bool;
|
||||
}
|
||||
|
||||
public void skipBoolean() throws IOException {
|
||||
if(!hasBoolean()) throw new FormatException();
|
||||
if (!hasBoolean()) throw new FormatException();
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasInteger() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == INT_8 || next == INT_16 || next == INT_32 ||
|
||||
next == INT_64;
|
||||
}
|
||||
|
||||
public long readInteger() throws IOException {
|
||||
if(!hasInteger()) throw new FormatException();
|
||||
if (!hasInteger()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
if(next == INT_8) return readInt8(true);
|
||||
if(next == INT_16) return readInt16(true);
|
||||
if(next == INT_32) return readInt32(true);
|
||||
if (next == INT_8) return readInt8(true);
|
||||
if (next == INT_16) return readInt16(true);
|
||||
if (next == INT_32) return readInt32(true);
|
||||
return readInt64(true);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ class ReaderImpl implements Reader {
|
||||
private short readInt16(boolean consume) throws IOException {
|
||||
readIntoBuffer(2, consume);
|
||||
short value = (short) (((buf[0] & 0xFF) << 8) + (buf[1] & 0xFF));
|
||||
if(value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
|
||||
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
|
||||
throw new FormatException();
|
||||
return value;
|
||||
}
|
||||
@@ -182,8 +182,8 @@ class ReaderImpl implements Reader {
|
||||
private int readInt32(boolean consume) throws IOException {
|
||||
readIntoBuffer(4, consume);
|
||||
int value = 0;
|
||||
for(int i = 0; i < 4; i++) value |= (buf[i] & 0xFF) << (24 - i * 8);
|
||||
if(value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
|
||||
for (int i = 0; i < 4; i++) value |= (buf[i] & 0xFF) << (24 - i * 8);
|
||||
if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
|
||||
throw new FormatException();
|
||||
return value;
|
||||
}
|
||||
@@ -191,113 +191,113 @@ class ReaderImpl implements Reader {
|
||||
private long readInt64(boolean consume) throws IOException {
|
||||
readIntoBuffer(8, consume);
|
||||
long value = 0;
|
||||
for(int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
|
||||
if(value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE)
|
||||
for (int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
|
||||
if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE)
|
||||
throw new FormatException();
|
||||
return value;
|
||||
}
|
||||
|
||||
public void skipInteger() throws IOException {
|
||||
if(!hasInteger()) throw new FormatException();
|
||||
if(next == INT_8) skip(1);
|
||||
else if(next == INT_16) skip(2);
|
||||
else if(next == INT_32) skip(4);
|
||||
if (!hasInteger()) throw new FormatException();
|
||||
if (next == INT_8) skip(1);
|
||||
else if (next == INT_16) skip(2);
|
||||
else if (next == INT_32) skip(4);
|
||||
else skip(8);
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasFloat() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == FLOAT_64;
|
||||
}
|
||||
|
||||
public double readFloat() throws IOException {
|
||||
if(!hasFloat()) throw new FormatException();
|
||||
if (!hasFloat()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
readIntoBuffer(8, true);
|
||||
long value = 0;
|
||||
for(int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
|
||||
for (int i = 0; i < 8; i++) value |= (buf[i] & 0xFFL) << (56 - i * 8);
|
||||
return Double.longBitsToDouble(value);
|
||||
}
|
||||
|
||||
public void skipFloat() throws IOException {
|
||||
if(!hasFloat()) throw new FormatException();
|
||||
if (!hasFloat()) throw new FormatException();
|
||||
skip(8);
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasString() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == STRING_8 || next == STRING_16 || next == STRING_32;
|
||||
}
|
||||
|
||||
public String readString(int maxLength) throws IOException {
|
||||
if(!hasString()) throw new FormatException();
|
||||
if (!hasString()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
int length = readStringLength(true);
|
||||
if(length < 0 || length > maxLength) throw new FormatException();
|
||||
if(length == 0) return "";
|
||||
if (length < 0 || length > maxLength) throw new FormatException();
|
||||
if (length == 0) return "";
|
||||
readIntoBuffer(length, true);
|
||||
return new String(buf, 0, length, "UTF-8");
|
||||
}
|
||||
|
||||
private int readStringLength(boolean consume) throws IOException {
|
||||
if(next == STRING_8) return readInt8(consume);
|
||||
if(next == STRING_16) return readInt16(consume);
|
||||
if(next == STRING_32) return readInt32(consume);
|
||||
if (next == STRING_8) return readInt8(consume);
|
||||
if (next == STRING_16) return readInt16(consume);
|
||||
if (next == STRING_32) return readInt32(consume);
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public void skipString() throws IOException {
|
||||
if(!hasString()) throw new FormatException();
|
||||
if (!hasString()) throw new FormatException();
|
||||
int length = readStringLength(false);
|
||||
if(length < 0) throw new FormatException();
|
||||
if (length < 0) throw new FormatException();
|
||||
skip(length);
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasRaw() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == RAW_8 || next == RAW_16 || next == RAW_32;
|
||||
}
|
||||
|
||||
public byte[] readRaw(int maxLength) throws IOException {
|
||||
if(!hasRaw()) throw new FormatException();
|
||||
if (!hasRaw()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
int length = readRawLength(true);
|
||||
if(length < 0 || length > maxLength) throw new FormatException();
|
||||
if(length == 0) return EMPTY_BUFFER;
|
||||
if (length < 0 || length > maxLength) throw new FormatException();
|
||||
if (length == 0) return EMPTY_BUFFER;
|
||||
byte[] b = new byte[length];
|
||||
readIntoBuffer(b, length, true);
|
||||
return b;
|
||||
}
|
||||
|
||||
private int readRawLength(boolean consume) throws IOException {
|
||||
if(next == RAW_8) return readInt8(consume);
|
||||
if(next == RAW_16) return readInt16(consume);
|
||||
if(next == RAW_32) return readInt32(consume);
|
||||
if (next == RAW_8) return readInt8(consume);
|
||||
if (next == RAW_16) return readInt16(consume);
|
||||
if (next == RAW_32) return readInt32(consume);
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public void skipRaw() throws IOException {
|
||||
if(!hasRaw()) throw new FormatException();
|
||||
if (!hasRaw()) throw new FormatException();
|
||||
int length = readRawLength(false);
|
||||
if(length < 0) throw new FormatException();
|
||||
if (length < 0) throw new FormatException();
|
||||
skip(length);
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasList() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == LIST;
|
||||
}
|
||||
|
||||
public void readListStart() throws IOException {
|
||||
if(!hasList()) throw new FormatException();
|
||||
if (!hasList()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
}
|
||||
|
||||
@@ -306,8 +306,8 @@ class ReaderImpl implements Reader {
|
||||
}
|
||||
|
||||
private boolean hasEnd() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == END;
|
||||
}
|
||||
|
||||
@@ -316,25 +316,25 @@ class ReaderImpl implements Reader {
|
||||
}
|
||||
|
||||
private void readEnd() throws IOException {
|
||||
if(!hasEnd()) throw new FormatException();
|
||||
if (!hasEnd()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
}
|
||||
|
||||
public void skipList() throws IOException {
|
||||
if(!hasList()) throw new FormatException();
|
||||
if (!hasList()) throw new FormatException();
|
||||
hasLookahead = false;
|
||||
while(!hasListEnd()) skipObject();
|
||||
while (!hasListEnd()) skipObject();
|
||||
hasLookahead = false;
|
||||
}
|
||||
|
||||
public boolean hasMap() throws IOException {
|
||||
if(!hasLookahead) readLookahead();
|
||||
if(eof) return false;
|
||||
if (!hasLookahead) readLookahead();
|
||||
if (eof) return false;
|
||||
return next == MAP;
|
||||
}
|
||||
|
||||
public void readMapStart() throws IOException {
|
||||
if(!hasMap()) throw new FormatException();
|
||||
if (!hasMap()) throw new FormatException();
|
||||
consumeLookahead();
|
||||
}
|
||||
|
||||
@@ -347,9 +347,9 @@ class ReaderImpl implements Reader {
|
||||
}
|
||||
|
||||
public void skipMap() throws IOException {
|
||||
if(!hasMap()) throw new FormatException();
|
||||
if (!hasMap()) throw new FormatException();
|
||||
hasLookahead = false;
|
||||
while(!hasMapEnd()) {
|
||||
while (!hasMapEnd()) {
|
||||
skipObject();
|
||||
skipObject();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class WriterImpl implements Writer {
|
||||
}
|
||||
|
||||
public void removeConsumer(Consumer c) {
|
||||
if(!consumers.remove(c)) throw new IllegalArgumentException();
|
||||
if (!consumers.remove(c)) throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public void writeNull() throws IOException {
|
||||
@@ -61,18 +61,18 @@ class WriterImpl implements Writer {
|
||||
}
|
||||
|
||||
public void writeBoolean(boolean b) throws IOException {
|
||||
if(b) write(TRUE);
|
||||
if (b) write(TRUE);
|
||||
else write(FALSE);
|
||||
}
|
||||
|
||||
public void writeInteger(long i) throws IOException {
|
||||
if(i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
|
||||
if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
|
||||
write(INT_8);
|
||||
write((byte) i);
|
||||
} else if(i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
|
||||
} else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
|
||||
write(INT_16);
|
||||
writeInt16((short) i);
|
||||
} else if(i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE) {
|
||||
} else if (i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE) {
|
||||
write(INT_32);
|
||||
writeInt32((int) i);
|
||||
} else {
|
||||
@@ -111,10 +111,10 @@ class WriterImpl implements Writer {
|
||||
|
||||
public void writeString(String s) throws IOException {
|
||||
byte[] b = s.getBytes("UTF-8");
|
||||
if(b.length <= Byte.MAX_VALUE) {
|
||||
if (b.length <= Byte.MAX_VALUE) {
|
||||
write(STRING_8);
|
||||
write((byte) b.length);
|
||||
} else if(b.length <= Short.MAX_VALUE) {
|
||||
} else if (b.length <= Short.MAX_VALUE) {
|
||||
write(STRING_16);
|
||||
writeInt16((short) b.length);
|
||||
} else {
|
||||
@@ -125,10 +125,10 @@ class WriterImpl implements Writer {
|
||||
}
|
||||
|
||||
public void writeRaw(byte[] b) throws IOException {
|
||||
if(b.length <= Byte.MAX_VALUE) {
|
||||
if (b.length <= Byte.MAX_VALUE) {
|
||||
write(RAW_8);
|
||||
write((byte) b.length);
|
||||
} else if(b.length <= Short.MAX_VALUE) {
|
||||
} else if (b.length <= Short.MAX_VALUE) {
|
||||
write(RAW_16);
|
||||
writeInt16((short) b.length);
|
||||
} else {
|
||||
@@ -140,24 +140,24 @@ class WriterImpl implements Writer {
|
||||
|
||||
public void writeList(Collection<?> c) throws IOException {
|
||||
write(LIST);
|
||||
for(Object o : c) writeObject(o);
|
||||
for (Object o : c) writeObject(o);
|
||||
write(END);
|
||||
}
|
||||
|
||||
private void writeObject(Object o) throws IOException {
|
||||
if(o instanceof Boolean) writeBoolean((Boolean) o);
|
||||
else if(o instanceof Byte) writeInteger((Byte) o);
|
||||
else if(o instanceof Short) writeInteger((Short) o);
|
||||
else if(o instanceof Integer) writeInteger((Integer) o);
|
||||
else if(o instanceof Long) writeInteger((Long) o);
|
||||
else if(o instanceof Float) writeFloat((Float) o);
|
||||
else if(o instanceof Double) writeFloat((Double) o);
|
||||
else if(o instanceof String) writeString((String) o);
|
||||
else if(o instanceof byte[]) writeRaw((byte[]) o);
|
||||
else if(o instanceof Bytes) writeRaw(((Bytes) o).getBytes());
|
||||
else if(o instanceof List<?>) writeList((List<?>) o);
|
||||
else if(o instanceof Map<?, ?>) writeMap((Map<?, ?>) o);
|
||||
else if(o == null) writeNull();
|
||||
if (o instanceof Boolean) writeBoolean((Boolean) o);
|
||||
else if (o instanceof Byte) writeInteger((Byte) o);
|
||||
else if (o instanceof Short) writeInteger((Short) o);
|
||||
else if (o instanceof Integer) writeInteger((Integer) o);
|
||||
else if (o instanceof Long) writeInteger((Long) o);
|
||||
else if (o instanceof Float) writeFloat((Float) o);
|
||||
else if (o instanceof Double) writeFloat((Double) o);
|
||||
else if (o instanceof String) writeString((String) o);
|
||||
else if (o instanceof byte[]) writeRaw((byte[]) o);
|
||||
else if (o instanceof Bytes) writeRaw(((Bytes) o).getBytes());
|
||||
else if (o instanceof List<?>) writeList((List<?>) o);
|
||||
else if (o instanceof Map<?, ?>) writeMap((Map<?, ?>) o);
|
||||
else if (o == null) writeNull();
|
||||
else throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ class WriterImpl implements Writer {
|
||||
|
||||
public void writeMap(Map<?, ?> m) throws IOException {
|
||||
write(MAP);
|
||||
for(Entry<?, ?> e : m.entrySet()) {
|
||||
for (Entry<?, ?> e : m.entrySet()) {
|
||||
writeObject(e.getKey());
|
||||
writeObject(e.getValue());
|
||||
}
|
||||
@@ -188,11 +188,11 @@ class WriterImpl implements Writer {
|
||||
|
||||
private void write(byte b) throws IOException {
|
||||
out.write(b);
|
||||
for(Consumer c : consumers) c.write(b);
|
||||
for (Consumer c : consumers) c.write(b);
|
||||
}
|
||||
|
||||
private void write(byte[] b) throws IOException {
|
||||
out.write(b);
|
||||
for(Consumer c : consumers) c.write(b, 0, b.length);
|
||||
for (Consumer c : consumers) c.write(b, 0, b.length);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user