static public void byteBuffer2Record(ByteBuffer bb, Record record) throws IOException { BinaryInputArchive ia; ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); record.deserialize(ia, "request"); }
static public void byteBuffer2Record(ByteBuffer bb, Record record) throws IOException { BinaryInputArchive ia; ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); record.deserialize(ia, "request"); }
@Before public void setUp() throws Exception { bb = ByteBuffer.wrap(DATA_BYTES); in = new ByteBufferInputStream(bb); bs = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 }; }
void readConnectResult() throws IOException { if (LOG.isTraceEnabled()) { StringBuilder buf = new StringBuilder("0x["); for (byte b : incomingBuffer.array()) { buf.append(Integer.toHexString(b) + ","); } buf.append("]"); LOG.trace("readConnectResult " + incomingBuffer.remaining() + " " + buf.toString()); } ByteBufferInputStream bbis = new ByteBufferInputStream(incomingBuffer); BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis); ConnectResponse conRsp = new ConnectResponse(); conRsp.deserialize(bbia, "connect"); // read "is read-only" flag boolean isRO = false; try { isRO = bbia.readBool("readOnly"); } catch (IOException e) { // this is ok -- just a packet from an old server which // doesn't contain readOnly field LOG.warn("Connected to an old server; r-o mode will be unavailable"); } this.sessionId = conRsp.getSessionId(); sendThread.onConnected(conRsp.getTimeOut(), this.sessionId, conRsp.getPasswd(), isRO); }
void readConnectResult() throws IOException { if (LOG.isTraceEnabled()) { StringBuilder buf = new StringBuilder("0x["); for (byte b : incomingBuffer.array()) { buf.append(Integer.toHexString(b) + ","); } buf.append("]"); LOG.trace("readConnectResult " + incomingBuffer.remaining() + " " + buf.toString()); } ByteBufferInputStream bbis = new ByteBufferInputStream(incomingBuffer); BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis); ConnectResponse conRsp = new ConnectResponse(); conRsp.deserialize(bbia, "connect"); // read "is read-only" flag boolean isRO = false; try { isRO = bbia.readBool("readOnly"); } catch (IOException e) { // this is ok -- just a packet from an old server which // doesn't contain readOnly field LOG.warn("Connected to an old server; r-o mode will be unavailable"); } this.sessionId = conRsp.getSessionId(); sendThread.onConnected(conRsp.getTimeOut(), this.sessionId, conRsp.getPasswd(), isRO); }
private MultiResponse codeDecode(MultiResponse request) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); request.serialize(boa, "result"); baos.close(); ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); bb.rewind(); BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); MultiResponse decodedRequest = new MultiResponse(); decodedRequest.deserialize(bia, "result"); return decodedRequest; }
private MultiTransactionRecord codeDecode(MultiTransactionRecord request) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos); request.serialize(boa, "request"); baos.close(); ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); bb.rewind(); BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); MultiTransactionRecord decodedRequest = new MultiTransactionRecord(); decodedRequest.deserialize(bia, "request"); return decodedRequest; } }
void readResponse(ByteBuffer incomingBuffer) throws IOException { ByteBufferInputStream bbis = new ByteBufferInputStream( incomingBuffer); BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis);
void readResponse(ByteBuffer incomingBuffer) throws IOException { ByteBufferInputStream bbis = new ByteBufferInputStream( incomingBuffer); BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis);
BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(incomingBuffer)); ConnectRequest connReq = new ConnectRequest(); connReq.deserialize(bia, "connect");
public void processConnectRequest(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException { BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(incomingBuffer)); ConnectRequest connReq = new ConnectRequest(); connReq.deserialize(bia, "connect");
public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException { InputStream bais = new ByteBufferInputStream(incomingBuffer); BinaryInputArchive bia = BinaryInputArchive.getArchive(bais); RequestHeader h = new RequestHeader();
public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException { InputStream bais = new ByteBufferInputStream(incomingBuffer); BinaryInputArchive bia = BinaryInputArchive.getArchive(bais); RequestHeader h = new RequestHeader();
@Override @SuppressWarnings({"unchecked"}) public Req deserializeRequest(ByteBuffer from) throws IOException { ObjectInputStream oin = new ObjectInputStream(new ByteBufferInputStream(from)); try { return (Req)oin.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e.getMessage(), e); } finally{ oin.close(); } }
@Override @SuppressWarnings({"unchecked"}) public Res deserializeResponse(ByteBuffer from) throws IOException { ObjectInputStream oin = new ObjectInputStream(new ByteBufferInputStream(from)); try { return (Res)oin.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e.getMessage(), e); } finally{ oin.close(); } }
@Override public Req deserializeRequest(ByteBuffer from) throws IOException { ByteBufferInputStream bin = new ByteBufferInputStream(from); return reqCodec.deserialize(bin); }
@Override public Res deserializeResponse(ByteBuffer from) throws IOException { ByteBufferInputStream bin = new ByteBufferInputStream(from); return resCodec.deserialize(bin); }
static public void byteBuffer2Record(ByteBuffer bb, Record record) throws IOException { BinaryInputArchive ia; ia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb)); record.deserialize(ia, "request"); }
/** * Gets the table that starts at the given offset. */ public Table getTable(int offset) throws UnknownTableException, DroppedTableException { preBufferAccess(); try { // Duplicate the buffer to allow for concurrent reads without locking ByteBuffer dup = _buffer.asReadOnlyBuffer(); // Move to the given offset dup.position(offset); // Read the length int length = dup.getInt(); if (length < 0) { // This was an exception throwUnknownOrDroppedTableException(dup, length); } // Restrict the buffer to only read the length of the table dup = (ByteBuffer) dup.slice().limit(length); try (InputStream in = new ByteBufferInputStream(dup)) { return getTableSerializer().deserialize(in); } catch (IOException e) { throw Throwables.propagate(e); } } finally { postBufferAccess(); } }
public static InputStream toJavabin(Object o) throws IOException { try (final JavaBinCodec jbc = new JavaBinCodec()) { BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS(); jbc.marshal(o,baos); return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(),0,baos.size())); } }