@Override public OutputStream asOutputStream() { return new ByteBufOutputStream(this.byteBuf); }
public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method) { this.bootstrap = bootstrap; this.uri = uri; this.method = method; this.body = new ByteBufOutputStream(Unpooled.buffer(1024)); }
@Override public OutputStream asOutputStream() { return new ByteBufOutputStream(this.byteBuf); }
public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method) { this.bootstrap = bootstrap; this.uri = uri; this.method = method; this.body = new ByteBufOutputStream(Unpooled.buffer(1024)); }
@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 void writeObject(Object obj) throws IOException { ByteBuf buf = Unpooled.buffer(estimatedLength); try { ObjectOutputStream oout = new CompactObjectOutputStream(new ByteBufOutputStream(buf)); try { oout.writeObject(obj); oout.flush(); } finally { oout.close(); } int objectSize = buf.readableBytes(); writeInt(objectSize); buf.getBytes(0, this, objectSize); } finally { buf.release(); } }
@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); } } };
@Override protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { ObjectOutputStream oos = newObjectOutputStream(new ByteBufOutputStream(out)); try { if (resetInterval != 0) { // Resetting will prevent OOM on the receiving side. writtenObjects ++; if (writtenObjects % resetInterval == 0) { oos.reset(); } } oos.writeObject(msg); oos.flush(); } finally { oos.close(); } } }
@Override public void writeObject(Object obj) throws IOException { ByteBuf buf = Unpooled.buffer(estimatedLength); try { ObjectOutputStream oout = new CompactObjectOutputStream(new ByteBufOutputStream(buf)); try { oout.writeObject(obj); oout.flush(); } finally { oout.close(); } int objectSize = buf.readableBytes(); writeInt(objectSize); buf.getBytes(0, this, objectSize); } finally { buf.release(); } }
@Override protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { ObjectOutputStream oos = newObjectOutputStream(new ByteBufOutputStream(out)); try { if (resetInterval != 0) { // Resetting will prevent OOM on the receiving side. writtenObjects ++; if (writtenObjects % resetInterval == 0) { oos.reset(); } } oos.writeObject(msg); oos.flush(); } finally { oos.close(); } } }
@Override protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { int startIdx = out.writerIndex(); ByteBufOutputStream bout = new ByteBufOutputStream(out); ObjectOutputStream oout = null; try { bout.write(LENGTH_PLACEHOLDER); oout = new CompactObjectOutputStream(bout); oout.writeObject(msg); oout.flush(); } finally { if (oout != null) { oout.close(); } else { bout.close(); } } int endIdx = out.writerIndex(); out.setInt(startIdx, endIdx - startIdx - 4); } }
@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 protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { final int length = in.readableBytes(); InputStream bbIn = null; ByteBufOutputStream bbOut = null; try { bbIn = new ByteBufInputStream(in); bbOut = new ByteBufOutputStream(out); bbOut.writeByte(properties); bbOut.writeInt(littleEndianDictionarySize); bbOut.writeLong(Long.reverseBytes(length)); encoder.code(bbIn, bbOut, -1, -1, null); } finally { if (bbIn != null) { bbIn.close(); } if (bbOut != null) { bbOut.close(); } } }
private void sendError(HttpErrorMessage errorMsg, ChannelHandlerContext ctx, ChannelPromise promise) throws IOException { final ByteBuf encBuf = encoder.allocateBuffer(ctx.alloc()); ByteBufOutputStream out = new ByteBufOutputStream(encBuf); encoder.getJsonSupport().writeValue(out, errorMsg.getData()); sendMessage(errorMsg, ctx.channel(), encBuf, "application/json", promise, HttpResponseStatus.BAD_REQUEST); }