當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。