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


Java DecoderException类代码示例

本文整理汇总了Java中io.netty.handler.codec.DecoderException的典型用法代码示例。如果您正苦于以下问题:Java DecoderException类的具体用法?Java DecoderException怎么用?Java DecoderException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: decode

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (in.readableBytes() <= 0)
		return;

	Packet packet = null;
	byte packetId = in.readByte();

	if (packetId < 0) {
		in.clear();
		throw new DecoderException("WTF, why is the packet id lower than zero?!?! Id: " + packetId);
	}
	Class<? extends Packet> clazz = PacketManager.getInstance().getPacketClass(packetId);

	if (clazz != null)
		packet = clazz.newInstance();

	if (packet == null) {
		throw new DecoderException("Cannot find packet id: " + packetId);
	}

	packet.decode(in);
	out.add(packet);
}
 
开发者ID:CentauriCloud,项目名称:CentauriCloud,代码行数:25,代码来源:PacketDecoder.java

示例2: convertFunction

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
private Function convertFunction ( final int functions )
{
    switch ( functions )
    {
        case 0x03 | 4:
            return Function.STARTDT_ACT;
        case 0x03 | 8:
            return Function.STARTDT_CONFIRM;
        case 0x03 | 16:
            return Function.STOPDT_ACT;
        case 0x03 | 32:
            return Function.STOPDT_CONFIRM;
        case 0x03 | 64:
            return Function.TESTFR_ACT;
        case 0x03 | 128:
            return Function.TESTFR_CONFIRM;
        default:
            throw new DecoderException ( String.format ( "Invalid function codes for U-format (%02x)", functions ) );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:APDUDecoder.java

示例3: readString

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
/**
 * Read string from buffer
 *
 * @param maxLength The slots length
 * @return The successful
 */
public String readString(int maxLength) {
    int i = this.readVarInt();

    if(i > maxLength * 4 || i < 0) {
        throw new DecoderException("The received encoded string buffer length is not allowed!");
    }
    else {
        ByteBuf part = buf.readBytes(i);
        String s = part.toString(Charsets.UTF_8);

        if(s.length() > maxLength) {
            throw new DecoderException("The received string length is longer than maximum allowed (" + i + " > " + maxLength + ")");
        }
        else {
            return s;
        }
    }
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:25,代码来源:PacketBuffer.java

示例4: decodeFixedHeader

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
/**
 * Decodes the fixed header. It's one byte for the flags and then variable bytes for the remaining length.
 *
 * @param buffer the buffer to decode from
 * @return the fixed header
 */
private static MqttFixedHeader decodeFixedHeader(ByteBuf buffer) {
    short b1 = buffer.readUnsignedByte();

    MqttMessageType messageType = MqttMessageType.valueOf(b1 >> 4);
    boolean dupFlag = (b1 & 0x08) == 0x08;
    int qosLevel = (b1 & 0x06) >> 1;
    boolean retain = (b1 & 0x01) != 0;

    int remainingLength = 0;
    int multiplier = 1;
    short digit;
    int loops = 0;
    do {
        digit = buffer.readUnsignedByte();
        remainingLength += (digit & 127) * multiplier;
        multiplier *= 128;
        loops++;
    } while ((digit & 128) != 0 && loops < 4);

    // MQTT protocol limits Remaining Length to 4 bytes
    if (loops == 4 && (digit & 128) != 0) {
        throw new DecoderException("remaining length exceeds 4 digits (" + messageType + ')');
    }
    return new MqttFixedHeader(messageType, dupFlag, MqttQoS.valueOf(qosLevel), retain, remainingLength);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:32,代码来源:MqttDecoder.java

示例5: decodePublishVariableHeader

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
private static Result<MqttPublishVariableHeader> decodePublishVariableHeader(
        ByteBuf buffer,
        MqttFixedHeader mqttFixedHeader) {
    final Result<String> decodedTopic = decodeString(buffer);
    if (!isValidPublishTopicName(decodedTopic.value)) {
        throw new DecoderException("invalid publish topic name: " + decodedTopic.value + " (contains wildcards)");
    }
    int numberOfBytesConsumed = decodedTopic.numberOfBytesConsumed;

    int messageId = -1;
    if (mqttFixedHeader.qosLevel().value() > 0) {
        final Result<Integer> decodedMessageId = decodeMessageId(buffer);
        messageId = decodedMessageId.value;
        numberOfBytesConsumed += decodedMessageId.numberOfBytesConsumed;
    }
    final MqttPublishVariableHeader mqttPublishVariableHeader =
            new MqttPublishVariableHeader(decodedTopic.value, messageId);
    return new Result<MqttPublishVariableHeader>(mqttPublishVariableHeader, numberOfBytesConsumed);
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:20,代码来源:MqttDecoder.java

示例6: getUnadjustedFrameLength

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
/**
 * Decodes the specified region of the buffer into an unadjusted frame length.  The default implementation is
 * capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer.  Override this method to
 * decode the length field encoded differently.  Note that this method must not modify the state of the specified
 * buffer (e.g. {@code readerIndex}, {@code writerIndex}, and the content of the buffer.)
 *
 * @throws DecoderException
 *         if failed to decode the specified region
 */
protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) {
    buf = buf.order(order);
    long frameLength;
    switch (length) {
        case 1:
            frameLength = buf.getUnsignedByte(offset);
            break;
        case 2:
            frameLength = buf.getUnsignedShort(offset);
            break;
        case 3:
            frameLength = buf.getUnsignedMedium(offset);
            break;
        case 4:
            frameLength = buf.getUnsignedInt(offset);
            break;
        case 8:
            frameLength = buf.getLong(offset);
            break;
        default:
            throw new DecoderException(
                    "unsupported lengthFieldLength: " + lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)");
    }
    return frameLength;
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:35,代码来源:LengthFieldBasedFrameDecoder.java

示例7: initiateProtocolOrSsl

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
void initiateProtocolOrSsl(String username, String password, String database, Handler<? super CommandResponse<Connection>> completionHandler) {
  ChannelPipeline pipeline = socket.channelHandlerContext().pipeline();
  if (ssl) {
    Future<Void> upgradeFuture = Future.future();
    upgradeFuture.setHandler(ar -> {
      if (ar.succeeded()) {
        initiateProtocol(username, password, database, completionHandler);
      } else {
        Throwable cause = ar.cause();
        if (cause instanceof DecoderException) {
          DecoderException err = (DecoderException) cause;
          cause = err.getCause();
        }
        completionHandler.handle(CommandResponse.failure(cause));
      }
    });
    pipeline.addBefore("handler", "initiate-ssl-handler", new InitiateSslHandler(this, upgradeFuture));
  } else {
    initiateProtocol(username, password, database, completionHandler);
  }
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:22,代码来源:SocketConnection.java

示例8: readVarIntArray

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
public int[] readVarIntArray(int maxLength)
{
    int i = this.readVarIntFromBuffer();

    if (i > maxLength)
    {
        throw new DecoderException("VarIntArray with size " + i + " is bigger than allowed " + maxLength);
    }
    else
    {
        int[] aint = new int[i];

        for (int j = 0; j < aint.length; ++j)
        {
            aint[j] = this.readVarIntFromBuffer();
        }

        return aint;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:21,代码来源:PacketBuffer.java

示例9: readLongArray

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
public long[] readLongArray(@Nullable long[] p_189423_1_, int p_189423_2_)
{
    int i = this.readVarIntFromBuffer();

    if (p_189423_1_ == null || p_189423_1_.length != i)
    {
        if (i > p_189423_2_)
        {
            throw new DecoderException("LongArray with size " + i + " is bigger than allowed " + p_189423_2_);
        }

        p_189423_1_ = new long[i];
    }

    for (int j = 0; j < p_189423_1_.length; ++j)
    {
        p_189423_1_[j] = this.readLong();
    }

    return p_189423_1_;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:22,代码来源:PacketBuffer.java

示例10: readEntries

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
@Nullable
public static List < EntityDataManager.DataEntry<? >> readEntries(PacketBuffer buf) throws IOException
{
    List < EntityDataManager.DataEntry<? >> list = null;
    int i;

    while ((i = buf.readUnsignedByte()) != 255)
    {
        if (list == null)
        {
            list = Lists. < EntityDataManager.DataEntry<? >> newArrayList();
        }

        int j = buf.readVarIntFromBuffer();
        DataSerializer<?> dataserializer = DataSerializers.getSerializer(j);

        if (dataserializer == null)
        {
            throw new DecoderException("Unknown serializer type " + j);
        }

        list.add(new EntityDataManager.DataEntry(dataserializer.createKey(i), dataserializer.read(buf)));
    }

    return list;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:27,代码来源:EntityDataManager.java

示例11: readLongArray

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
@SideOnly(Side.CLIENT)
public long[] readLongArray(@Nullable long[] p_189423_1_, int p_189423_2_)
{
    int i = this.readVarIntFromBuffer();

    if (p_189423_1_ == null || p_189423_1_.length != i)
    {
        if (i > p_189423_2_)
        {
            throw new DecoderException("LongArray with size " + i + " is bigger than allowed " + p_189423_2_);
        }

        p_189423_1_ = new long[i];
    }

    for (int j = 0; j < p_189423_1_.length; ++j)
    {
        p_189423_1_[j] = this.readLong();
    }

    return p_189423_1_;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:23,代码来源:PacketBuffer.java

示例12: readText

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
public String readText(final int i)
{
    final int j = this.readVarInt();
    if (j > (i << 2))
    {
        throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + j + " > " + (i << 2) + ")");
    }
    if (j < 0)
    {
        throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!");
    }
    final String s = new String(this.readBytes(j).array(), StandardCharsets.UTF_8);
    if (s.length() > i)
    {
        throw new DecoderException("The received string length is longer than maximum allowed (" + j + " > " + i + ")");
    }
    return s;
}
 
开发者ID:Diorite,项目名称:Diorite-old,代码行数:19,代码来源:PacketDataSerializer.java

示例13: decode

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
    ByteBuf buf = (ByteBuf) super.decode(ctx, buffer);
    if (buf != null) {
        try {
            int pos = buf.bytesBefore((byte) config.getStartByte());
            if (pos >= 0) {
                ByteBuf msg = buf.readerIndex(pos + 1).slice();
                LOG.debug("Message ends with length {}", msg.readableBytes());
                return config.isProduceString() ? asString(msg) : asByteArray(msg);
            } else {
                throw new DecoderException("Did not find start byte " + (int) config.getStartByte());
            }
        } finally {
            // We need to release the buf here to avoid the memory leak
            buf.release();
        }
    }
    // Message not complete yet - return null to be called again
    LOG.debug("No complete messages yet at position {}", buffer.readableBytes());
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:HL7MLLPNettyDecoder.java

示例14: exceptionCaught

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
@Override
public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if(cause instanceof DecoderException && cause != null) {
        cause = cause.getCause();
    }
    
    errorHandler.logError(cause, false);
    
    if(cause instanceof NotSslRecordException) {
        log.warn("Someone ({}) speaks transport plaintext instead of ssl, will close the channel", ctx.channel().remoteAddress());
        ctx.channel().close();
        return;
    } else if (cause instanceof SSLException) {
        log.error("SSL Problem "+cause.getMessage(),cause);
        ctx.channel().close();
        return;
    } else if (cause instanceof SSLHandshakeException) {
        log.error("Problem during handshake "+cause.getMessage());
        ctx.channel().close();
        return;
    }

    super.exceptionCaught(ctx, cause);
}
 
开发者ID:floragunncom,项目名称:search-guard-ssl,代码行数:25,代码来源:SearchGuardSSLNettyTransport.java

示例15: decode

import io.netty.handler.codec.DecoderException; //导入依赖的package包/类
@Override
public Message decode(CodecContext context, ByteBuffer buf) throws CodecException {
    int action = buf.readByte();
    Vector3i position = buf.read(Types.VECTOR_3_I);
    int face = buf.readByte();
    switch (action) {
        case 0:
        case 1:
        case 2:
            return new MessagePlayInPlayerDigging(MessagePlayInPlayerDigging.Action.values()[action],
                    position, fromFace(face));
        case 3:
        case 4:
            return new MessagePlayInDropHeldItem(action == 3);
        case 5:
            return new MessagePlayInOutFinishUsingItem();
        case 6:
            return new MessagePlayInSwapHandItems();
        default:
            throw new DecoderException("Unknown player digging message action: " + action);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:CodecPlayInPlayerDigging.java


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