From d512c218cd51d3851ada774fbd1aa6f93f8218c5 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Fri, 22 Jan 2016 11:50:06 +0000 Subject: [PATCH] Removed consumers from BdfWriter. --- .../org/briarproject/api/data/BdfWriter.java | 3 - .../org/briarproject/api/data/Consumer.java | 10 -- .../org/briarproject/data/BdfWriterImpl.java | 103 +++++++----------- 3 files changed, 41 insertions(+), 75 deletions(-) delete mode 100644 briar-api/src/org/briarproject/api/data/Consumer.java diff --git a/briar-api/src/org/briarproject/api/data/BdfWriter.java b/briar-api/src/org/briarproject/api/data/BdfWriter.java index e46e38a6de..b0f3432311 100644 --- a/briar-api/src/org/briarproject/api/data/BdfWriter.java +++ b/briar-api/src/org/briarproject/api/data/BdfWriter.java @@ -9,9 +9,6 @@ public interface BdfWriter { void flush() throws IOException; void close() throws IOException; - void addConsumer(Consumer c); - void removeConsumer(Consumer c); - void writeNull() throws IOException; void writeBoolean(boolean b) throws IOException; void writeInteger(long l) throws IOException; diff --git a/briar-api/src/org/briarproject/api/data/Consumer.java b/briar-api/src/org/briarproject/api/data/Consumer.java deleted file mode 100644 index d640ba2c08..0000000000 --- a/briar-api/src/org/briarproject/api/data/Consumer.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.briarproject.api.data; - -import java.io.IOException; - -public interface Consumer { - - void write(byte b) throws IOException; - - void write(byte[] b, int off, int len) throws IOException; -} diff --git a/briar-core/src/org/briarproject/data/BdfWriterImpl.java b/briar-core/src/org/briarproject/data/BdfWriterImpl.java index 9a7c04c817..07137184d5 100644 --- a/briar-core/src/org/briarproject/data/BdfWriterImpl.java +++ b/briar-core/src/org/briarproject/data/BdfWriterImpl.java @@ -3,11 +3,9 @@ package org.briarproject.data; import org.briarproject.api.Bytes; import org.briarproject.api.FormatException; import org.briarproject.api.data.BdfWriter; -import org.briarproject.api.data.Consumer; import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -35,7 +33,6 @@ import static org.briarproject.data.Types.TRUE; class BdfWriterImpl implements BdfWriter { private final OutputStream out; - private final Collection<Consumer> consumers = new ArrayList<Consumer>(0); BdfWriterImpl(OutputStream out) { this.out = out; @@ -49,100 +46,92 @@ class BdfWriterImpl implements BdfWriter { out.close(); } - public void addConsumer(Consumer c) { - consumers.add(c); - } - - public void removeConsumer(Consumer c) { - if (!consumers.remove(c)) throw new IllegalArgumentException(); - } - public void writeNull() throws IOException { - write(NULL); + out.write(NULL); } public void writeBoolean(boolean b) throws IOException { - if (b) write(TRUE); - else write(FALSE); + if (b) out.write(TRUE); + else out.write(FALSE); } public void writeInteger(long i) throws IOException { if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) { - write(INT_8); - write((byte) i); + out.write(INT_8); + out.write((byte) i); } else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) { - write(INT_16); + out.write(INT_16); writeInt16((short) i); } else if (i >= Integer.MIN_VALUE && i <= Integer.MAX_VALUE) { - write(INT_32); + out.write(INT_32); writeInt32((int) i); } else { - write(INT_64); + out.write(INT_64); writeInt64(i); } } private void writeInt16(short i) throws IOException { - write((byte) (i >> 8)); - write((byte) ((i << 8) >> 8)); + out.write((byte) (i >> 8)); + out.write((byte) ((i << 8) >> 8)); } private void writeInt32(int i) throws IOException { - write((byte) (i >> 24)); - write((byte) ((i << 8) >> 24)); - write((byte) ((i << 16) >> 24)); - write((byte) ((i << 24) >> 24)); + out.write((byte) (i >> 24)); + out.write((byte) ((i << 8) >> 24)); + out.write((byte) ((i << 16) >> 24)); + out.write((byte) ((i << 24) >> 24)); } private void writeInt64(long i) throws IOException { - write((byte) (i >> 56)); - write((byte) ((i << 8) >> 56)); - write((byte) ((i << 16) >> 56)); - write((byte) ((i << 24) >> 56)); - write((byte) ((i << 32) >> 56)); - write((byte) ((i << 40) >> 56)); - write((byte) ((i << 48) >> 56)); - write((byte) ((i << 56) >> 56)); + out.write((byte) (i >> 56)); + out.write((byte) ((i << 8) >> 56)); + out.write((byte) ((i << 16) >> 56)); + out.write((byte) ((i << 24) >> 56)); + out.write((byte) ((i << 32) >> 56)); + out.write((byte) ((i << 40) >> 56)); + out.write((byte) ((i << 48) >> 56)); + out.write((byte) ((i << 56) >> 56)); } public void writeFloat(double d) throws IOException { - write(FLOAT_64); + out.write(FLOAT_64); writeInt64(Double.doubleToRawLongBits(d)); } public void writeString(String s) throws IOException { byte[] b = s.getBytes("UTF-8"); if (b.length <= Byte.MAX_VALUE) { - write(STRING_8); - write((byte) b.length); + out.write(STRING_8); + out.write((byte) b.length); } else if (b.length <= Short.MAX_VALUE) { - write(STRING_16); + out.write(STRING_16); writeInt16((short) b.length); } else { - write(STRING_32); + out.write(STRING_32); writeInt32(b.length); } - write(b); + out.write(b); } public void writeRaw(byte[] b) throws IOException { if (b.length <= Byte.MAX_VALUE) { - write(RAW_8); - write((byte) b.length); + out.write(RAW_8); + out.write((byte) b.length); } else if (b.length <= Short.MAX_VALUE) { - write(RAW_16); + out.write(RAW_16); writeInt16((short) b.length); } else { - write(RAW_32); + out.write(RAW_32); writeInt32(b.length); } - write(b); + out.write(b); } public void writeList(Collection<?> c) throws IOException { - write(LIST); + out.write(LIST); for (Object o : c) writeObject(o); - write(END); + out.write(END); } private void writeObject(Object o) throws IOException { @@ -163,38 +152,28 @@ class BdfWriterImpl implements BdfWriter { } public void writeListStart() throws IOException { - write(LIST); + out.write(LIST); } public void writeListEnd() throws IOException { - write(END); + out.write(END); } public void writeDictionary(Map<?, ?> m) throws IOException { - write(DICTIONARY); + out.write(DICTIONARY); for (Entry<?, ?> e : m.entrySet()) { if (!(e.getKey() instanceof String)) throw new FormatException(); writeString((String) e.getKey()); writeObject(e.getValue()); } - write(END); + out.write(END); } public void writeDictionaryStart() throws IOException { - write(DICTIONARY); + out.write(DICTIONARY); } public void writeDictionaryEnd() throws IOException { - write(END); - } - - private void write(byte b) throws IOException { - out.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); + out.write(END); } } -- GitLab