java: add Unpacker.wrap method

This commit is contained in:
frsyuki 2010-05-20 06:18:32 +09:00
parent 135a9f5586
commit 985c31b378

View File

@ -40,7 +40,7 @@ public class Unpacker implements Iterable<Object> {
protected int bufferReserveSize; protected int bufferReserveSize;
protected InputStream stream; protected InputStream stream;
class BufferedUnpackerMixin extends BufferedUnpackerImpl { final class BufferedUnpackerMixin extends BufferedUnpackerImpl {
boolean fill() throws IOException { boolean fill() throws IOException {
if(stream == null) { if(stream == null) {
return false; return false;
@ -109,6 +109,16 @@ public class Unpacker implements Iterable<Object> {
bufferConsumed(length); bufferConsumed(length);
} }
public void wrap(byte[] buffer) {
wrap(buffer, 0, buffer.length);
}
public void wrap(byte[] buffer, int offset, int length) {
impl.buffer = buffer;
impl.offset = offset;
impl.filled = length;
}
public boolean fill() throws IOException { public boolean fill() throws IOException {
return impl.fill(); return impl.fill();
} }
@ -226,51 +236,51 @@ public class Unpacker implements Iterable<Object> {
} }
final public byte unpackByte() throws IOException, MessageTypeException { public byte unpackByte() throws IOException, MessageTypeException {
return impl.unpackByte(); return impl.unpackByte();
} }
final public short unpackShort() throws IOException, MessageTypeException { public short unpackShort() throws IOException, MessageTypeException {
return impl.unpackShort(); return impl.unpackShort();
} }
final public int unpackInt() throws IOException, MessageTypeException { public int unpackInt() throws IOException, MessageTypeException {
return impl.unpackInt(); return impl.unpackInt();
} }
final public long unpackLong() throws IOException, MessageTypeException { public long unpackLong() throws IOException, MessageTypeException {
return impl.unpackLong(); return impl.unpackLong();
} }
final public float unpackFloat() throws IOException, MessageTypeException { public float unpackFloat() throws IOException, MessageTypeException {
return impl.unpackFloat(); return impl.unpackFloat();
} }
final public double unpackDouble() throws IOException, MessageTypeException { public double unpackDouble() throws IOException, MessageTypeException {
return impl.unpackDouble(); return impl.unpackDouble();
} }
final public Object unpackNull() throws IOException, MessageTypeException { public Object unpackNull() throws IOException, MessageTypeException {
return impl.unpackNull(); return impl.unpackNull();
} }
final public boolean unpackBoolean() throws IOException, MessageTypeException { public boolean unpackBoolean() throws IOException, MessageTypeException {
return impl.unpackBoolean(); return impl.unpackBoolean();
} }
final public int unpackArray() throws IOException, MessageTypeException { public int unpackArray() throws IOException, MessageTypeException {
return impl.unpackArray(); return impl.unpackArray();
} }
final public int unpackMap() throws IOException, MessageTypeException { public int unpackMap() throws IOException, MessageTypeException {
return impl.unpackMap(); return impl.unpackMap();
} }
final public int unpackRaw() throws IOException, MessageTypeException { public int unpackRaw() throws IOException, MessageTypeException {
return impl.unpackRaw(); return impl.unpackRaw();
} }
final public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { public byte[] unpackRawBody(int length) throws IOException, MessageTypeException {
return impl.unpackRawBody(length); return impl.unpackRawBody(length);
} }