mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Renamed serial component to data, moved consumers to briar-core.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import org.briarproject.api.UniqueId;
|
||||
|
||||
public interface SerialConstants {
|
||||
public interface DataConstants {
|
||||
|
||||
int LIST_START_LENGTH = 1;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.serial;
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user