diff --git a/briar-api/src/org/briarproject/api/data/BdfWriter.java b/briar-api/src/org/briarproject/api/data/BdfWriter.java index b0f34323112ce70babaf290a906da44ab3e14b7a..df0eb676df5c2d0ffaefed8277562312cae4225d 100644 --- a/briar-api/src/org/briarproject/api/data/BdfWriter.java +++ b/briar-api/src/org/briarproject/api/data/BdfWriter.java @@ -11,8 +11,8 @@ public interface BdfWriter { void writeNull() throws IOException; void writeBoolean(boolean b) throws IOException; - void writeInteger(long l) throws IOException; - void writeFloat(double d) throws IOException; + void writeLong(long l) throws IOException; + void writeDouble(double d) throws IOException; void writeString(String s) throws IOException; void writeRaw(byte[] b) throws IOException; diff --git a/briar-core/src/org/briarproject/data/BdfWriterImpl.java b/briar-core/src/org/briarproject/data/BdfWriterImpl.java index 07137184d51c0667436b31aeb87b28c234e71313..2b497dd02f21c802a9498167631acd4769dee65b 100644 --- a/briar-core/src/org/briarproject/data/BdfWriterImpl.java +++ b/briar-core/src/org/briarproject/data/BdfWriterImpl.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import static org.briarproject.api.data.BdfDictionary.NULL_VALUE; import static org.briarproject.data.Types.DICTIONARY; import static org.briarproject.data.Types.END; import static org.briarproject.data.Types.FALSE; @@ -55,7 +56,7 @@ class BdfWriterImpl implements BdfWriter { else out.write(FALSE); } - public void writeInteger(long i) throws IOException { + public void writeLong(long i) throws IOException { if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) { out.write(INT_8); out.write((byte) i); @@ -94,7 +95,7 @@ class BdfWriterImpl implements BdfWriter { out.write((byte) ((i << 56) >> 56)); } - public void writeFloat(double d) throws IOException { + public void writeDouble(double d) throws IOException { out.write(FLOAT_64); writeInt64(Double.doubleToRawLongBits(d)); } @@ -135,14 +136,14 @@ class BdfWriterImpl implements BdfWriter { } private void writeObject(Object o) throws IOException { - if (o == null) writeNull(); + if (o == null || o == NULL_VALUE) writeNull(); else 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 Byte) writeLong((Byte) o); + else if (o instanceof Short) writeLong((Short) o); + else if (o instanceof Integer) writeLong((Integer) o); + else if (o instanceof Long) writeLong((Long) o); + else if (o instanceof Float) writeDouble((Float) o); + else if (o instanceof Double) writeDouble((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()); diff --git a/briar-core/src/org/briarproject/forum/ForumPostFactoryImpl.java b/briar-core/src/org/briarproject/forum/ForumPostFactoryImpl.java index 515310aa8fed400569f11b816e972101d5a89a76..c598dc1c3162d45483f79fb76aa66bcd5abcfa57 100644 --- a/briar-core/src/org/briarproject/forum/ForumPostFactoryImpl.java +++ b/briar-core/src/org/briarproject/forum/ForumPostFactoryImpl.java @@ -77,7 +77,7 @@ class ForumPostFactoryImpl implements ForumPostFactory { BdfWriter w = bdfWriterFactory.createWriter(out); w.writeListStart(); w.writeRaw(groupId.getBytes()); - w.writeInteger(timestamp); + w.writeLong(timestamp); if (parent == null) w.writeNull(); else w.writeRaw(parent.getBytes()); writeAuthor(w, author); diff --git a/briar-core/src/org/briarproject/forum/ForumPostValidator.java b/briar-core/src/org/briarproject/forum/ForumPostValidator.java index a21f546252e5c3151e6bada39fe02cf2506ccf9f..3fbcf2f08fcbc0820f1493b18ad5210ecf522fbd 100644 --- a/briar-core/src/org/briarproject/forum/ForumPostValidator.java +++ b/briar-core/src/org/briarproject/forum/ForumPostValidator.java @@ -117,7 +117,7 @@ class ForumPostValidator implements MessageValidator { BdfWriter w = bdfWriterFactory.createWriter(out); w.writeListStart(); w.writeRaw(m.getGroupId().getBytes()); - w.writeInteger(m.getTimestamp()); + w.writeLong(m.getTimestamp()); if (parent == null) w.writeNull(); else w.writeRaw(parent.getBytes()); writeAuthor(w, author); diff --git a/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java b/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java index f371bddc2c5accda1fc46d88bbb8a082abb1bba6..872bd929907c6f062884ec91c32cf3aa119b2f4b 100644 --- a/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java +++ b/briar-core/src/org/briarproject/forum/ForumSharingManagerImpl.java @@ -387,7 +387,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook, BdfWriter w = bdfWriterFactory.createWriter(out); try { w.writeListStart(); - w.writeInteger(version); + w.writeLong(version); w.writeListStart(); for (Forum f : forums) { w.writeListStart(); diff --git a/briar-core/src/org/briarproject/invitation/Connector.java b/briar-core/src/org/briarproject/invitation/Connector.java index a632f9359a482c5fd0f95dc74e4633bdb395c396..6310c4f170ad3031faeecc00c80697f2b95932dc 100644 --- a/briar-core/src/org/briarproject/invitation/Connector.java +++ b/briar-core/src/org/briarproject/invitation/Connector.java @@ -196,7 +196,7 @@ abstract class Connector extends Thread { protected void sendTimestamp(BdfWriter w, long timestamp) throws IOException { - w.writeInteger(timestamp); + w.writeLong(timestamp); w.flush(); if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent timestamp"); } diff --git a/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java b/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java index 70aac05ff6ac3b9fc2caaeb523e3b3801194b56e..60dbc96d5a7ab8ac65053a5cf316a6a655f84595 100644 --- a/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java +++ b/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java @@ -288,7 +288,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, w.writeListStart(); w.writeRaw(dev.getBytes()); w.writeString(t.getString()); - w.writeInteger(version); + w.writeLong(version); w.writeDictionary(p); w.writeListEnd(); } catch (IOException e) { diff --git a/briar-tests/src/org/briarproject/data/BdfReaderImplTest.java b/briar-tests/src/org/briarproject/data/BdfReaderImplTest.java index 6981b03a06f35ba9ede78074dd24cbadcf5505de..8bf3830ab13ebdcbf3ce510a1560b64177c7847e 100644 --- a/briar-tests/src/org/briarproject/data/BdfReaderImplTest.java +++ b/briar-tests/src/org/briarproject/data/BdfReaderImplTest.java @@ -57,7 +57,7 @@ public class BdfReaderImplTest extends BriarTestCase { } @Test - public void testReadInt8() throws Exception { + public void testReadLong8() throws Exception { setContents("21" + "00" + "21" + "FF" + "21" + "7F" + "21" + "80"); assertEquals(0, r.readLong()); @@ -68,14 +68,14 @@ public class BdfReaderImplTest extends BriarTestCase { } @Test - public void testSkipInt8() throws Exception { + public void testSkipLong8() throws Exception { setContents("21" + "00"); r.skipLong(); assertTrue(r.eof()); } @Test - public void testReadInt16() throws Exception { + public void testReadLong16() throws Exception { setContents("22" + "0080" + "22" + "FF7F" + "22" + "7FFF" + "22" + "8000"); assertEquals(Byte.MAX_VALUE + 1, r.readLong()); @@ -86,14 +86,14 @@ public class BdfReaderImplTest extends BriarTestCase { } @Test - public void testSkipInt16() throws Exception { + public void testSkipLong16() throws Exception { setContents("22" + "0080"); r.skipLong(); assertTrue(r.eof()); } @Test - public void testReadInt32() throws Exception { + public void testReadLong32() throws Exception { setContents("24" + "00008000" + "24" + "FFFF7FFF" + "24" + "7FFFFFFF" + "24" + "80000000"); assertEquals(Short.MAX_VALUE + 1, r.readLong()); @@ -104,14 +104,14 @@ public class BdfReaderImplTest extends BriarTestCase { } @Test - public void testSkipInt32() throws Exception { + public void testSkipLong32() throws Exception { setContents("24" + "00008000"); r.skipLong(); assertTrue(r.eof()); } @Test - public void testReadInt64() throws Exception { + public void testReadLong64() throws Exception { setContents("28" + "0000000080000000" + "28" + "FFFFFFFF7FFFFFFF" + "28" + "7FFFFFFFFFFFFFFF" + "28" + "8000000000000000"); assertEquals(Integer.MAX_VALUE + 1L, r.readLong()); @@ -122,14 +122,14 @@ public class BdfReaderImplTest extends BriarTestCase { } @Test - public void testSkipInt64() throws Exception { + public void testSkipLong() throws Exception { setContents("28" + "0000000080000000"); r.skipLong(); assertTrue(r.eof()); } @Test - public void testReadFloat() throws Exception { + public void testReadDouble() throws Exception { // http://babbage.cs.qc.edu/IEEE-754/Decimal.html // http://steve.hollasch.net/cgindex/coding/ieeefloat.html setContents("38" + "0000000000000000" + "38" + "3FF0000000000000" diff --git a/briar-tests/src/org/briarproject/data/BdfWriterImplTest.java b/briar-tests/src/org/briarproject/data/BdfWriterImplTest.java index 8da0f0e2c6e8205570f4e3993a28c049bafa545c..8ddd0c2097139e63d66c4765c8d52a02a3eb928a 100644 --- a/briar-tests/src/org/briarproject/data/BdfWriterImplTest.java +++ b/briar-tests/src/org/briarproject/data/BdfWriterImplTest.java @@ -13,6 +13,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import static org.briarproject.api.data.BdfDictionary.NULL_VALUE; import static org.junit.Assert.assertArrayEquals; public class BdfWriterImplTest extends BriarTestCase { @@ -41,17 +42,17 @@ public class BdfWriterImplTest extends BriarTestCase { } @Test - public void testWriteInteger() throws IOException { - w.writeInteger(0); - w.writeInteger(-1); - w.writeInteger(Byte.MAX_VALUE); - w.writeInteger(Byte.MIN_VALUE); - w.writeInteger(Short.MAX_VALUE); - w.writeInteger(Short.MIN_VALUE); - w.writeInteger(Integer.MAX_VALUE); - w.writeInteger(Integer.MIN_VALUE); - w.writeInteger(Long.MAX_VALUE); - w.writeInteger(Long.MIN_VALUE); + public void testWriteLong() throws IOException { + w.writeLong(0); + w.writeLong(-1); + w.writeLong(Byte.MAX_VALUE); + w.writeLong(Byte.MIN_VALUE); + w.writeLong(Short.MAX_VALUE); + w.writeLong(Short.MIN_VALUE); + w.writeLong(Integer.MAX_VALUE); + w.writeLong(Integer.MIN_VALUE); + w.writeLong(Long.MAX_VALUE); + w.writeLong(Long.MIN_VALUE); // INTEGER_8 tag, 0, INTEGER_8 tag, -1, etc checkContents("21" + "00" + "21" + "FF" + "21" + "7F" + "21" + "80" + @@ -61,17 +62,17 @@ public class BdfWriterImplTest extends BriarTestCase { } @Test - public void testWriteFloat() throws IOException { + public void testWriteDouble() throws IOException { // http://babbage.cs.qc.edu/IEEE-754/Decimal.html // 1 bit for sign, 11 for exponent, 52 for significand - w.writeFloat(0.0); // 0 0 0 -> 0x0000000000000000 - w.writeFloat(1.0); // 0 1023 1 -> 0x3FF0000000000000 - w.writeFloat(2.0); // 0 1024 1 -> 0x4000000000000000 - w.writeFloat(-1.0); // 1 1023 1 -> 0xBFF0000000000000 - w.writeFloat(-0.0); // 1 0 0 -> 0x8000000000000000 - w.writeFloat(Double.NEGATIVE_INFINITY); // 1 2047 0 -> 0xFFF00000... - w.writeFloat(Double.POSITIVE_INFINITY); // 0 2047 0 -> 0x7FF00000... - w.writeFloat(Double.NaN); // 0 2047 1 -> 0x7FF8000000000000 + w.writeDouble(0.0); // 0 0 0 -> 0x0000000000000000 + w.writeDouble(1.0); // 0 1023 1 -> 0x3FF0000000000000 + w.writeDouble(2.0); // 0 1024 1 -> 0x4000000000000000 + w.writeDouble(-1.0); // 1 1023 1 -> 0xBFF0000000000000 + w.writeDouble(-0.0); // 1 0 0 -> 0x8000000000000000 + w.writeDouble(Double.NEGATIVE_INFINITY); // 1 2047 0 -> 0xFFF00000... + w.writeDouble(Double.POSITIVE_INFINITY); // 0 2047 0 -> 0x7FF00000... + w.writeDouble(Double.NaN); // 0 2047 1 -> 0x7FF8000000000000 checkContents("38" + "0000000000000000" + "38" + "3FF0000000000000" + "38" + "4000000000000000" + "38" + "BFF0000000000000" + "38" + "8000000000000000" + "38" + "FFF0000000000000" @@ -122,7 +123,7 @@ public class BdfWriterImplTest extends BriarTestCase { } @Test - public void testWriteBytes8() throws IOException { + public void testWriteRaw8() throws IOException { byte[] longest = new byte[Byte.MAX_VALUE]; String longHex = StringUtils.toHexString(longest); w.writeRaw(new byte[] {1, 2, 3}); @@ -132,7 +133,7 @@ public class BdfWriterImplTest extends BriarTestCase { } @Test - public void testWriteBytes16() throws IOException { + public void testWriteRaw16() throws IOException { byte[] shortest = new byte[Byte.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); byte[] longest = new byte[Short.MAX_VALUE]; @@ -144,7 +145,7 @@ public class BdfWriterImplTest extends BriarTestCase { } @Test - public void testWriteBytes32() throws IOException { + public void testWriteRaw32() throws IOException { byte[] shortest = new byte[Short.MAX_VALUE + 1]; String shortHex = StringUtils.toHexString(shortest); w.writeRaw(shortest); @@ -166,10 +167,11 @@ public class BdfWriterImplTest extends BriarTestCase { List<Object> l = new ArrayList<Object>(); l.add(1); l.add(null); + l.add(NULL_VALUE); l.add(2); w.writeList(l); - // LIST tag, 1 as integer, NULL tag, 2 as integer, END tag - checkContents("60" + "21" + "01" + "00" + "21" + "02" + "80"); + // LIST tag, 1 as integer, NULL tag, NULL tag, 2 as integer, END tag + checkContents("60" + "21" + "01" + "00" + "00" + "21" + "02" + "80"); } @Test @@ -188,9 +190,9 @@ public class BdfWriterImplTest extends BriarTestCase { @Test public void testWriteDelimitedList() throws IOException { w.writeListStart(); - w.writeInteger(1); + w.writeLong(1); w.writeString("foo"); - w.writeInteger(128); + w.writeLong(128); w.writeListEnd(); // LIST tag, 1 as integer, "foo" as string, 128 as integer, END tag checkContents("60" + "21" + "01" + @@ -202,7 +204,7 @@ public class BdfWriterImplTest extends BriarTestCase { public void testWriteDelimitedDictionary() throws IOException { w.writeDictionaryStart(); w.writeString("foo"); - w.writeInteger(123); + w.writeLong(123); w.writeString("bar"); w.writeNull(); w.writeDictionaryEnd();