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


Java EmptyArrays.EMPTY_BYTES属性代码示例

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


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

示例1: get

@Override
public byte[] get() throws IOException {
    if (file == null) {
        return EmptyArrays.EMPTY_BYTES;
    }
    return readFrom(file);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:7,代码来源:AbstractDiskHttpData.java

示例2: newBinaryData

private static ByteBuf newBinaryData(int statusCode, String reasonText) {
    byte[] reasonBytes = EmptyArrays.EMPTY_BYTES;
    if (reasonText != null) {
        reasonBytes = reasonText.getBytes(CharsetUtil.UTF_8);
    }

    ByteBuf binaryData = Unpooled.buffer(2 + reasonBytes.length);
    binaryData.writeShort(statusCode);
    if (reasonBytes.length > 0) {
        binaryData.writeBytes(reasonBytes);
    }

    binaryData.readerIndex(0);
    return binaryData;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:15,代码来源:CloseWebSocketFrame.java

示例3: array

@Override
public byte[] array() {
    switch (components.size()) {
    case 0:
        return EmptyArrays.EMPTY_BYTES;
    case 1:
        return components.get(0).buf.array();
    default:
        throw new UnsupportedOperationException();
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:CompositeByteBuf.java

示例4: encodeConnectMessage

private static ByteBuf encodeConnectMessage(
        ByteBufAllocator byteBufAllocator,
        MqttConnectMessage message) {
    int payloadBufferSize = 0;

    MqttFixedHeader mqttFixedHeader = message.fixedHeader();
    MqttConnectVariableHeader variableHeader = message.variableHeader();
    MqttConnectPayload payload = message.payload();
    MqttVersion mqttVersion = MqttVersion.fromProtocolNameAndLevel(variableHeader.name(),
            (byte) variableHeader.version());

    // Client id
    String clientIdentifier = payload.clientIdentifier();
    if (!isValidClientId(mqttVersion, clientIdentifier)) {
        throw new MqttIdentifierRejectedException("invalid clientIdentifier: " + clientIdentifier);
    }
    byte[] clientIdentifierBytes = encodeStringUtf8(clientIdentifier);
    payloadBufferSize += 2 + clientIdentifierBytes.length;

    // Will topic and message
    String willTopic = payload.willTopic();
    byte[] willTopicBytes = willTopic != null ? encodeStringUtf8(willTopic) : EmptyArrays.EMPTY_BYTES;
    byte[] willMessage = payload.willMessageInBytes();
    byte[] willMessageBytes = willMessage != null ? willMessage : EmptyArrays.EMPTY_BYTES;
    if (variableHeader.isWillFlag()) {
        payloadBufferSize += 2 + willTopicBytes.length;
        payloadBufferSize += 2 + willMessageBytes.length;
    }

    String userName = payload.userName();
    byte[] userNameBytes = userName != null ? encodeStringUtf8(userName) : EmptyArrays.EMPTY_BYTES;
    if (variableHeader.hasUserName()) {
        payloadBufferSize += 2 + userNameBytes.length;
    }

    byte[] password = payload.passwordInBytes();
    byte[] passwordBytes = password != null ? password : EmptyArrays.EMPTY_BYTES;
    if (variableHeader.hasPassword()) {
        payloadBufferSize += 2 + passwordBytes.length;
    }

    // Fixed header
    byte[] protocolNameBytes = mqttVersion.protocolNameBytes();
    int variableHeaderBufferSize = 2 + protocolNameBytes.length + 4;
    int variablePartSize = variableHeaderBufferSize + payloadBufferSize;
    int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize);
    ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variablePartSize);
    buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
    writeVariableLengthInt(buf, variablePartSize);

    buf.writeShort(protocolNameBytes.length);
    buf.writeBytes(protocolNameBytes);

    buf.writeByte(variableHeader.version());
    buf.writeByte(getConnVariableHeaderFlag(variableHeader));
    buf.writeShort(variableHeader.keepAliveTimeSeconds());

    // Payload
    buf.writeShort(clientIdentifierBytes.length);
    buf.writeBytes(clientIdentifierBytes, 0, clientIdentifierBytes.length);
    if (variableHeader.isWillFlag()) {
        buf.writeShort(willTopicBytes.length);
        buf.writeBytes(willTopicBytes, 0, willTopicBytes.length);
        buf.writeShort(willMessageBytes.length);
        buf.writeBytes(willMessageBytes, 0, willMessageBytes.length);
    }
    if (variableHeader.hasUserName()) {
        buf.writeShort(userNameBytes.length);
        buf.writeBytes(userNameBytes, 0, userNameBytes.length);
    }
    if (variableHeader.hasPassword()) {
        buf.writeShort(passwordBytes.length);
        buf.writeBytes(passwordBytes, 0, passwordBytes.length);
    }
    return buf;
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:76,代码来源:MqttEncoder.java

示例5: array

@Override
public byte[] array() {
    return EmptyArrays.EMPTY_BYTES;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:4,代码来源:EmptyByteBuf.java

示例6: finishEncode

private ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelPromise promise) {
    if (finished) {
        promise.setSuccess();
        return promise;
    }
    finished = true;

    ByteBuf footer;
    try {
        // Configure input.
        z.next_in = EmptyArrays.EMPTY_BYTES;
        z.next_in_index = 0;
        z.avail_in = 0;

        // Configure output.
        byte[] out = new byte[32]; // room for ADLER32 + ZLIB / CRC32 + GZIP header
        z.next_out = out;
        z.next_out_index = 0;
        z.avail_out = out.length;

        // Write the ADLER32 checksum (stream footer).
        int resultCode = z.deflate(JZlib.Z_FINISH);
        if (resultCode != JZlib.Z_OK && resultCode != JZlib.Z_STREAM_END) {
            promise.setFailure(ZlibUtil.deflaterException(z, "compression failure", resultCode));
            return promise;
        } else if (z.next_out_index != 0) {
            footer = Unpooled.wrappedBuffer(out, 0, z.next_out_index);
        } else {
            footer = Unpooled.EMPTY_BUFFER;
        }
    } finally {
        z.deflateEnd();

        // Deference the external references explicitly to tell the VM that
        // the allocated byte arrays are temporary so that the call stack
        // can be utilized.
        // I'm not sure if the modern VMs do this optimization though.
        z.next_in = null;
        z.next_out = null;
    }
    return ctx.writeAndFlush(footer, promise);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:42,代码来源:JZlibEncoder.java

示例7: encodeConnectMessage

private static ByteBuf encodeConnectMessage(
        ByteBufAllocator byteBufAllocator,
        MqttConnectMessage message) {
    int payloadBufferSize = 0;

    MqttFixedHeader mqttFixedHeader = message.fixedHeader();
    MqttConnectVariableHeader variableHeader = message.variableHeader();
    MqttConnectPayload payload = message.payload();
    MqttVersion mqttVersion = MqttVersion.fromProtocolNameAndLevel(variableHeader.protocolName(),
            (byte) variableHeader.protocolLevel());

    // Client id
    String clientId = payload.clientId();
    byte[] clientIdBytes = encodeStringUtf8(clientId);
    payloadBufferSize += 2 + clientIdBytes.length;

    // Will topic and message
    String willTopic = payload.willTopic();
    byte[] willTopicBytes = willTopic != null ? encodeStringUtf8(willTopic) : EmptyArrays.EMPTY_BYTES;
    String willMessage = payload.willMessage();
    byte[] willMessageBytes = willMessage != null ? encodeStringUtf8(willMessage) : EmptyArrays.EMPTY_BYTES;
    if (variableHeader.willFlag()) {
        payloadBufferSize += 2 + willTopicBytes.length;
        payloadBufferSize += 2 + willMessageBytes.length;
    }

    String userName = payload.userName();
    byte[] userNameBytes = userName != null ? encodeStringUtf8(userName) : EmptyArrays.EMPTY_BYTES;
    if (variableHeader.userNameFlag()) {
        payloadBufferSize += 2 + userNameBytes.length;
    }

    String password = payload.password();
    byte[] passwordBytes = password != null ? encodeStringUtf8(password) : EmptyArrays.EMPTY_BYTES;
    if (variableHeader.passwordFlag()) {
        payloadBufferSize += 2 + passwordBytes.length;
    }

    // Fixed header
    byte[] protocolNameBytes = mqttVersion.protocolNameBytes();
    int variableHeaderBufferSize = 2 + protocolNameBytes.length + 4;
    int variablePartSize = variableHeaderBufferSize + payloadBufferSize;
    int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize);
    ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variablePartSize);
    buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
    writeVariableLengthInt(buf, variablePartSize);

    buf.writeShort(protocolNameBytes.length);
    buf.writeBytes(protocolNameBytes);

    buf.writeByte(variableHeader.protocolLevel());
    buf.writeByte(getConnVariableHeaderFlag(variableHeader));
    buf.writeShort(variableHeader.keepAlive());

    // Payload
    buf.writeShort(clientIdBytes.length);
    buf.writeBytes(clientIdBytes, 0, clientIdBytes.length);
    if (variableHeader.willFlag()) {
        buf.writeShort(willTopicBytes.length);
        buf.writeBytes(willTopicBytes, 0, willTopicBytes.length);
        buf.writeShort(willMessageBytes.length);
        buf.writeBytes(willMessageBytes, 0, willMessageBytes.length);
    }
    if (variableHeader.userNameFlag()) {
        buf.writeShort(userNameBytes.length);
        buf.writeBytes(userNameBytes, 0, userNameBytes.length);
    }
    if (variableHeader.passwordFlag()) {
        buf.writeShort(passwordBytes.length);
        buf.writeBytes(passwordBytes, 0, passwordBytes.length);
    }

    return buf;
}
 
开发者ID:longkerdandy,项目名称:mithqtt,代码行数:74,代码来源:MqttEncoder.java

示例8: toBytes

/**
 * Convert a string of hex values into a string of bytes.
 *
 * @param values
 *            "0f:ca:fe:de:ad:be:ef"
 * @return [15, 5 ,2, 5, 17]
 * @throws NumberFormatException
 *             If the string can not be parsed
 */
public static byte[] toBytes(final String values) throws NumberFormatException {
    int start = 0;
    int len = values.length();

    if (len == 0) {
        return EmptyArrays.EMPTY_BYTES;
    }

    int numColons = 0;
    for (int i=0; i < len; i++) {
        if (values.charAt(i) == ':') {
            numColons++;
        }
    }

    byte[] res = new byte[numColons+1];
    int pos = 0;

    int state = FIRST_DIGIT;

    byte b = 0;
    while (start < len) {
        char c = values.charAt(start++);
        switch (state) {
            case FIRST_DIGIT:
                int digit = Character.digit(c, 16);
                if(digit < 0) {
                    throw new NumberFormatException("Invalid char at index " + start + ": " + values);
                }
                b = (byte) digit;
                state = start < len ? SECOND_DIGIT_OR_COLON : SAVE_BYTE;
                break;
            case SECOND_DIGIT_OR_COLON:
                if(c != ':') {
                    int digit2 = Character.digit(c, 16);
                    if(digit2 < 0) {
                        throw new NumberFormatException("Invalid char at index " + start + ": " + values);
                    }
                    b =  (byte) ((b<<4) | digit2);
                    state = start < len ? COLON : SAVE_BYTE;
                } else {
                    state = SAVE_BYTE;
                }
                break;
            case COLON:
                if(c != ':') {
                    throw new NumberFormatException("Separator expected at index " + start + ": " + values);
                }
                state = SAVE_BYTE;
                break;
            default:
                throw new IllegalStateException("Should not be in state " + state);
        }
        if (state == SAVE_BYTE) {
            res[pos++] = b;
            b = 0;
            state = FIRST_DIGIT;
        }
    }
    if (pos != res.length) {
        // detects a mal-formed input string, e.g., "01:02:"
        throw new NumberFormatException("Invalid hex string: " + values);
    }

    return res;
}
 
开发者ID:floodlight,项目名称:loxigen-artifacts,代码行数:75,代码来源:HexString.java


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