2014-09-03 19:06:22 +00:00
|
|
|
package org.capnproto;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.channels.WritableByteChannel;
|
|
|
|
|
2014-09-03 21:50:23 +00:00
|
|
|
public final class ArrayOutputStream implements BufferedOutputStream {
|
2014-09-03 19:06:22 +00:00
|
|
|
|
|
|
|
public final ByteBuffer buf;
|
|
|
|
|
2014-09-03 21:50:23 +00:00
|
|
|
public ArrayOutputStream(ByteBuffer buf) {
|
2014-09-03 19:06:22 +00:00
|
|
|
this.buf = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final int write(ByteBuffer src) throws IOException {
|
|
|
|
int available = this.buf.remaining();
|
|
|
|
int size = src.remaining();
|
|
|
|
if (available < size) {
|
|
|
|
throw new IOException("backing buffer was not large enough");
|
|
|
|
}
|
|
|
|
this.buf.put(src);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final ByteBuffer getWriteBuffer() {
|
|
|
|
return this.buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void close() throws IOException {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean isOpen() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|