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


Java CharsetUtil.UTF_8屬性代碼示例

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


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

示例1: writeResponse

private void writeResponse(MessageEvent e) {
  HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");

  ChannelBuffer content = ChannelBuffers.dynamicBuffer();
  Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
  reportAdapter.toJson(report.get(), writer);
  try {
    writer.close();
  } catch (IOException e1) {
    LOG.error("error writing resource report", e1);
  }
  response.setContent(content);
  ChannelFuture future = e.getChannel().write(response);
  future.addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:16,代碼來源:TrackerService.java

示例2: decode

public static ByePacket decode(ChannelBuffer buffer, boolean hasPadding, byte innerBlocks, int length) {
    ByePacket packet = new ByePacket();
    int read = 0;
    for (int i = 0; i < innerBlocks; i++) {
        packet.addSsrc(buffer.readUnsignedInt());
        read += 4;
    }

    // Length is written in 32bit words, not octet count.
    int lengthInOctets = (length * 4);
    if (read < lengthInOctets) {
        byte[] reasonBytes = new byte[buffer.readUnsignedByte()];
        buffer.readBytes(reasonBytes);
        packet.reasonForLeaving = new String(reasonBytes, CharsetUtil.UTF_8);
        read += (1 + reasonBytes.length);
        if (read < lengthInOctets) {
            // Skip remaining bytes (used for padding). This takes care of both the null termination bytes (padding
            // of the 'reason for leaving' string and the packet padding bytes.
            buffer.skipBytes(lengthInOctets - read);
        }
    }

    return packet;
}
 
開發者ID:elasticsoftwarefoundation,項目名稱:elasterix,代碼行數:24,代碼來源:ByePacket.java

示例3: getPipeline

public ChannelPipeline getPipeline() {
    ChannelPipeline p = Channels.pipeline();
    Charset charset = CharsetUtil.UTF_8;
   
    ChannelBuffer[] delimiters = Delimiters.nulDelimiter();
   
    // setup the textline encoding and decoding
    p.addLast("decoder1", ChannelHandlerFactories.newDelimiterBasedFrameDecoder(1024 * 8, delimiters).newChannelHandler());
    p.addLast("decoder2", ChannelHandlerFactories.newStringDecoder(charset).newChannelHandler());
    
    p.addLast("encoder", ChannelHandlerFactories.newStringEncoder(charset).newChannelHandler());
    
    p.addLast("handler", new ServerHandler());
    return p;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:15,代碼來源:NettyConsumerClientModeTest.java

示例4: readHadoopString

/**
 * Reads a string encoded by {@code hadoop.io.WritableUtils#readString}.
 * @throws IllegalArgumentException if the length we read for the string
 * is out of reasonable bounds.
 */
static String readHadoopString(final ChannelBuffer buf) {
  final int length = buf.readInt();
  checkArrayLength(buf, length);
  final byte[] s = new byte[length];
  buf.readBytes(s);
  return new String(s, CharsetUtil.UTF_8);
}
 
開發者ID:OpenTSDB,項目名稱:asynccassandra,代碼行數:12,代碼來源:HBaseRpc.java

示例5: decode

public static SdesChunkItem decode(ChannelBuffer buffer) {
    SdesChunkItem.Type type = SdesChunkItem.Type.fromByte(buffer.readByte());
    switch (type) {
        case NULL:
            return NULL_ITEM;
        case CNAME:
        case NAME:
        case EMAIL:
        case PHONE:
        case LOCATION:
        case TOOL:
        case NOTE:
            byte[] value = new byte[buffer.readUnsignedByte()];
            buffer.readBytes(value);
            return new SdesChunkItem(type, new String(value, CharsetUtil.UTF_8));
        case PRIV:
            short valueLength = buffer.readUnsignedByte();
            short prefixLength = buffer.readUnsignedByte();
            // Value length field indicates the length of all that follows this field:
            // Prefix length (1b), Prefix (xb) and Value itself (xb). Thus, the actual value length is equal to
            // the length indicated by this field - 1b (prefix length) and - xb (prefix value).
            value = new byte[valueLength - prefixLength - 1];
            byte[] prefix = new byte[prefixLength];
            buffer.readBytes(prefix);
            buffer.readBytes(value);
            return new SdesChunkPrivItem(new String(prefix, CharsetUtil.UTF_8),
                    new String(value, CharsetUtil.UTF_8));
        default:
            throw new IllegalArgumentException("Unknown type of SDES chunk: " + type);
    }
}
 
開發者ID:elasticsoftwarefoundation,項目名稱:elasterix,代碼行數:31,代碼來源:SdesChunkItems.java

示例6: parseURI

public void parseURI(URI uri, Map<String, Object> parameters, NettyComponent component, String... supportedProtocols) throws Exception {
    protocol = uri.getScheme();

    boolean found = false;
    for (String supportedProtocol : supportedProtocols) {
        if (protocol != null && protocol.equalsIgnoreCase(supportedProtocol)) {
            found = true;
            break;
        }
    }

    if (!found) {
        throw new IllegalArgumentException("Unrecognized Netty protocol: " + protocol + " for uri: " + uri);
    }

    setHost(uri.getHost());
    if (uri.getPort() != -1) {
        setPort(uri.getPort());
    }

    ssl = component.getAndRemoveOrResolveReferenceParameter(parameters, "ssl", boolean.class, false);
    sslHandler = component.getAndRemoveOrResolveReferenceParameter(parameters, "sslHandler", SslHandler.class, sslHandler);
    passphrase = component.getAndRemoveOrResolveReferenceParameter(parameters, "passphrase", String.class, passphrase);
    keyStoreFormat = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreFormat", String.class, keyStoreFormat == null ? "JKS" : keyStoreFormat);
    securityProvider = component.getAndRemoveOrResolveReferenceParameter(parameters, "securityProvider", String.class, securityProvider == null ? "SunX509" : securityProvider);
    keyStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreFile", File.class, keyStoreFile);
    trustStoreFile = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreFile", File.class, trustStoreFile);
    keyStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "keyStoreResource", String.class, keyStoreResource);
    trustStoreResource = component.getAndRemoveOrResolveReferenceParameter(parameters, "trustStoreResource", String.class, trustStoreResource);
    clientPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "clientPipelineFactory", ClientPipelineFactory.class, clientPipelineFactory);
    serverPipelineFactory = component.getAndRemoveOrResolveReferenceParameter(parameters, "serverPipelineFactory", ServerPipelineFactory.class, serverPipelineFactory);

    // set custom encoders and decoders first
    List<ChannelHandler> referencedEncoders = component.resolveAndRemoveReferenceListParameter(parameters, "encoders", ChannelHandler.class, null);
    addToHandlersList(encoders, referencedEncoders, ChannelHandler.class);
    List<ChannelHandler> referencedDecoders = component.resolveAndRemoveReferenceListParameter(parameters, "decoders", ChannelHandler.class, null);
    addToHandlersList(decoders, referencedDecoders, ChannelHandler.class);

    // then set parameters with the help of the camel context type converters
    EndpointHelper.setReferenceProperties(component.getCamelContext(), this, parameters);
    EndpointHelper.setProperties(component.getCamelContext(), this, parameters);

    // additional netty options, we don't want to store an empty map, so set it as null if empty
    options = IntrospectionSupport.extractProperties(parameters, "option.");
    if (options !=  null && options.isEmpty()) {
        options = null;
    }

    // add default encoders and decoders
    if (encoders.isEmpty() && decoders.isEmpty()) {
        if (isAllowDefaultCodec()) {
            // are we textline or object?
            if (isTextline()) {
                Charset charset = getEncoding() != null ? Charset.forName(getEncoding()) : CharsetUtil.UTF_8;
                encoders.add(ChannelHandlerFactories.newStringEncoder(charset));
                ChannelBuffer[] delimiters = delimiter == TextLineDelimiter.LINE ? Delimiters.lineDelimiter() : Delimiters.nulDelimiter();
                decoders.add(ChannelHandlerFactories.newDelimiterBasedFrameDecoder(decoderMaxLineLength, delimiters));
                decoders.add(ChannelHandlerFactories.newStringDecoder(charset));

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Using textline encoders and decoders with charset: {}, delimiter: {} and decoderMaxLineLength: {}", 
                            new Object[]{charset, delimiter, decoderMaxLineLength});
                }
            } else {
                // object serializable is then used
                encoders.add(ChannelHandlerFactories.newObjectEncoder());
                decoders.add(ChannelHandlerFactories.newObjectDecoder());

                LOG.debug("Using object encoders and decoders");
            }
        } else {
            LOG.debug("No encoders and decoders will be used");
        }
    } else {
        LOG.debug("Using configured encoders and/or decoders");
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:77,代碼來源:NettyConfiguration.java


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