From 36db5b48eff164547156793a7182708322eb1478 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Mon, 20 Feb 2023 13:05:38 +0000 Subject: [PATCH] Remove methods for manually reading lists and dictionaries. --- .../bramble/api/data/BdfReader.java | 12 ----- .../bramble/data/BdfReaderImpl.java | 50 ++++--------------- .../bramble/data/BdfReaderImplTest.java | 39 --------------- 3 files changed, 9 insertions(+), 92 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfReader.java b/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfReader.java index 7e1ff0e50..fe710becd 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfReader.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfReader.java @@ -60,23 +60,11 @@ public interface BdfReader { BdfList readList() throws IOException; - void readListStart() throws IOException; - - boolean hasListEnd() throws IOException; - - void readListEnd() throws IOException; - void skipList() throws IOException; boolean hasDictionary() throws IOException; BdfDictionary readDictionary() throws IOException; - void readDictionaryStart() throws IOException; - - boolean hasDictionaryEnd() throws IOException; - - void readDictionaryEnd() throws IOException; - void skipDictionary() throws IOException; } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/data/BdfReaderImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/data/BdfReaderImpl.java index 72fb8bd21..352c440d1 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/data/BdfReaderImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/data/BdfReaderImpl.java @@ -365,22 +365,11 @@ final class BdfReaderImpl implements BdfReader { private BdfList readList(int level) throws IOException { if (!hasList()) throw new FormatException(); if (level > nestedLimit) throw new FormatException(); - BdfList list = new BdfList(); - readListStart(); - while (!hasListEnd()) list.add(readObject(level + 1)); - readListEnd(); - return list; - } - - @Override - public void readListStart() throws IOException { - if (!hasList()) throw new FormatException(); hasLookahead = false; - } - - @Override - public boolean hasListEnd() throws IOException { - return hasEnd(); + BdfList list = new BdfList(); + while (!hasEnd()) list.add(readObject(level + 1)); + readEnd(); + return list; } private boolean hasEnd() throws IOException { @@ -389,11 +378,6 @@ final class BdfReaderImpl implements BdfReader { return next == END; } - @Override - public void readListEnd() throws IOException { - readEnd(); - } - private void readEnd() throws IOException { if (!hasEnd()) throw new FormatException(); hasLookahead = false; @@ -403,7 +387,7 @@ final class BdfReaderImpl implements BdfReader { public void skipList() throws IOException { if (!hasList()) throw new FormatException(); hasLookahead = false; - while (!hasListEnd()) skipObject(); + while (!hasEnd()) skipObject(); hasLookahead = false; } @@ -422,10 +406,10 @@ final class BdfReaderImpl implements BdfReader { private BdfDictionary readDictionary(int level) throws IOException { if (!hasDictionary()) throw new FormatException(); if (level > nestedLimit) throw new FormatException(); + hasLookahead = false; BdfDictionary dictionary = new BdfDictionary(); - readDictionaryStart(); String prevKey = null; - while (!hasDictionaryEnd()) { + while (!hasEnd()) { String key = readString(); if (canonical && prevKey != null && key.compareTo(prevKey) <= 0) { // Keys not unique and sorted @@ -434,31 +418,15 @@ final class BdfReaderImpl implements BdfReader { dictionary.put(key, readObject(level + 1)); prevKey = key; } - readDictionaryEnd(); - return dictionary; - } - - @Override - public void readDictionaryStart() throws IOException { - if (!hasDictionary()) throw new FormatException(); - hasLookahead = false; - } - - @Override - public boolean hasDictionaryEnd() throws IOException { - return hasEnd(); - } - - @Override - public void readDictionaryEnd() throws IOException { readEnd(); + return dictionary; } @Override public void skipDictionary() throws IOException { if (!hasDictionary()) throw new FormatException(); hasLookahead = false; - while (!hasDictionaryEnd()) { + while (!hasEnd()) { skipString(); skipObject(); } diff --git a/bramble-core/src/test/java/org/briarproject/bramble/data/BdfReaderImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/data/BdfReaderImplTest.java index 2b09189b7..f34935cf3 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/data/BdfReaderImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/data/BdfReaderImplTest.java @@ -526,25 +526,6 @@ public class BdfReaderImplTest extends BrambleTestCase { r.readList(); } - @Test - public void testReadListManually() throws Exception { - // A list containing 1, "foo", and null - setContents("60" + "21" + "01" + - "41" + "03" + "666F6F" + - "00" + "80"); - r.readListStart(); - assertFalse(r.hasListEnd()); - assertEquals(1, r.readLong()); - assertFalse(r.hasListEnd()); - assertEquals("foo", r.readString()); - assertFalse(r.hasListEnd()); - assertTrue(r.hasNull()); - r.readNull(); - assertTrue(r.hasListEnd()); - r.readListEnd(); - assertTrue(r.eof()); - } - @Test public void testSkipList() throws Exception { // A list containing 1, "foo", and 128 @@ -609,26 +590,6 @@ public class BdfReaderImplTest extends BrambleTestCase { r.readDictionary(); } - @Test - public void testReadDictionaryManually() throws Exception { - // A dictionary containing "foo" -> 123 and "bar" -> null - setContents("70" + "41" + "03" + "666F6F" + "21" + "7B" + - "41" + "03" + "626172" + "00" + "80"); - r.readDictionaryStart(); - assertFalse(r.hasDictionaryEnd()); - assertEquals("foo", r.readString()); - assertFalse(r.hasDictionaryEnd()); - assertEquals(123, r.readLong()); - assertFalse(r.hasDictionaryEnd()); - assertEquals("bar", r.readString()); - assertFalse(r.hasDictionaryEnd()); - assertTrue(r.hasNull()); - r.readNull(); - assertTrue(r.hasDictionaryEnd()); - r.readDictionaryEnd(); - assertTrue(r.eof()); - } - @Test public void testSkipDictionary() throws Exception { // A map containing "foo" -> 123 and "bar" -> null