@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream result = new ByteBufOutputStream(out); ObjectOutputStream outputStream = new ObjectOutputStream(result); outputStream.writeObject(in); outputStream.close(); return result.buffer(); } catch (IOException e) { out.release(); throw e; } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream result = new ByteBufOutputStream(out); ObjectOutputStream outputStream = new ObjectOutputStream(result); outputStream.writeObject(in); outputStream.close(); return result.buffer(); } catch (IOException e) { out.release(); throw e; } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } catch (Exception e) { out.release(); throw new IOException(e); } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } catch (Exception e) { out.release(); throw new IOException(e); } } };
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) { io.netty.handler.codec.http.HttpMethod nettyMethod = io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name()); String authority = this.uri.getRawAuthority(); String path = this.uri.toString().substring(this.uri.toString().indexOf(authority) + authority.length()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, nettyMethod, path, this.body.buffer()); nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost() + ":" + getPort(this.uri)); nettyRequest.headers().set(HttpHeaders.CONNECTION, "close"); headers.forEach((headerName, headerValues) -> nettyRequest.headers().add(headerName, headerValues)); if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) { nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes()); } return nettyRequest; }
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); FSTObjectOutput oos = config.getObjectOutput(os); oos.writeObject(in); oos.flush(); return os.buffer(); } catch (IOException e) { out.release(); throw e; } catch (Exception e) { out.release(); throw new IOException(e); } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); FSTObjectOutput oos = config.getObjectOutput(os); oos.writeObject(in); oos.flush(); return os.buffer(); } catch (IOException e) { out.release(); throw e; } catch (Exception e) { out.release(); throw new IOException(e); } } };
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) { io.netty.handler.codec.http.HttpMethod nettyMethod = io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name()); String authority = this.uri.getRawAuthority(); String path = this.uri.toString().substring(this.uri.toString().indexOf(authority) + authority.length()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, nettyMethod, path, this.body.buffer()); nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost() + ":" + getPort(this.uri)); nettyRequest.headers().set(HttpHeaders.CONNECTION, "close"); headers.forEach((headerName, headerValues) -> nettyRequest.headers().add(headerName, headerValues)); if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) { nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes()); } return nettyRequest; }
@Override public ByteBuf encode(Object in) throws IOException { Kryo kryo = null; ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream baos = new ByteBufOutputStream(out); Output output = new Output(baos); kryo = kryoPool.get(); kryo.writeClassAndObject(output, in); output.close(); return baos.buffer(); } catch (Exception e) { out.release(); if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RedissonKryoCodecException(e); } finally { if (kryo != null) { kryoPool.yield(kryo); } } } };
@Override public ByteBuf encode(Object in) throws IOException { Kryo kryo = null; ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream baos = new ByteBufOutputStream(out); Output output = new Output(baos); kryo = kryoPool.get(); kryo.writeClassAndObject(output, in); output.close(); return baos.buffer(); } catch (Exception e) { out.release(); if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RedissonKryoCodecException(e); } finally { if (kryo != null) { kryoPool.yield(kryo); } } } };
private RedirectedPrintStream(Logger logger, @Nullable PrintStream outStream, boolean isErrorStream) { super(new ByteBufOutputStream(Unpooled.buffer())); // Safe cast as we know what outputStream we've created. this.buffer = ((ByteBufOutputStream) out).buffer(); this.logger = logger; this.outStream = outStream; this.isErrorStream = isErrorStream; }
private RedirectedPrintStream(Logger logger, @Nullable PrintStream outStream, boolean isErrorStream) { super(new ByteBufOutputStream(Unpooled.buffer())); // Safe cast as we know what outputStream we've created. this.buffer = ((ByteBufOutputStream) out).buffer(); this.logger = logger; this.outStream = outStream; this.isErrorStream = isErrorStream; }
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { ByteBufOutputStream os = new ByteBufOutputStream(out); mapObjectMapper.writeValue((OutputStream)os, in); return os.buffer(); } catch (IOException e) { out.release(); throw e; } } };
public void fixedNumberEviction(int numEvictions) { ByteBufOutputStream byteStream = new ByteBufOutputStream(PooledByteBufAllocator.DEFAULT.buffer()); try { for (int i = 0; i < numEvictions; i++) { doEvictPage(byteStream); } } finally { byteStream.buffer().release(); } }
public void backgroundEviction() { ByteBufOutputStream byteStream = new ByteBufOutputStream(PooledByteBufAllocator.DEFAULT.buffer()); try { while (shutdownEvictionThreads.get() && shouldEvictPage() && doEvictPage(byteStream)) ; } finally { byteStream.buffer().release(); } }
@Test public void testSerialize() throws Exception { ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer()); DefaultNBTSerializer.INSTANCE.serializeTag(stream, tag); Assertions.assertArrayEquals(serializedTagData, MiscSerializer.readAllBytes(stream.buffer())); }