public static String getStringContent(Object content) { if (content instanceof String) { return (String) content; } else if (content instanceof byte[]) { return new String((byte[]) content, StandardCharsets.UTF_8); } else if (content instanceof ByteBuf) { final ByteBuf byteBuf = (ByteBuf) content; byte[] bytes = new byte[byteBuf.readableBytes()]; byteBuf.readBytes(bytes); byteBuf.release(); return new String(bytes, StandardCharsets.UTF_8); } return content.toString(); }
@Override public void onNext(D doc) { try { callbackFired.set(true); WriteResponse writeResponse = new GenericWriteResponse<D>(doc); writeResponseQueue.add(new Pair<WriteResponse, Throwable>(writeResponse, null)); callback.onSuccess(writeResponse); } finally { if (doc instanceof TupleDocument) { ((TupleDocument) doc).content().value1().release(); } } } });
private <V> V deserialize(BinaryDocument doc, Deserializer<V> valueDeserializer) throws IOException { if (doc == null) { return null; } final ByteBuf byteBuf = doc.content(); final byte[] bytes = new byte[byteBuf.readableBytes()]; byteBuf.readBytes(bytes); byteBuf.release(); return valueDeserializer.deserialize(bytes); }
byteBuf.release(); }; doc = document;
@Override public boolean release(int decrement) { return content.release(decrement); } }
@Override public void delete() { if (byteBuf != null) { byteBuf.release(); byteBuf = null; } }
@Override public boolean release(int decrement) { return content.release(decrement); } }
@Override public boolean release(int decrement) { return buf.release(decrement); } }
@Override public void close() throws IOException { try { super.close(); } finally { // The Closable interface says "If the stream is already closed then invoking this method has no effect." if (releaseOnClose && !closed) { closed = true; buffer.release(); } } }
@Override public void call(ByteBuf byteBuf) { if (byteBuf != null && byteBuf.refCnt() > 0) { byteBuf.release(); } } };
@Override public boolean stop() { if (!stopped) { stopped = true; byteBuff.release(); } return stopped; }
@Override public boolean release(int decrement) { super.release(decrement); return content.release(decrement); }
/** * Fills the {@link ByteBuf} with zero bytes and releases it. */ static void zerooutAndRelease(ByteBuf buffer) { zeroout(buffer); buffer.release(); }
@Override public boolean release() { super.release(); return content.release(); }
@Override public boolean release() { super.release(); return content.release(); }
public void call(ByteBuf buf) { handle = buf.toString(CHARSET).replaceAll("^\"|\"$", ""); buf.release(); if (!sentResponse) { createResponse(); LOGGER.trace("Received handle for requestId {}", requestID); } } }),
public void setValue(String value, int rank) { if (value == null) { throw new NullPointerException("value"); } ByteBuf buf = Unpooled.copiedBuffer(value, charset); ByteBuf old = this.value.set(rank, buf); if (old != null) { size -= old.readableBytes(); old.release(); } size += buf.readableBytes(); }
@Override public void readHeaderBlock(ByteBuf headerBlock) { try { spdyHeaderBlockDecoder.decode(ctx.alloc(), headerBlock, spdyHeadersFrame); } catch (Exception e) { ctx.fireExceptionCaught(e); } finally { headerBlock.release(); } }