inputStream = docId .map(key -> bucket.get(key, BinaryDocument.class)) .map(doc -> new ByteBufInputStream(doc.content())); break;
ByteBufInputStream bbis = null; try { bbis = new ByteBufInputStream(input); return mapper.readValue((InputStream)bbis, clazz); bbis.close();
@Override public void readFully(byte[] b, int off, int len) throws IOException { checkAvailable(len); buffer.readBytes(b, off, len); }
@Override public boolean readBoolean() throws IOException { checkAvailable(1); return read() != 0; }
private void checkAvailable(int fieldSize) throws IOException { if (fieldSize < 0) { throw new IndexOutOfBoundsException("fieldSize cannot be a negative number"); } if (fieldSize > available()) { throw new EOFException("fieldSize is too long! Length is " + fieldSize + ", but maximum is " + available()); } } }
@Override public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
@Override public void readFully(byte[] b) throws IOException { readFully(b, 0, b.length); }
@Override public int readUnsignedByte() throws IOException { return readByte() & 0xff; }
@Override public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
@Override public long readLong() throws IOException { checkAvailable(8); return buffer.readLong(); }
@Override public boolean readBoolean() throws IOException { checkAvailable(1); return read() != 0; }
private void checkAvailable(int fieldSize) throws IOException { if (fieldSize < 0) { throw new IndexOutOfBoundsException("fieldSize cannot be a negative number"); } if (fieldSize > available()) { throw new EOFException("fieldSize is too long! Length is " + fieldSize + ", but maximum is " + available()); } } }
@Override public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
@Override public void readFully(byte[] b) throws IOException { readFully(b, 0, b.length); }
@Override public int readUnsignedByte() throws IOException { return readByte() & 0xff; }
@Override public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } ObjectInputStream ois = new CompactObjectInputStream(new ByteBufInputStream(frame, true), classResolver); try { return ois.readObject(); } finally { ois.close(); } } }
@Override public short readShort() throws IOException { checkAvailable(2); return buffer.readShort(); }
@Override public int skipBytes(int n) throws IOException { int nBytes = Math.min(available(), n); buffer.skipBytes(nBytes); return nBytes; }
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } ObjectInputStream ois = new CompactObjectInputStream(new ByteBufInputStream(frame, true), classResolver); try { return ois.readObject(); } finally { ois.close(); } } }