public void decompress(ByteBuffer @in, ByteBuffer @out) { using (ByteBufferInputStream input = new ByteBufferInputStream(@in.duplicate())) using (DeflateStream inflater = new DeflateStream(input, CompressionMode.Decompress)) using (ByteBufferOutputStream output = new ByteBufferOutputStream(@out)) { inflater.CopyTo(output); } @out.flip(); @in.position(@in.limit()); }
public bool compress(ByteBuffer @in, ByteBuffer @out, ByteBuffer overflow) { using (ByteBufferOutputStream output = new ByteBufferOutputStream(@out, overflow)) { using (DeflateStream deflater = new DeflateStream(output, level)) using (ByteBufferInputStream input = new ByteBufferInputStream(@in.duplicate())) { input.CopyTo(deflater); } return output.Okay; } }
public bool compress(ByteBuffer @in, ByteBuffer @out, ByteBuffer overflow) { using (ByteBufferOutputStream output = new ByteBufferOutputStream(@out, overflow)) { using (DeflateStream deflater = new DeflateStream(output, level)) using (ByteBufferInputStream input = new ByteBufferInputStream(@in.duplicate())) { input.CopyTo(deflater); } return(output.Okay); } }
public Protocol GetRemote() { if (remoteProtocol != null) { return(remoteProtocol); // already have it } lock (remoteHashLock) { MD5 remoteHash; if (RemoteHashes.TryGetValue(transceiver.RemoteName, out remoteHash)) { lock (remoteProtocolsLock) { remoteProtocol = RemoteProtocols[remoteHash]; if (remoteProtocol != null) { return(remoteProtocol); // already cached } } } } Monitor.Enter(handshakeLock); try { // force handshake var bbo = new ByteBufferOutputStream(); // direct because the payload is tiny. Encoder outp = new BinaryEncoder(bbo); WriteHandshake(outp); outp.WriteInt(0); // empty metadata outp.WriteString(""); // bogus message name IList <MemoryStream> response = Transceiver.Transceive(bbo.GetBufferList()); var bbi = new ByteBufferInputStream(response); var inp = new BinaryDecoder(bbi); ReadHandshake(inp); return(remoteProtocol); } finally { Monitor.Exit(handshakeLock); } }
public void HandleResult(IList <MemoryStream> result) { var bbi = new ByteBufferInputStream(result); var input = new BinaryDecoder(bbi); if (!requestor.ReadHandshake(input)) { // Resend the handshake and return var handshake = new RpcRequest(request); IList <MemoryStream> requestBytes = handshake.GetBytes(requestor.Local, requestor); var transceiverCallback = new TransceiverCallback <T>(requestor, handshake, callback, local); requestor.Transceiver.Transceive(requestBytes, transceiverCallback); return; } // Read response; invoke callback var response = new Response(requestor, request, input); try { Object responseObject; try { responseObject = response.getResponse(); } catch (Exception e) { if (callback != null) { callback.HandleException(e); } return; } if (callback != null) { callback.HandleResult((T)responseObject); } } catch { //LOG.error("Error in callback handler: " + t, t); } }