当前位置: 首页>>代码示例>>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;未经允许,请勿转载。