mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Implemented incoming and outgoing batch connections (untested).
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package net.sf.briar.transport.batch;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.briar.api.transport.batch.BatchTransportReader;
|
||||
|
||||
class ByteArrayBatchTransportReader extends FilterInputStream
|
||||
implements BatchTransportReader {
|
||||
|
||||
ByteArrayBatchTransportReader(ByteArrayInputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void dispose() throws IOException {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return in.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return in.read(b, off, len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.sf.briar.transport.batch;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import net.sf.briar.api.transport.batch.BatchTransportWriter;
|
||||
|
||||
class ByteArrayBatchTransportWriter extends FilterOutputStream
|
||||
implements BatchTransportWriter {
|
||||
|
||||
private int capacity;
|
||||
|
||||
ByteArrayBatchTransportWriter(ByteArrayOutputStream out, int capacity) {
|
||||
super(out);
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public long getCapacity() throws IOException {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void dispose() throws IOException {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
if(capacity < 1) throw new IllegalArgumentException();
|
||||
out.write(b);
|
||||
capacity--;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if(len > capacity) throw new IllegalArgumentException();
|
||||
out.write(b, off, len);
|
||||
capacity -= len;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user