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


Java ByteBufOutputStream.buffer方法代碼示例

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


在下文中一共展示了ByteBufOutputStream.buffer方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: sendToClient

import io.netty.buffer.ByteBufOutputStream; //導入方法依賴的package包/類
public static void sendToClient(PlayBlockPayload payload, List<EntityPlayer> players) {
    ByteBufOutputStream out = new ByteBufOutputStream(Unpooled.buffer());

    try {
        payload.write(out);
        out.flush();
    } catch (IOException e) {
        PlayBlock.log(Level.WARN, "Failed to build packet to send to the client");
        return;
    }

    FMLProxyPacket packet = new FMLProxyPacket(out.buffer(), PlayBlock.CHANNEL_ID);

    if (players == null) {
        SharedRuntime.networkWrapper.sendToAll(packet);
    } else {
        for (EntityPlayer player : players) {
            if (player instanceof EntityPlayerMP) {
                SharedRuntime.networkWrapper.sendTo(packet, (EntityPlayerMP) player);
            }
        }
    }
}
 
開發者ID:sk89q,項目名稱:playblock,代碼行數:24,代碼來源:PacketHandler.java

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

示例4: encode

import io.netty.buffer.ByteBufOutputStream; //導入方法依賴的package包/類
@Override
public ByteBuf encode(Object in) throws IOException {
    ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
    try {
        ByteBufOutputStream os = new ByteBufOutputStream(out);
        mapper.writeValue((OutputStream)os, in);
        return os.buffer();
    } catch (IOException e) {
        out.release();
        throw e;
    }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:13,代碼來源:JsonJacksonMapCodec.java

示例5: encode

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

示例6: encode

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

示例7: encode

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

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

示例9: sendToServer

import io.netty.buffer.ByteBufOutputStream; //導入方法依賴的package包/類
/**
 * Send a payload to the server.
 * 
 * @param payload
 *            the payload
 */
public static void sendToServer(PlayBlockPayload payload) {
    ByteBufOutputStream out = new ByteBufOutputStream(Unpooled.buffer());

    try {
        payload.write(out);
        out.flush();
    } catch (IOException e) {
        PlayBlock.log(Level.WARN, "Failed to send packet to the server");
        return;
    }

    FMLProxyPacket packet = new FMLProxyPacket(out.buffer(), PlayBlock.CHANNEL_ID);
    SharedRuntime.networkWrapper.sendToServer(packet);
}
 
開發者ID:sk89q,項目名稱:playblock,代碼行數:21,代碼來源:PacketHandler.java

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

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