mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Changed the root package from net.sf.briar to org.briarproject.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user