当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufOutputStream.close方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBufOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufOutputStream.close方法的具体用法?Java ByteBufOutputStream.close怎么用?Java ByteBufOutputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBufOutputStream的用法示例。


在下文中一共展示了ByteBufOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: encode

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
    KryoContext kryoContext = kryoContextHolder.get();
    Kryo kryo = kryoContext.getKryo();
    Output output = kryoContext.getOut();
    output.clear();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    int startIdx = out.writerIndex();
    bout.write(LENGTH_PLACEHOLDER);
    output.setOutputStream(bout);
    output.writeByte(StreamMessageDecoder.KRYO_STREAM_VERSION);
    kryo.writeClassAndObject(output, msg);
    output.flush();
    bout.flush();
    bout.close();
    output.close();
    
    int endIdx = out.writerIndex();

    out.setInt(startIdx, endIdx - startIdx - 4);
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:22,代码来源:KryoObjectEncoder.java

示例4: networkedNbt

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@Override
public void networkedNbt(NBTTagCompound tag) {
    if (!this.worldObj.isRemote) {
        try {
            super.writeToNBT(tag); // Coordinates
            ByteBufOutputStream out = new ByteBufOutputStream(Unpooled.buffer());
            out.writeByte(PlayBlockPayload.Type.TILE_ENTITY_NBT.ordinal());
            ByteBufUtils.writeTag(out.buffer(), tag);
            FMLProxyPacket packet = new FMLProxyPacket(out.buffer(), PlayBlock.CHANNEL_ID);
            SharedRuntime.networkWrapper.sendToAllAround(packet, new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 250));
            out.close();
        } catch (IOException e) {
            PlayBlock.log(Level.WARN, "Failed to send tile info to players!");
        }
    }
}
 
开发者ID:sk89q,项目名称:playblock,代码行数:17,代码来源:TileEntityProjector.java

示例5: merge

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
public ByteBuf merge(final JsonGenerator jg, final List<TSMeta> metas) {
	merges++;
	final ByteBufOutputStream os = (ByteBufOutputStream)jg.getOutputTarget();
	final ByteBuf buff = os.buffer();
	//System.err.println("MetaBatch:" + metas.size() + ", Merges:" + merges);
	try {
		int cnt = 0;
		for(final TSMeta tsMeta: metas) {
			if(tsMeta==null) continue;
			jg.writeStartObject();				// start of query
			jg.writeStringField("aggregator", aggregator.name().toLowerCase());
			if(rateOptions!=null) {
				jg.writeStringField("rate", "true");  // FIXME
			}
			if(downSampling!=null) {
				jg.writeStringField("downsample", downSampling);
			}
			
			jg.writeArrayFieldStart("tsuids");								
			jg.writeString(tsMeta.getTSUID());
			jg.writeEndArray();					// end of tsuids
			jg.writeEndObject();				// end of query
			cnt++;
		}  // end of TSMetas
		log.info("Wrote {} TSDUID Queries", cnt);
		jg.writeEndArray(); // end of queries array
		jg.writeEndObject(); // end of request
		jg.flush();
		os.flush();
		jg.close();
		os.close();
		log.info("TSDB Request:\n{}", buff.toString(UTF8));
		return buff;
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:38,代码来源:RequestBuilder.java

示例6: writeMessage

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@SneakyThrows(IOException.class)
private void writeMessage(AppendBlock block, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(block.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);
    block.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize + currentBlockSize);
}
 
开发者ID:pravega,项目名称:pravega,代码行数:14,代码来源:CommandEncoder.java

示例7: toBytes

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@Override
public void toBytes(ByteBuf buf) {

    try {
        ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
        write(bbos);
        bbos.flush();
        bbos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Qmunity,项目名称:QmunityLib,代码行数:13,代码来源:Packet.java

示例8: encode

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, CLLPacket msg, List<Object> out) throws Exception {
	Class<? extends CLLPacket> packetClass = msg.getClass();
	if(registeredPackets.contains(packetClass)){
		ByteBuf writeBuffer = Unpooled.buffer();
		ByteBufOutputStream bbos = new ByteBufOutputStream(writeBuffer);
		writeBuffer.writeByte(registeredPackets.indexOf(packetClass));
		msg.writeDataTo(bbos);
		FMLProxyPacket packet = new FMLProxyPacket(new PacketBuffer(writeBuffer.copy()), MOD_CHANNEL);
		bbos.close();
		out.add(packet);
	}
}
 
开发者ID:Phlenum,项目名称:Combustible-Lemon-Launcher,代码行数:14,代码来源:CLLPacketHandler.java

示例9: decode

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
protected ResourceState decode(HttpResponse response) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ByteBufOutputStream out = new ByteBufOutputStream(buffer);
    response.getEntity().writeTo(out);
    out.flush();
    out.close();
    System.err.println("===================");
    System.err.println(buffer.toString(Charset.defaultCharset()));
    System.err.println("===================");
    return system.codecManager().decode(MediaType.JSON, buffer);
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:12,代码来源:BasicServerTest.java

示例10: decode

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
protected ResourceState decode(HttpResponse response) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ByteBufOutputStream out = new ByteBufOutputStream(buffer);
    response.getEntity().writeTo(out);
    out.flush();
    out.close();
    return system.codecManager().decode(MediaType.GIT_APP_JSON, buffer);
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:9,代码来源:GitApplicationsResourceTest.java

示例11: decode

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
protected ResourceState decode(HttpResponse response) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ByteBufOutputStream out = new ByteBufOutputStream(buffer);
    response.getEntity().writeTo(out);
    out.flush();
    out.close();
    System.err.println("========= HttpResponse ==========");
    System.err.println(buffer.toString(Charset.defaultCharset()));
    System.err.println("===================");
    return system.codecManager().decode(MediaType.LOCAL_APP_JSON, buffer);
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:12,代码来源:LocalApplicationsResourceTest.java

示例12: decode

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
protected ResourceState decode(HttpResponse response) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ByteBufOutputStream out = new ByteBufOutputStream(buffer);
    response.getEntity().writeTo(out);
    out.flush();
    out.close();
    System.err.println("========= HttpResponse ==========");
    System.err.println(buffer.toString(Charset.defaultCharset()));
    System.err.println("===================");
    return system.codecManager().decode(MediaType.JSON, buffer);
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:12,代码来源:AbstractContainerTest.java

示例13: toResourceState

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
protected ResourceState toResourceState(HttpEntity entity, MediaType contentType) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ByteBufOutputStream out = new ByteBufOutputStream(buffer);
    entity.writeTo(out);
    out.flush();
    out.close();
    return this.system.codecManager().decode(contentType, buffer);
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:9,代码来源:AbstractHTTPResourceTestCase.java

示例14: handle

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@Override
public void handle(ChannelHandlerContext context, URI uri, FullHttpRequest request) throws Exception {
    if (request.getMethod() != HttpMethod.GET) {
        sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED));
        return;
    }
    String modified = request.headers().get(IF_MODIFIED_SINCE);
    if (modified != null && !modified.isEmpty()) {
        Date modifiedDate = format.parse(modified);

        if (modifiedDate.equals(plugin.getStartUpDate())) {
            sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED));
            return;
        }
    }

    String path = uri.getPath();
    if (path.equals("/")) {
        path = "/index.html";
    }

    ByteBuf buffer;
    try (InputStream stream = this.getClass().getClassLoader().getResourceAsStream("www" + path)) {
        if (stream == null) {
            sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND));
            return;
        }
        ByteBufOutputStream out = new ByteBufOutputStream(context.alloc().buffer());
        IOUtils.copy(stream, out);
        buffer = out.buffer();
        out.close();
    }

    if (path.equals("/index.html")) {
        String page = buffer.toString(Charsets.UTF_8);
        page = page.replaceAll("%SERVERPORT%", Integer.toString(plugin.getConfiguration().getPort()));
        buffer.release();
        buffer = Unpooled.wrappedBuffer(page.getBytes(Charsets.UTF_8));
    }

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer);

    response.headers().set(DATE, format.format(new Date()));
    response.headers().set(LAST_MODIFIED, format.format(plugin.getStartUpDate()));


    String ext = path.substring(path.lastIndexOf('.') + 1);
    String type = mimeTypes.containsKey(ext) ? mimeTypes.get(ext) : "text/plain";
    if (type.startsWith("text/")) {
        type += "; charset=UTF-8";
    }
    response.headers().set(CONTENT_TYPE, type);
    sendHttpResponse(context, request, response);
}
 
开发者ID:Thinkofname,项目名称:ThinkMap,代码行数:55,代码来源:InternalWebServer.java

示例15: handle

import io.netty.buffer.ByteBufOutputStream; //导入方法依赖的package包/类
@Override
public void handle(ChannelHandlerContext context, URI uri, FullHttpRequest request) throws Exception {
    File file = new File(plugin.getResourceDir(), uri.getPath().substring("/resources/".length()));
    if (!file.exists()) {
        sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND));
        return;
    }

    String modified = request.headers().get(IF_MODIFIED_SINCE);
    if (modified != null && !modified.isEmpty()) {
        Date modifiedDate = format.parse(modified);

        if (modifiedDate.equals(plugin.getStartUpDate())) {
            sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED));
            return;
        }
    }

    ByteBuf buffer;
    try (InputStream stream = new FileInputStream(file)) {
        ByteBufOutputStream out = new ByteBufOutputStream(context.alloc().buffer());
        IOUtils.copy(stream, out);
        buffer = out.buffer();
        out.close();
    }

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer);

    response.headers().set(DATE, format.format(new Date()));
    response.headers().set(LAST_MODIFIED, format.format(plugin.getStartUpDate()));

    if (uri.getPath().startsWith("/resources/assets")) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, 1);
        response.headers().set(EXPIRES, format.format(calendar.getTime()));
        response.headers().set(CACHE_CONTROL, "public, max-age=2592000");
    }

    String path = uri.getPath();
    String ext = path.substring(path.lastIndexOf('.') + 1);
    String type = mimeTypes.containsKey(ext) ? mimeTypes.get(ext) : "text/plain";
    if (type.startsWith("text/")) {
        type += "; charset=UTF-8";
    }
    response.headers().set(CONTENT_TYPE, type);
    response.headers().add("Access-Control-Allow-Origin", "*");
    sendHttpResponse(context, request, response);
}
 
开发者ID:Thinkofname,项目名称:ThinkMap,代码行数:50,代码来源:ResourcesServer.java


注:本文中的io.netty.buffer.ByteBufOutputStream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。