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


Java CorruptedFrameException類代碼示例

本文整理匯總了Java中io.netty.handler.codec.CorruptedFrameException的典型用法代碼示例。如果您正苦於以下問題:Java CorruptedFrameException類的具體用法?Java CorruptedFrameException怎麽用?Java CorruptedFrameException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
protected void decode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf, List<Object> paramList)
        throws Exception {
    paramByteBuf.markReaderIndex();
    byte[] arrayOfByte = new byte[5];
    for(int i = 0; i < arrayOfByte.length; i++) {
        if(!paramByteBuf.isReadable()) {
            paramByteBuf.resetReaderIndex();
            return;
        }
        arrayOfByte[i] = paramByteBuf.readByte();
        if(arrayOfByte[i] >= 0) {
            int j = CodedInputStream.newInstance(arrayOfByte, 0, i + 1).readRawVarint32();
            if(j < 0) {
                throw new CorruptedFrameException("negative length: " + j);
            }
            if(paramByteBuf.readableBytes() < j) {
                paramByteBuf.resetReaderIndex();
                return;
            }
            paramList.add(paramByteBuf.readBytes(j));
            return;
        }
    }
    throw new CorruptedFrameException("length wider than 32-bit");
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:26,代碼來源:Varint32FrameDecoder.java

示例2: decodeSubscription

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
/**
 * Populate the message with couple of Qos, topic
 */
private void decodeSubscription(ByteBuf in, SubscribeMessage message) throws UnsupportedEncodingException
{
    String topic = Utils.decodeString(in);
    //check topic is at least one char [MQTT-4.7.3-1]
    if (topic.length() == 0) {
        throw new CorruptedFrameException("Received a SUBSCRIBE with empty topic filter");
    }
    byte qosByte = in.readByte();
    if ((qosByte & 0xFC) > 0) { //the first 6 bits is reserved => has to be 0
        throw new CorruptedFrameException("subscribe MUST have QoS byte with reserved buts to 0, found " + Integer.toHexString(qosByte));
    }
    byte qos = (byte) (qosByte & 0x03);
    //TODO check qos id 000000xx
    message.addSubscription(new SubscribeMessage.Couple(qos, topic));
}
 
開發者ID:sylvek,項目名稱:websocket-mqtt-forwarder,代碼行數:19,代碼來源:SubscribeDecoder.java

示例3: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    in.markReaderIndex();
    if (!Utils.checkHeaderAvailability(in)) {
        in.resetReaderIndex();
        return;
    }
    in.resetReaderIndex();
    
    byte messageType = Utils.readMessageType(in);
    
    DemuxDecoder decoder = m_decoderMap.get(messageType);
    if (decoder == null) {
        throw new CorruptedFrameException("Can't find any suitable decoder for message type: " + messageType);
    }
    decoder.decode(ctx, in, out);
}
 
開發者ID:sn3009,項目名稱:EasyMessage,代碼行數:18,代碼來源:MQTTDecoder.java

示例4: encodeRemainingLength

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
/**
 * Encode the value in the format defined in specification as variable length
 * array.
 * 
 * @throws IllegalArgumentException if the value is not in the specification bounds
 *  [0..268435455].
 */
static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException {
    if (value > MAX_LENGTH_LIMIT || value < 0) {
        throw new CorruptedFrameException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value);
    }

    ByteBuf encoded = Unpooled.buffer(4);
    byte digit;
    do {
        digit = (byte) (value % 128);
        value = value / 128;
        // if there are more digits to encode, set the top bit of this digit
        if (value > 0) {
            digit = (byte) (digit | 0x80);
        }
        encoded.writeByte(digit);
    } while (value > 0);
    return encoded;
}
 
開發者ID:sn3009,項目名稱:EasyMessage,代碼行數:26,代碼來源:Utils.java

示例5: testFailureDecodeBadRsa

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
@Test(expected = CorruptedFrameException.class)
public void testFailureDecodeBadRsa() throws Exception {
    // Decode our bad RSA key
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(TestVotifierPlugin.r("/bad_public.key"));
    PublicKey badPublicKey = keyFactory.generatePublic(publicKeySpec);

    // Send the bad vote
    EmbeddedChannel channel = createChannel();

    byte[] encrypted = VoteUtil.encodePOJOv1(new Vote("Test", "test", "test", "test"), badPublicKey);
    ByteBuf encryptedByteBuf = Unpooled.wrappedBuffer(encrypted);

    try {
        channel.writeInbound(encryptedByteBuf);
    } finally {
        channel.close();
    }
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:20,代碼來源:VotifierProtocol1DecoderTest.java

示例6: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    in.markReaderIndex();
    if (!Utils.checkHeaderAvailability(in)) {
        in.resetReaderIndex();
        return;
    }
    in.resetReaderIndex();

    byte messageType = Utils.readMessageType(in);

    DemuxDecoder decoder = m_decoderMap.get(messageType);
    if (decoder == null) {
        throw new CorruptedFrameException("Can't find any suitable decoder for message type: " + messageType);
    }
    decoder.decode(ctx, in, out);
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:18,代碼來源:MQTTDecoder.java

示例7: encodeRemainingLength

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
/**
 * Encode the value in the format defined in specification as variable length
 * array.
 *
 * @throws IllegalArgumentException if the value is not in the specification bounds
 *                                  [0..268435455].
 */
static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException {
    if (value > MAX_LENGTH_LIMIT || value < 0) {
        throw new CorruptedFrameException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value);
    }

    ByteBuf encoded = Unpooled.buffer(4);
    byte digit;
    do {
        digit = (byte) (value % 128);
        value = value / 128;
        // if there are more digits to encode, set the top bit of this digit
        if (value > 0) {
            digit = (byte) (digit | 0x80);
        }
        encoded.writeByte(digit);
    } while (value > 0);
    return encoded;
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:26,代碼來源:Utils.java

示例8: encodeRemainingLength

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
/**
 * Encode the value in the format defined in specification as variable length array.
 *
 * @throws IllegalArgumentException
 *             if the value is not in the specification bounds [0..268435455].
 */
static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException {
    if (value > MAX_LENGTH_LIMIT || value < 0) {
        throw new CorruptedFrameException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value);
    }

    ByteBuf encoded = Unpooled.buffer(4);
    byte digit;
    do {
        digit = (byte) (value % 128);
        value = value / 128;
        // if there are more digits to encode, set the top bit of this digit
        if (value > 0) {
            digit = (byte) (digit | 0x80);
        }
        encoded.writeByte(digit);
    } while (value > 0);
    return encoded;
}
 
開發者ID:andsel,項目名稱:moquette,代碼行數:25,代碼來源:Utils.java

示例9: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
private void decode(ByteBuf in, List<Object> out) throws Exception {
    in.markReaderIndex();
    if (!Utils.checkHeaderAvailability(in)) {
        in.resetReaderIndex();
        return;
    }
    in.resetReaderIndex();

    byte messageType = Utils.readMessageType(in);

    DemuxDecoder decoder = m_decoderMap.get(messageType);
    if (decoder == null) {
        throw new CorruptedFrameException("Can't find any suitable decoder for message type: " + messageType);
    }
    decoder.decode(in, out);
}
 
開發者ID:GruppoFilippetti,項目名稱:vertx-mqtt-broker,代碼行數:17,代碼來源:MQTTDecoder.java

示例10: encodeRemainingLength

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
/**
 * Encode the value in the format defined in specification as variable length
 * array.
 *
 * @throws IllegalArgumentException if the value is not in the specification bounds
 *  [0..268435455].
 */
static ByteBuf encodeRemainingLength(int value) throws CorruptedFrameException {
    if (value > MAX_LENGTH_LIMIT || value < 0) {
        throw new CorruptedFrameException("Value should in range 0.." + MAX_LENGTH_LIMIT + " found " + value);
    }

    ByteBuf encoded = Unpooled.buffer(4);
    byte digit;
    do {
        digit = (byte) (value % 128);
        value = value / 128;
        // if there are more digits to encode, set the top bit of this digit
        if (value > 0) {
            digit = (byte) (digit | 0x80);
        }
        encoded.writeByte(digit);
    } while (value > 0);
    return encoded;
}
 
開發者ID:GruppoFilippetti,項目名稱:vertx-mqtt-broker,代碼行數:26,代碼來源:Utils.java

示例11: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
@Override
void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    //Common decoding part
    in.resetReaderIndex();
    UnsubscribeMessage message = new UnsubscribeMessage();
    if (!decodeCommonHeader(message, in)) {
        in.resetReaderIndex();
        return;
    }
    
    //check qos level
    if (message.getQos() != AbstractMessage.QOSType.LEAST_ONE) {
        throw new CorruptedFrameException("Found an Usubscribe message with qos other than LEAST_ONE, was: " + message.getQos());
    }
        
    int start = in.readerIndex();
    //read  messageIDs
    message.setMessageID(in.readUnsignedShort());
    int readed = in.readerIndex()- start;
    while (readed < message.getRemainingLength()) {
        message.addTopic(Utils.decodeString(in));
        readed = in.readerIndex()- start;
    }
    
    out.add(message);
}
 
開發者ID:kevoree,項目名稱:kevoree-library,代碼行數:27,代碼來源:UnsubscribeDecoder.java

示例12: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
@Override
void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    //Common decoding part
    SubscribeMessage message = new SubscribeMessage();
    in.resetReaderIndex();
    if (!decodeCommonHeader(message, in)) {
        in.resetReaderIndex();
        return;
    }
    
    //check qos level
    if (message.getQos() != QOSType.LEAST_ONE) {
        throw new CorruptedFrameException("Received Subscribe message with QoS other than LEAST_ONE, was: " + message.getQos());
    }
        
    int start = in.readerIndex();
    //read  messageIDs
    message.setMessageID(in.readUnsignedShort());
    int readed = in.readerIndex() - start;
    while (readed < message.getRemainingLength()) {
        decodeSubscription(in, message);
        readed = in.readerIndex()- start;
    }
    
    out.add(message);
}
 
開發者ID:kevoree,項目名稱:kevoree-library,代碼行數:27,代碼來源:SubscribeDecoder.java

示例13: testBadFlagUserPwd

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
@Test(expected = CorruptedFrameException.class)
public void testBadFlagUserPwd() throws UnsupportedEncodingException, Exception {
    m_buff = Unpooled.buffer(14);
    m_buff.writeByte((AbstractMessage.CONNECT << 4)).writeByte(12);
    //Proto name
    encodeString(m_buff, "MQIsdp");
    //version
    m_buff.writeByte(3);
    //conn flags
    m_buff.writeByte(0x4E); //sets user to false and password to true
    //keepAlive
    m_buff.writeByte(0).writeByte(0x0A);
    List<Object> results = new ArrayList<Object >();
    
    //Excercise
    m_msgdec.decode(null, m_buff, results);
}
 
開發者ID:milliondreams,項目名稱:moquette-mqtt,代碼行數:18,代碼來源:ConnectDecoderTest.java

示例14: decode

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out) throws Exception {
	in.markReaderIndex();
	for(int i = 0; i < 3; i++) {
		if(!in.isReadable(i + 1)) {
			in.resetReaderIndex();
			return;
		}
		if(in.getByte(in.readerIndex() + i) < 0) {
			continue;
		}
		int size = BufferUtils.readVarInt(in);
		if(size > in.readableBytes()) {
			in.resetReaderIndex();
			return;
		}
		out.add(in.readBytes(size));
		return;
	}
	throw new CorruptedFrameException("VarInt size is longer than 21-bit");
}
 
開發者ID:LilyPad,項目名稱:JLilyPad,代碼行數:21,代碼來源:VarIntFrameCodec.java

示例15: readRawVarint32

import io.netty.handler.codec.CorruptedFrameException; //導入依賴的package包/類
public static int readRawVarint32(ByteBufInputStream is) throws IOException {
  byte tmp = is.readByte();
  if (tmp >= 0) {
    return tmp;
  }
  int result = tmp & 0x7f;
  if ((tmp = is.readByte()) >= 0) {
    result |= tmp << 7;
  } else {
    result |= (tmp & 0x7f) << 7;
    if ((tmp = is.readByte()) >= 0) {
      result |= tmp << 14;
    } else {
      result |= (tmp & 0x7f) << 14;
      if ((tmp = is.readByte()) >= 0) {
        result |= tmp << 21;
      } else {
        result |= (tmp & 0x7f) << 21;
        result |= (tmp = is.readByte()) << 28;
        if (tmp < 0) {
          // Discard upper 32 bits.
          for (int i = 0; i < 5; i++) {
            if (is.readByte() >= 0) {
              return result;
            }
          }
          throw new CorruptedFrameException("Encountered a malformed varint.");
        }
      }
    }
  }
  return result;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:34,代碼來源:RpcDecoder.java


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