diff --git a/api/net/sf/briar/api/protocol/AuthorId.java b/api/net/sf/briar/api/protocol/AuthorId.java index 4f50e2ae22aeab557f30793135726d65e3464ae3..e628511b62d13020dd4ad518dd925a5acae8983f 100644 --- a/api/net/sf/briar/api/protocol/AuthorId.java +++ b/api/net/sf/briar/api/protocol/AuthorId.java @@ -14,7 +14,7 @@ public class AuthorId extends UniqueId { public void writeTo(Writer w) throws IOException { w.writeUserDefinedTag(Tags.AUTHOR_ID); - w.writeRaw(id); + w.writeBytes(id); } @Override diff --git a/api/net/sf/briar/api/protocol/BatchId.java b/api/net/sf/briar/api/protocol/BatchId.java index a1640913d6c21e7a052e5eea8d784c6732781dbe..95949e0872ad2170e33663278ac382f3ce01bc77 100644 --- a/api/net/sf/briar/api/protocol/BatchId.java +++ b/api/net/sf/briar/api/protocol/BatchId.java @@ -17,7 +17,7 @@ public class BatchId extends UniqueId { public void writeTo(Writer w) throws IOException { w.writeUserDefinedTag(Tags.BATCH_ID); - w.writeRaw(id); + w.writeBytes(id); } @Override diff --git a/api/net/sf/briar/api/protocol/GroupId.java b/api/net/sf/briar/api/protocol/GroupId.java index 0cf267d16cfa6913431ecd1cff06e8d83e903a0d..6621777de8ecb56124e3aa9075ff4e34d9434342 100644 --- a/api/net/sf/briar/api/protocol/GroupId.java +++ b/api/net/sf/briar/api/protocol/GroupId.java @@ -17,7 +17,7 @@ public class GroupId extends UniqueId { public void writeTo(Writer w) throws IOException { w.writeUserDefinedTag(Tags.GROUP_ID); - w.writeRaw(id); + w.writeBytes(id); } @Override diff --git a/api/net/sf/briar/api/protocol/Message.java b/api/net/sf/briar/api/protocol/Message.java index 3b1739fdfdef30f3169bb52711962c97a9d6ae6e..89e0212451c7df4918a8b2732f5b6bc91a8616a1 100644 --- a/api/net/sf/briar/api/protocol/Message.java +++ b/api/net/sf/briar/api/protocol/Message.java @@ -1,10 +1,8 @@ package net.sf.briar.api.protocol; -import net.sf.briar.api.serial.Raw; +public interface Message { -public interface Message extends Raw { - - static final int MAX_SIZE = 1024 * 1023; // Not a typo + static final int MAX_SIZE = (1024 * 1024) - 200; /** Returns the message's unique identifier. */ MessageId getId(); @@ -26,4 +24,7 @@ public interface Message extends Raw { /** Returns the size of the message in bytes. */ int getSize(); + + /** Returns the serialised representation of the message. */ + byte[] getBytes(); } \ No newline at end of file diff --git a/api/net/sf/briar/api/protocol/MessageId.java b/api/net/sf/briar/api/protocol/MessageId.java index 41cfecc3dbdb793d1dbd9d64be890cbc1be9b4f6..e3109ef087db266d985eb63d7af42b3918d14dc0 100644 --- a/api/net/sf/briar/api/protocol/MessageId.java +++ b/api/net/sf/briar/api/protocol/MessageId.java @@ -20,7 +20,7 @@ public class MessageId extends UniqueId { public void writeTo(Writer w) throws IOException { w.writeUserDefinedTag(Tags.MESSAGE_ID); - w.writeRaw(id); + w.writeBytes(id); } @Override diff --git a/api/net/sf/briar/api/protocol/UniqueId.java b/api/net/sf/briar/api/protocol/UniqueId.java index 4a18fc3d67c3ee107f4582df9ddfd28bfcb75c33..0cbccb5ff52f5ed9ef0438c232ed581e1a54b305 100644 --- a/api/net/sf/briar/api/protocol/UniqueId.java +++ b/api/net/sf/briar/api/protocol/UniqueId.java @@ -2,10 +2,9 @@ package net.sf.briar.api.protocol; import java.util.Arrays; -import net.sf.briar.api.serial.Raw; import net.sf.briar.api.serial.Writable; -public abstract class UniqueId implements Raw, Writable { +public abstract class UniqueId implements Writable { public static final int LENGTH = 32; public static final int SERIALISED_LENGTH = LENGTH + 3; diff --git a/api/net/sf/briar/api/serial/RawByteArray.java b/api/net/sf/briar/api/serial/Bytes.java similarity index 59% rename from api/net/sf/briar/api/serial/RawByteArray.java rename to api/net/sf/briar/api/serial/Bytes.java index 50ed9e02b8d405f211212c66e25a217b81f6da4f..e6ad5ee52e46f3ba0afefeb9746f7cb1184952bb 100644 --- a/api/net/sf/briar/api/serial/RawByteArray.java +++ b/api/net/sf/briar/api/serial/Bytes.java @@ -2,13 +2,12 @@ package net.sf.briar.api.serial; import java.util.Arrays; - -/** A byte array wrapped in the Raw interface. */ -public class RawByteArray implements Raw { +/** A wrapper around a byte array, to allow it to be stored in maps etc. */ +public class Bytes { private final byte[] bytes; - public RawByteArray(byte[] bytes) { + public Bytes(byte[] bytes) { this.bytes = bytes; } @@ -23,7 +22,8 @@ public class RawByteArray implements Raw { @Override public boolean equals(Object o) { - if(o instanceof Raw) return Arrays.equals(bytes, ((Raw) o).getBytes()); + if(o instanceof Bytes) + return Arrays.equals(bytes, ((Bytes) o).bytes); return false; } } diff --git a/api/net/sf/briar/api/serial/Raw.java b/api/net/sf/briar/api/serial/Raw.java deleted file mode 100644 index 5a40b2f8c5549e00436028a0996619652159fc8d..0000000000000000000000000000000000000000 --- a/api/net/sf/briar/api/serial/Raw.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.sf.briar.api.serial; - -/** - * Generic interface for any object that knows how to serialise itself as a - * raw byte array. - */ -public interface Raw { - - byte[] getBytes(); -} diff --git a/api/net/sf/briar/api/serial/Reader.java b/api/net/sf/briar/api/serial/Reader.java index 9b80ebc4361964a502f7a07c9314f8c0228aded2..c0a4f8f69b55af3628b9d62dd8ec720df4b8eb41 100644 --- a/api/net/sf/briar/api/serial/Reader.java +++ b/api/net/sf/briar/api/serial/Reader.java @@ -38,8 +38,8 @@ public interface Reader { boolean hasString() throws IOException; String readString() throws IOException; - boolean hasRaw() throws IOException; - byte[] readRaw() throws IOException; + boolean hasBytes() throws IOException; + byte[] readBytes() throws IOException; boolean hasList() throws IOException; List<Object> readList() throws IOException; diff --git a/api/net/sf/briar/api/serial/Tag.java b/api/net/sf/briar/api/serial/Tag.java index e924d6a50683dc13cd8cd7f38d1db27ce54fed2d..bc52820dfe152f21f2b7a86a54619dfd032c2f31 100644 --- a/api/net/sf/briar/api/serial/Tag.java +++ b/api/net/sf/briar/api/serial/Tag.java @@ -11,7 +11,7 @@ public interface Tag { static final byte FLOAT32 = -7; // 1111 1001 static final byte FLOAT64 = -8; // 1111 1000 static final byte STRING = -9; // 1111 0111 - static final byte RAW = -10; // 1111 0110 + static final byte BYTES = -10; // 1111 0110 static final byte LIST = -11; // 1111 0101 static final byte MAP = -12; // 1111 0100 static final byte LIST_START = -13; // 1111 0011 @@ -22,7 +22,7 @@ public interface Tag { static final int SHORT_MASK = 0xF0; // Match first four bits static final int SHORT_STRING = 0x80; // 1000 xxxx - static final int SHORT_RAW = 0x90; // 1001 xxxx + static final int SHORT_BYTES = 0x90; // 1001 xxxx static final int SHORT_LIST = 0xA0; // 1010 xxxx static final int SHORT_MAP = 0xB0; // 1011 xxxx diff --git a/api/net/sf/briar/api/serial/Writer.java b/api/net/sf/briar/api/serial/Writer.java index 6b53486e27003ffa595a707dc26ddd3884ef4dc9..8f2d187d2ed37e0ee28668bf8f850b7f5856e7d2 100644 --- a/api/net/sf/briar/api/serial/Writer.java +++ b/api/net/sf/briar/api/serial/Writer.java @@ -21,8 +21,7 @@ public interface Writer { void writeFloat64(double d) throws IOException; void writeString(String s) throws IOException; - void writeRaw(byte[] b) throws IOException; - void writeRaw(Raw r) throws IOException; + void writeBytes(byte[] b) throws IOException; void writeList(Collection<?> c) throws IOException; void writeListStart() throws IOException; diff --git a/components/net/sf/briar/protocol/BatchIdReader.java b/components/net/sf/briar/protocol/BatchIdReader.java index 57348423348fbffdea232be7d475f16a20c3258c..3daeda2862c58fc5ed951c85907e3ed22cd2e351 100644 --- a/components/net/sf/briar/protocol/BatchIdReader.java +++ b/components/net/sf/briar/protocol/BatchIdReader.java @@ -13,7 +13,7 @@ class BatchIdReader implements ObjectReader<BatchId> { public BatchId readObject(Reader r) throws IOException { r.readUserDefinedTag(Tags.BATCH_ID); - byte[] b = r.readRaw(); + byte[] b = r.readBytes(); if(b.length != UniqueId.LENGTH) throw new FormatException(); return new BatchId(b); } diff --git a/components/net/sf/briar/protocol/GroupIdReader.java b/components/net/sf/briar/protocol/GroupIdReader.java index 13d37deb524781afc4551fedd556457cdc56c415..76c13e6166b927d814c185cd5c8fe5fa249ddab0 100644 --- a/components/net/sf/briar/protocol/GroupIdReader.java +++ b/components/net/sf/briar/protocol/GroupIdReader.java @@ -13,7 +13,7 @@ class GroupIdReader implements ObjectReader<GroupId> { public GroupId readObject(Reader r) throws IOException { r.readUserDefinedTag(Tags.GROUP_ID); - byte[] b = r.readRaw(); + byte[] b = r.readBytes(); if(b.length != UniqueId.LENGTH) throw new FormatException(); return new GroupId(b); } diff --git a/components/net/sf/briar/protocol/GroupImpl.java b/components/net/sf/briar/protocol/GroupImpl.java index b70a54403557deb018944081720af21e4711b3a4..79afd7993251afeebbe1badd2a24689529639fc5 100644 --- a/components/net/sf/briar/protocol/GroupImpl.java +++ b/components/net/sf/briar/protocol/GroupImpl.java @@ -53,8 +53,8 @@ class GroupImpl implements Group { w.writeUserDefinedTag(Tags.GROUP); w.writeString(name); w.writeBoolean(isRestricted()); - if(salt == null) w.writeRaw(publicKey.getEncoded()); - else w.writeRaw(salt); + if(salt == null) w.writeBytes(publicKey.getEncoded()); + else w.writeBytes(salt); } @Override diff --git a/components/net/sf/briar/protocol/GroupReader.java b/components/net/sf/briar/protocol/GroupReader.java index af94f29440f156ed1d3a949df6416c3a876b320b..8bf54f8972c9e4c28a93a90cf03c5b9a08ede9ae 100644 --- a/components/net/sf/briar/protocol/GroupReader.java +++ b/components/net/sf/briar/protocol/GroupReader.java @@ -29,7 +29,7 @@ class GroupReader implements ObjectReader<Group> { r.readUserDefinedTag(Tags.GROUP); String name = r.readString(); boolean restricted = r.readBoolean(); - byte[] saltOrKey = r.readRaw(); + byte[] saltOrKey = r.readBytes(); r.removeConsumer(digesting); // Build and return the group GroupId id = new GroupId(messageDigest.digest()); diff --git a/components/net/sf/briar/protocol/MessageEncoderImpl.java b/components/net/sf/briar/protocol/MessageEncoderImpl.java index e945166ce0a8748979243af6ca49e5b1629fcc33..102f552e960dd6b44fa4c361dc53af6ace0d38b4 100644 --- a/components/net/sf/briar/protocol/MessageEncoderImpl.java +++ b/components/net/sf/briar/protocol/MessageEncoderImpl.java @@ -44,8 +44,8 @@ class MessageEncoderImpl implements MessageEncoder { group.writeTo(w); w.writeInt64(timestamp); w.writeString(nick); - w.writeRaw(keyPair.getPublic().getEncoded()); - w.writeRaw(body); + w.writeBytes(keyPair.getPublic().getEncoded()); + w.writeBytes(body); // Sign the message byte[] signable = out.toByteArray(); signature.initSign(keyPair.getPrivate()); @@ -53,7 +53,7 @@ class MessageEncoderImpl implements MessageEncoder { byte[] sig = signature.sign(); signable = null; // Write the signature - w.writeRaw(sig); + w.writeBytes(sig); byte[] raw = out.toByteArray(); // The message ID is the hash of the entire message messageDigest.reset(); @@ -63,7 +63,7 @@ class MessageEncoderImpl implements MessageEncoder { out.reset(); w = writerFactory.createWriter(out); w.writeString(nick); - w.writeRaw(keyPair.getPublic().getEncoded()); + w.writeBytes(keyPair.getPublic().getEncoded()); messageDigest.reset(); messageDigest.update(out.toByteArray()); AuthorId authorId = new AuthorId(messageDigest.digest()); diff --git a/components/net/sf/briar/protocol/MessageReader.java b/components/net/sf/briar/protocol/MessageReader.java index 3258ae9568a82dd921c08d52fda501b920c565e6..0bb9f7f4ab017bfbc35654bd7345051a23ca84bf 100644 --- a/components/net/sf/briar/protocol/MessageReader.java +++ b/components/net/sf/briar/protocol/MessageReader.java @@ -41,12 +41,12 @@ class MessageReader implements ObjectReader<Message> { r.readUserDefinedTag(Tags.MESSAGE); // Read the parent's message ID r.readUserDefinedTag(Tags.MESSAGE_ID); - byte[] b = r.readRaw(); + byte[] b = r.readBytes(); if(b.length != UniqueId.LENGTH) throw new FormatException(); MessageId parent = new MessageId(b); // Read the group ID r.readUserDefinedTag(Tags.GROUP_ID); - b = r.readRaw(); + b = r.readBytes(); if(b.length != UniqueId.LENGTH) throw new FormatException(); GroupId group = new GroupId(b); // Read the timestamp @@ -57,15 +57,15 @@ class MessageReader implements ObjectReader<Message> { messageDigest.reset(); r.addConsumer(digesting); r.readString(); - byte[] encodedKey = r.readRaw(); + byte[] encodedKey = r.readBytes(); r.removeConsumer(digesting); AuthorId author = new AuthorId(messageDigest.digest()); // Skip the message body - r.readRaw(); + r.readBytes(); // Record the length of the signed data int messageLength = (int) counting.getCount(); // Read the signature - byte[] sig = r.readRaw(); + byte[] sig = r.readBytes(); r.removeConsumer(counting); r.removeConsumer(copying); // Verify the signature diff --git a/components/net/sf/briar/serial/ReaderImpl.java b/components/net/sf/briar/serial/ReaderImpl.java index 648e94a10ca9aeceede0bddddfa44aa228d9d1f7..0f520d27e99db436d16f1e89dbbe16eda6cb57c0 100644 --- a/components/net/sf/briar/serial/ReaderImpl.java +++ b/components/net/sf/briar/serial/ReaderImpl.java @@ -7,10 +7,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.briar.api.serial.Bytes; import net.sf.briar.api.serial.Consumer; import net.sf.briar.api.serial.FormatException; import net.sf.briar.api.serial.ObjectReader; -import net.sf.briar.api.serial.RawByteArray; import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Tag; @@ -309,25 +309,25 @@ class ReaderImpl implements Reader { || next == Tag.INT32; } - public boolean hasRaw() throws IOException { + public boolean hasBytes() throws IOException { if(!started) readNext(true); if(eof) return false; - return next == Tag.RAW || (next & Tag.SHORT_MASK) == Tag.SHORT_RAW; + return next == Tag.BYTES || (next & Tag.SHORT_MASK) == Tag.SHORT_BYTES; } - public byte[] readRaw() throws IOException { - if(!hasRaw()) throw new FormatException(); - if(next == Tag.RAW) { + public byte[] readBytes() throws IOException { + if(!hasBytes()) throw new FormatException(); + if(next == Tag.BYTES) { readNext(false); - return readRaw(readLength()); + return readBytes(readLength()); } else { - int length = 0xFF & next ^ Tag.SHORT_RAW; + int length = 0xFF & next ^ Tag.SHORT_BYTES; readNext(length == 0); - return readRaw(length); + return readBytes(length); } } - private byte[] readRaw(int length) throws IOException { + private byte[] readBytes(int length) throws IOException { assert length >= 0; if(length == 0) return EMPTY_BUFFER; byte[] b = new byte[length]; @@ -395,7 +395,7 @@ class ReaderImpl implements Reader { if(hasFloat32()) return Float.valueOf(readFloat32()); if(hasFloat64()) return Double.valueOf(readFloat64()); if(hasString()) return readString(); - if(hasRaw()) return new RawByteArray(readRaw()); + if(hasBytes()) return new Bytes(readBytes()); if(hasList()) return readList(); if(hasMap()) return readMap(); if(hasNull()) { diff --git a/components/net/sf/briar/serial/WriterImpl.java b/components/net/sf/briar/serial/WriterImpl.java index b14c7fed51392a72be50cb285924646a453b1f62..b6d3b5b6c699d354a463d7c2bfb25e8eadbaca1a 100644 --- a/components/net/sf/briar/serial/WriterImpl.java +++ b/components/net/sf/briar/serial/WriterImpl.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import net.sf.briar.api.serial.Raw; +import net.sf.briar.api.serial.Bytes; import net.sf.briar.api.serial.Tag; import net.sf.briar.api.serial.Writable; import net.sf.briar.api.serial.Writer; @@ -123,20 +123,16 @@ class WriterImpl implements Writer { else writeInt32(i); } - public void writeRaw(byte[] b) throws IOException { - if(b.length < 16) out.write((byte) (Tag.SHORT_RAW | b.length)); + public void writeBytes(byte[] b) throws IOException { + if(b.length < 16) out.write((byte) (Tag.SHORT_BYTES | b.length)); else { - out.write(Tag.RAW); + out.write(Tag.BYTES); writeLength(b.length); } out.write(b); bytesWritten += b.length + 1; } - public void writeRaw(Raw r) throws IOException { - writeRaw(r.getBytes()); - } - public void writeList(Collection<?> c) throws IOException { int length = c.size(); if(length < 16) out.write((byte) (Tag.SHORT_LIST | length)); @@ -158,7 +154,7 @@ class WriterImpl implements Writer { else if(o instanceof Float) writeFloat32((Float) o); else if(o instanceof Double) writeFloat64((Double) o); else if(o instanceof String) writeString((String) o); - else if(o instanceof Raw) writeRaw((Raw) o); + else if(o instanceof Bytes) writeBytes(((Bytes) o).getBytes()); else if(o instanceof List) writeList((List<?>) o); else if(o instanceof Map) writeMap((Map<?, ?>) o); else if(o == null) writeNull(); diff --git a/test/net/sf/briar/protocol/AckReaderTest.java b/test/net/sf/briar/protocol/AckReaderTest.java index 4c793e218fa6a16c05ee48b4fae75c599075ea70..815553e28bdbf1fd8fe629cf7cd4a54d52876fe3 100644 --- a/test/net/sf/briar/protocol/AckReaderTest.java +++ b/test/net/sf/briar/protocol/AckReaderTest.java @@ -106,12 +106,12 @@ public class AckReaderTest extends TestCase { while(out.size() < Ack.MAX_SIZE - BatchId.SERIALISED_LENGTH) { w.writeUserDefinedTag(Tags.BATCH_ID); random.nextBytes(b); - w.writeRaw(b); + w.writeBytes(b); } if(tooBig) { w.writeUserDefinedTag(Tags.BATCH_ID); random.nextBytes(b); - w.writeRaw(b); + w.writeBytes(b); } w.writeListEnd(); assertEquals(tooBig, out.size() > Ack.MAX_SIZE); diff --git a/test/net/sf/briar/protocol/BatchReaderTest.java b/test/net/sf/briar/protocol/BatchReaderTest.java index f53641057f458ed6798044accafe0abb5abda6b2..7e58b5c264f5a02f1be00bf34fda98493c5cc1c1 100644 --- a/test/net/sf/briar/protocol/BatchReaderTest.java +++ b/test/net/sf/briar/protocol/BatchReaderTest.java @@ -150,7 +150,7 @@ public class BatchReaderTest extends TestCase { w.writeListStart(); // We're using a fake message reader, so it's OK to use a fake message w.writeUserDefinedTag(Tags.MESSAGE); - w.writeRaw(new byte[size - 10]); + w.writeBytes(new byte[size - 10]); w.writeListEnd(); byte[] b = out.toByteArray(); assertEquals(size, b.length); @@ -170,7 +170,7 @@ public class BatchReaderTest extends TestCase { public Message readObject(Reader r) throws IOException { r.readUserDefinedTag(Tags.MESSAGE); - r.readRaw(); + r.readBytes(); return message; } } diff --git a/test/net/sf/briar/serial/ReaderImplTest.java b/test/net/sf/briar/serial/ReaderImplTest.java index 5a52f28d85594bc0628dd6a473462897c9043512..8baaf127be5c098142ecf4afb0d4f8bd4137aa2f 100644 --- a/test/net/sf/briar/serial/ReaderImplTest.java +++ b/test/net/sf/briar/serial/ReaderImplTest.java @@ -12,8 +12,7 @@ import junit.framework.TestCase; import net.sf.briar.api.serial.Consumer; import net.sf.briar.api.serial.FormatException; import net.sf.briar.api.serial.ObjectReader; -import net.sf.briar.api.serial.Raw; -import net.sf.briar.api.serial.RawByteArray; +import net.sf.briar.api.serial.Bytes; import net.sf.briar.api.serial.Reader; import net.sf.briar.util.StringUtils; @@ -134,12 +133,12 @@ public class ReaderImplTest extends TestCase { } @Test - public void testReadRaw() throws Exception { + public void testReadBytes() throws Exception { setContents("F603010203" + "93010203" + "F600" + "90"); - assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readRaw())); - assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readRaw())); - assertTrue(Arrays.equals(new byte[] {}, r.readRaw())); - assertTrue(Arrays.equals(new byte[] {}, r.readRaw())); + assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readBytes())); + assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readBytes())); + assertTrue(Arrays.equals(new byte[] {}, r.readBytes())); + assertTrue(Arrays.equals(new byte[] {}, r.readBytes())); assertTrue(r.eof()); } @@ -197,9 +196,9 @@ public class ReaderImplTest extends TestCase { assertNotNull(m); assertEquals(2, m.size()); assertEquals((byte) 123, m.get("foo")); - Raw raw = new RawByteArray(new byte[] {}); - assertTrue(m.containsKey(raw)); - assertNull(m.get(raw)); + Bytes b = new Bytes(new byte[] {}); + assertTrue(m.containsKey(b)); + assertNull(m.get(b)); assertTrue(r.eof()); } @@ -210,9 +209,9 @@ public class ReaderImplTest extends TestCase { assertNotNull(m); assertEquals(2, m.size()); assertEquals((byte) 123, m.get("foo")); - Raw raw = new RawByteArray(new byte[] {}); - assertTrue(m.containsKey(raw)); - assertNull(m.get(raw)); + Bytes b = new Bytes(new byte[] {}); + assertTrue(m.containsKey(b)); + assertNull(m.get(b)); assertTrue(r.eof()); } @@ -275,9 +274,9 @@ public class ReaderImplTest extends TestCase { assertNotNull(m); assertEquals(2, m.size()); assertEquals((byte) 123, m.get("foo")); - Raw raw = new RawByteArray(new byte[] {}); - assertTrue(m.containsKey(raw)); - assertNull(m.get(raw)); + Bytes b = new Bytes(new byte[] {}); + assertTrue(m.containsKey(b)); + assertNull(m.get(b)); assertTrue(r.eof()); } @@ -291,7 +290,7 @@ public class ReaderImplTest extends TestCase { assertFalse(r.hasMapEnd()); assertEquals((byte) 123, r.readIntAny()); assertFalse(r.hasMapEnd()); - assertTrue(Arrays.equals(new byte[] {}, r.readRaw())); + assertTrue(Arrays.equals(new byte[] {}, r.readBytes())); assertFalse(r.hasMapEnd()); assertTrue(r.hasNull()); r.readNull(); diff --git a/test/net/sf/briar/serial/WriterImplTest.java b/test/net/sf/briar/serial/WriterImplTest.java index f71eb9edec08ac54c44ef263e345799ba2ac6f22..7e26cc347761c72ef5376962ee32a81038d82dde 100644 --- a/test/net/sf/briar/serial/WriterImplTest.java +++ b/test/net/sf/briar/serial/WriterImplTest.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Map; import junit.framework.TestCase; -import net.sf.briar.api.serial.RawByteArray; import net.sf.briar.api.serial.Writable; import net.sf.briar.api.serial.Writer; import net.sf.briar.util.StringUtils; @@ -152,38 +151,20 @@ public class WriterImplTest extends TestCase { } @Test - public void testWriteShortRawBytes() throws IOException { - w.writeRaw(new byte[] { + public void testWriteShortBytes() throws IOException { + w.writeBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }); - // SHORT_RAW tag, length 15, raw bytes + // SHORT_BYTES tag, length 15, bytes checkContents("9" + "F" + "000102030405060708090A0B0C0D0E"); } @Test - public void testWriteShortRawObject() throws IOException { - w.writeRaw(new RawByteArray(new byte[] { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 - })); - // SHORT_RAW tag, length 15, raw bytes - checkContents("9" + "F" + "000102030405060708090A0B0C0D0E"); - } - - @Test - public void testWriteRawBytes() throws IOException { - w.writeRaw(new byte[] { + public void testWriteBytes() throws IOException { + w.writeBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); - // RAW tag, length 16 as uint7, raw bytes - checkContents("F6" + "10" + "000102030405060708090A0B0C0D0E0F"); - } - - @Test - public void testWriteRawObject() throws IOException { - w.writeRaw(new RawByteArray(new byte[] { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 - })); - // RAW tag, length 16 as uint7, raw bytes + // BYTES tag, length 16 as uint7, bytes checkContents("F6" + "10" + "000102030405060708090A0B0C0D0E0F"); } @@ -257,11 +238,11 @@ public class WriterImplTest extends TestCase { w.writeMapStart(); w.writeString("foo"); // Written as short string w.writeIntAny(123); // Written as a uint7 - w.writeRaw(new byte[] {}); // Written as short raw + w.writeBytes(new byte[] {}); // Written as short bytes w.writeNull(); w.writeMapEnd(); // MAP_START tag, "foo" as short string, 123 as uint7, - // byte[] {} as short raw, NULL tag, END tag + // byte[] {} as short bytes, NULL tag, END tag checkContents("F2" + "83666F6F" + "7B" + "90" + "F0" + "F1"); } diff --git a/util/net/sf/briar/util/StringUtils.java b/util/net/sf/briar/util/StringUtils.java index cc0c92c18861d5c720aac7563fdca23d801bd6c9..acfdd3a911d31935ab55cc877492294d40ada5be 100644 --- a/util/net/sf/briar/util/StringUtils.java +++ b/util/net/sf/briar/util/StringUtils.java @@ -25,7 +25,7 @@ public class StringUtils { else return s; } - /** Converts the given raw byte array to a hex string. */ + /** Converts the given byte array to a hex string. */ public static String toHexString(byte[] bytes) { StringBuilder s = new StringBuilder(bytes.length * 2); for(byte b : bytes) { @@ -37,7 +37,7 @@ public class StringUtils { return s.toString(); } - /** Converts the given hex string to a raw byte array. */ + /** Converts the given hex string to a byte array. */ public static byte[] fromHexString(String hex) { int len = hex.length(); if(len % 2 != 0) throw new IllegalArgumentException("Not a hex string");