當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBufOutputStream類代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBufOutputStream的典型用法代碼示例。如果您正苦於以下問題:Java ByteBufOutputStream類的具體用法?Java ByteBufOutputStream怎麽用?Java ByteBufOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ByteBufOutputStream類屬於io.netty.buffer包,在下文中一共展示了ByteBufOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:24,代碼來源:KryoCodec.java

示例2: getDino

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
private static FullHttpResponse getDino(XrpcRequest request, List<Dino> dinos) {
  try {
    DinoGetRequest getRequest =
        DinoGetRequest.parseFrom(CodedInputStream.newInstance(request.getData().nioBuffer()));
    Optional<Dino> dinoOptional =
        dinos.stream().filter(xs -> xs.getName().equals(getRequest.getName())).findFirst();

    if (dinoOptional.isPresent()) {
      DinoGetReply getReply = DinoGetReply.newBuilder().setDino(dinoOptional.get()).build();
      ByteBuf resp = request.getByteBuf();
      resp.ensureWritable(CodedOutputStream.computeMessageSizeNoTag(getReply), true);
      getReply.writeTo(new ByteBufOutputStream(resp));

      return Recipes.newResponse(
          HttpResponseStatus.OK,
          request.getByteBuf().writeBytes(resp),
          Recipes.ContentType.Application_Octet_Stream);
    }

  } catch (IOException e) {
    return Recipes.newResponseBadRequest("Malformed GetDino Request: " + e.getMessage());
  }

  return Recipes.newResponseOk("Dino not Found");
}
 
開發者ID:Nordstrom,項目名稱:xrpc,代碼行數:26,代碼來源:Example.java

示例3: writeNBTTagCompoundToBuffer

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
/**
 * Writes a compressed NBTTagCompound to this buffer
 */
public void writeNBTTagCompoundToBuffer(NBTTagCompound nbt)
{
    if (nbt == null)
    {
        this.writeByte(0);
    }
    else
    {
        try
        {
            CompressedStreamTools.write(nbt, new ByteBufOutputStream(this));
        }
        catch (IOException ioexception)
        {
            throw new EncoderException(ioexception);
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:22,代碼來源:PacketBuffer.java

示例4: processRequest

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
private HttpResponse processRequest(FullHttpRequest request) throws JsonProcessingException {
    HttpResponse response;
    ByteBuf responseContent = Unpooled.buffer();
    HttpResponseStatus responseStatus = HttpResponseStatus.OK;
    try (ByteBufOutputStream os = new ByteBufOutputStream(responseContent);
         ByteBufInputStream is = new ByteBufInputStream(request.content().retain())){
        int result = jsonRpcServer.handleRequest(is, os);
        responseStatus = HttpResponseStatus.valueOf(DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result));
    } catch (Exception e) {
        LOGGER.error("Unexpected error", e);
        responseContent = buildErrorContent(JSON_RPC_SERVER_ERROR_HIGH_CODE, HttpResponseStatus.INTERNAL_SERVER_ERROR.reasonPhrase());
        responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
    } finally {
        response = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1,
            responseStatus,
            responseContent
        );
    }
    return response;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:22,代碼來源:JsonRpcWeb3ServerHandler.java

示例5: write

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
@Override
public void write(RakNetByteBuf out) {
    super.write(out);

    RakNetOutputStream os = new RakNetOutputStream(new BufferedOutputStream(new DeflaterOutputStream(new ByteBufOutputStream(out))));
    RakNetByteBuf payload = RakNetByteBuf.buffer();
    body.write(payload);
    try {
        int bodySize = payload.readableBytes();
        byte[] bytes = new byte[bodySize];
        payload.readBytes(bytes);
        os.writeUnsignedVarInt(bodySize);
        os.write(bytes);
    } catch (Exception ignored) {
    } finally {
        payload.release();
    }
}
 
開發者ID:MagicDroidX,項目名稱:RakNetty,代碼行數:19,代碼來源:GameWrapperPacket.java

示例6: encode

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, T msg, ByteBuf out)
        throws Exception {

    int lengthIndex = out.writerIndex();
    // length field, will be filled in later.
    out.writeInt(0);

    int startIndex = out.writerIndex();
    ByteBufOutputStream os = new ByteBufOutputStream(out);
    TCompactProtocol thriftProtocol =
            new TCompactProtocol(new TIOStreamTransport(os));
    msg.write(thriftProtocol);
    os.close();
    int endIndex = out.writerIndex();

    // update the length field
    int length = endIndex - startIndex;
    out.setInt(lengthIndex, length);
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:21,代碼來源:ThriftFrameEncoder.java

示例7: writeNBTTagCompoundToBuffer

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
/**
 * Writes a compressed NBTTagCompound to this buffer
 */
public PacketBuffer writeNBTTagCompoundToBuffer(@Nullable NBTTagCompound nbt)
{
    if (nbt == null)
    {
        this.writeByte(0);
    }
    else
    {
        try
        {
            CompressedStreamTools.write(nbt, new ByteBufOutputStream(this));
        }
        catch (IOException ioexception)
        {
            throw new EncoderException(ioexception);
        }
    }

    return this;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:24,代碼來源:PacketBuffer.java

示例8: writeNBTTagCompoundToBuffer

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
public static void writeNBTTagCompoundToBuffer(ByteBuf buf, NBTTagCompound tag)
{
    if (tag == null)
    {
        buf.writeByte(0);
        return;
    }

    try
    {
        CompressedStreamTools.write(tag, new ByteBufOutputStream(buf));
    }
    catch (IOException ioexception)
    {
        ModLogger.error("IOException while trying to write a NBTTagCompound to ByteBuf");
        throw new EncoderException(ioexception);
    }
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:19,代碼來源:ByteBufUtils.java

示例9: writeResourceReport

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
private void writeResourceReport(Channel channel) {
  ByteBuf content = Unpooled.buffer();
  Writer writer = new OutputStreamWriter(new ByteBufOutputStream(content), CharsetUtil.UTF_8);
  try {
    reportAdapter.toJson(resourceReport.get(), writer);
    writer.close();
  } catch (IOException e) {
    LOG.error("error writing resource report", e);
    writeAndClose(channel, new DefaultFullHttpResponse(
      HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR,
      Unpooled.copiedBuffer(e.getMessage(), StandardCharsets.UTF_8)));
    return;
  }

  FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, content);
  HttpUtil.setContentLength(response, content.readableBytes());
  response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=UTF-8");
  channel.writeAndFlush(response);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:20,代碼來源:TrackerService.java

示例10: toBytes

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
@Override
public void toBytes(ByteBuf buf)
{
    ByteBufOutputStream output = new ByteBufOutputStream(buf);

    try
    {
        output.writeUTF(this.filename);
        output.writeInt(this.frames.size());

        for (Frame frame : this.frames)
        {
            frame.toBytes(output);
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
開發者ID:mchorse,項目名稱:blockbuster,代碼行數:21,代碼來源:PacketFrames.java

示例11: serialize

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
/**
 * Serializes the passed object to the passed byte buffer or a new one if the passed one is null
 * @param object The object to serialize
 * @param buff The buffer to write to, or null to create a new one
 * @return the written buffer
 */
public static ByteBuf serialize(final Object object, final ByteBuf buff) {
	if (object == null) throw new IllegalArgumentException("Object was null");
	final ByteBuf _buff = buff==null ? byteBufAllocator.buffer() : buff;
	final OutputStream os = new ByteBufOutputStream(_buff);
	try {
		serialize(object, os);
		os.flush();
		os.close();
	} catch (Exception ex) {
		throw new RuntimeException("Failed to write object to buffer", ex);
	} finally {
		try { os.close(); } catch (Exception x) {/* No Op */}
	}
	return _buff;
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:22,代碼來源:JSONOps.java

示例12: serializeOffHeapLoopBack

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
/**
 * Serializes the passed object to an off-heap buffer and returns an InputStream to read it back
 * @param obj The object to serialize
 * @return an InputStream to read back the JSON serialized object 
 */
public static InputStream serializeOffHeapLoopBack(final Object obj) {
	if(obj==null) throw new IllegalArgumentException("The passed object was null");
	final ByteBuf cb = byteBufAllocator.buffer();
	final OutputStream os = new ByteBufOutputStream(cb);
	
	try {
		serialize(obj, os);
		os.flush();
		os.close();
	} catch (Exception ex) {
		throw new RuntimeException("Failed to write object to buffer", ex);
	}
	
	return new ByteBufInputStream(cb) {
		@Override
		public void close() throws IOException {				
			super.close();
			try { cb.release(); } catch (Exception x) {/* No Op */}
		}
	};
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:27,代碼來源:JSONOps.java

示例13: serializeAndGzip

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
/**
 * Serializes and gzips the passed object to the passed byte buffer or a new one if the passed one is null
 * @param object The object to serialize
 * @param buff The buffer to write to, or null to create a new one
 * @return the written buffer
 */
public static ByteBuf serializeAndGzip(final Object object, final ByteBuf buff) {
	if (object == null) throw new IllegalArgumentException("Object was null");
	final ByteBuf _buff = buff==null ? byteBufAllocator.buffer() : buff;
	 
	final OutputStream os = new ByteBufOutputStream(_buff);
	
	try {
		final GZIPOutputStream gos = new GZIPOutputStream(os);
		serialize(object, gos);
		gos.finish();
		gos.flush();
		gos.close();
		os.flush();
		os.close();
	} catch (Exception ex) {
		throw new RuntimeException("Failed to write object to buffer", ex);
	} finally {
		try { os.close(); } catch (Exception x) {/* No Op */}
	}
	return _buff;
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:28,代碼來源:JSONOps.java

示例14: getPayload

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
@Override
protected ByteBuf getPayload(ChannelHandlerContext ctx, Batch batch) throws IOException {
    ByteBuf payload = super.getPayload(ctx, batch);

    Deflater deflater = new Deflater();
    ByteBufOutputStream output = new ByteBufOutputStream(ctx.alloc().buffer());
    DeflaterOutputStream outputDeflater = new DeflaterOutputStream(output, deflater);

    byte[] chunk = new byte[payload.readableBytes()];
    payload.readBytes(chunk);
    outputDeflater.write(chunk);
    outputDeflater.close();

    ByteBuf content = ctx.alloc().buffer();
    content.writeByte(batch.getProtocol());
    content.writeByte('C');


    content.writeInt(output.writtenBytes());
    content.writeBytes(output.buffer());

    return content;
}
 
開發者ID:DTStack,項目名稱:jlogstash-input-plugin,代碼行數:24,代碼來源:CompressedBatchEncoder.java

示例15: channelActive

import io.netty.buffer.ByteBufOutputStream; //導入依賴的package包/類
@Override
public void channelActive(ChannelHandlerContext context) throws Exception {
  ByteBuf buffer = context.alloc().ioBuffer(1024);
  boolean success = false;
  try {
    ByteBufOutputStream out = new ByteBufOutputStream(buffer);
    for (String path : myLockedPaths) out.writeUTF(path);
    out.writeUTF(PATHS_EOT_RESPONSE);
    out.close();
    success = true;
  }
  finally {
    if (!success) {
      buffer.release();
    }
  }
  context.writeAndFlush(buffer);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:SocketLock.java


注:本文中的io.netty.buffer.ByteBufOutputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。