mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Changed the root package from net.sf.briar to org.briarproject.
This commit is contained in:
10
briar-api/src/org/briarproject/api/serial/Consumer.java
Normal file
10
briar-api/src/org/briarproject/api/serial/Consumer.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Consumer {
|
||||
|
||||
void write(byte b) throws IOException;
|
||||
|
||||
void write(byte[] b, int off, int len) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/** A consumer that makes a copy of the bytes consumed. */
|
||||
public class CopyingConsumer implements Consumer {
|
||||
|
||||
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
public byte[] getCopy() {
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
public void write(byte b) throws IOException {
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
out.write(b, off, len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
|
||||
/**
|
||||
* A consumer that counts the number of bytes consumed and throws a
|
||||
* FormatException if the count exceeds a given limit.
|
||||
*/
|
||||
public class CountingConsumer implements Consumer {
|
||||
|
||||
private final long limit;
|
||||
private long count = 0;
|
||||
|
||||
public CountingConsumer(long limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void write(byte b) throws IOException {
|
||||
count++;
|
||||
if(count > limit) throw new FormatException();
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
count += len;
|
||||
if(count > limit) throw new FormatException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import org.briarproject.api.crypto.MessageDigest;
|
||||
|
||||
/** A consumer that passes its input through a message digest. */
|
||||
public class DigestingConsumer implements Consumer {
|
||||
|
||||
private final MessageDigest messageDigest;
|
||||
|
||||
public DigestingConsumer(MessageDigest messageDigest) {
|
||||
this.messageDigest = messageDigest;
|
||||
}
|
||||
|
||||
public void write(byte b) {
|
||||
messageDigest.update(b);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) {
|
||||
messageDigest.update(b, off, len);
|
||||
}
|
||||
}
|
||||
79
briar-api/src/org/briarproject/api/serial/Reader.java
Normal file
79
briar-api/src/org/briarproject/api/serial/Reader.java
Normal file
@@ -0,0 +1,79 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Reader {
|
||||
|
||||
boolean eof() throws IOException;
|
||||
void close() throws IOException;
|
||||
|
||||
void addConsumer(Consumer c);
|
||||
void removeConsumer(Consumer c);
|
||||
|
||||
boolean hasBoolean() throws IOException;
|
||||
boolean readBoolean() throws IOException;
|
||||
void skipBoolean() throws IOException;
|
||||
|
||||
boolean hasUint7() throws IOException;
|
||||
byte readUint7() throws IOException;
|
||||
void skipUint7() throws IOException;
|
||||
|
||||
boolean hasInt8() throws IOException;
|
||||
byte readInt8() throws IOException;
|
||||
void skipInt8() throws IOException;
|
||||
|
||||
boolean hasInt16() throws IOException;
|
||||
short readInt16() throws IOException;
|
||||
void skipInt16() throws IOException;
|
||||
|
||||
boolean hasInt32() throws IOException;
|
||||
int readInt32() throws IOException;
|
||||
void skipInt32() throws IOException;
|
||||
|
||||
boolean hasInt64() throws IOException;
|
||||
long readInt64() throws IOException;
|
||||
void skipInt64() throws IOException;
|
||||
|
||||
boolean hasIntAny() throws IOException;
|
||||
long readIntAny() throws IOException;
|
||||
void skipIntAny() throws IOException;
|
||||
|
||||
boolean hasFloat32() throws IOException;
|
||||
float readFloat32() throws IOException;
|
||||
void skipFloat32() throws IOException;
|
||||
|
||||
boolean hasFloat64() throws IOException;
|
||||
double readFloat64() throws IOException;
|
||||
void skipFloat64() throws IOException;
|
||||
|
||||
boolean hasString() throws IOException;
|
||||
String readString(int maxLength) throws IOException;
|
||||
void skipString(int maxLength) throws IOException;
|
||||
|
||||
boolean hasBytes() throws IOException;
|
||||
byte[] readBytes(int maxLength) throws IOException;
|
||||
void skipBytes(int maxLength) throws IOException;
|
||||
|
||||
boolean hasList() throws IOException;
|
||||
void readListStart() throws IOException;
|
||||
boolean hasListEnd() throws IOException;
|
||||
void readListEnd() throws IOException;
|
||||
void skipList() throws IOException;
|
||||
|
||||
boolean hasMap() throws IOException;
|
||||
void readMapStart() throws IOException;
|
||||
boolean hasMapEnd() throws IOException;
|
||||
void readMapEnd() throws IOException;
|
||||
void skipMap() throws IOException;
|
||||
|
||||
boolean hasStruct() throws IOException;
|
||||
boolean hasStruct(int id) throws IOException;
|
||||
void readStructStart(int id) throws IOException;
|
||||
boolean hasStructEnd() throws IOException;
|
||||
void readStructEnd() throws IOException;
|
||||
void skipStruct() throws IOException;
|
||||
|
||||
boolean hasNull() throws IOException;
|
||||
void readNull() throws IOException;
|
||||
void skipNull() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface ReaderFactory {
|
||||
|
||||
Reader createReader(InputStream in);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
public interface SerialComponent {
|
||||
|
||||
int getSerialisedListStartLength();
|
||||
|
||||
int getSerialisedListEndLength();
|
||||
|
||||
int getSerialisedStructStartLength(int id);
|
||||
|
||||
int getSerialisedStructEndLength();
|
||||
|
||||
int getSerialisedUniqueIdLength();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import org.briarproject.api.crypto.Signature;
|
||||
|
||||
/** A consumer that passes its input through a signature. */
|
||||
public class SigningConsumer implements Consumer {
|
||||
|
||||
private final Signature signature;
|
||||
|
||||
public SigningConsumer(Signature signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public void write(byte b) {
|
||||
signature.update(b);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) {
|
||||
signature.update(b, off, len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface StructReader<T> {
|
||||
|
||||
T readStruct(Reader r) throws IOException;
|
||||
}
|
||||
42
briar-api/src/org/briarproject/api/serial/Writer.java
Normal file
42
briar-api/src/org/briarproject/api/serial/Writer.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Writer {
|
||||
|
||||
void flush() throws IOException;
|
||||
void close() throws IOException;
|
||||
|
||||
void addConsumer(Consumer c);
|
||||
void removeConsumer(Consumer c);
|
||||
|
||||
void writeBoolean(boolean b) throws IOException;
|
||||
|
||||
void writeUint7(byte b) throws IOException;
|
||||
void writeInt8(byte b) throws IOException;
|
||||
void writeInt16(short s) throws IOException;
|
||||
void writeInt32(int i) throws IOException;
|
||||
void writeInt64(long l) throws IOException;
|
||||
void writeIntAny(long l) throws IOException;
|
||||
|
||||
void writeFloat32(float f) throws IOException;
|
||||
void writeFloat64(double d) throws IOException;
|
||||
|
||||
void writeString(String s) throws IOException;
|
||||
void writeBytes(byte[] b) throws IOException;
|
||||
|
||||
void writeList(Collection<?> c) throws IOException;
|
||||
void writeListStart() throws IOException;
|
||||
void writeListEnd() throws IOException;
|
||||
|
||||
void writeMap(Map<?, ?> m) throws IOException;
|
||||
void writeMapStart() throws IOException;
|
||||
void writeMapEnd() throws IOException;
|
||||
|
||||
void writeStructStart(int id) throws IOException;
|
||||
void writeStructEnd() throws IOException;
|
||||
|
||||
void writeNull() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.api.serial;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface WriterFactory {
|
||||
|
||||
Writer createWriter(OutputStream out);
|
||||
}
|
||||
Reference in New Issue
Block a user