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


Java CodecException类代码示例

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


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

示例1: processTRAILER

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
private void processTRAILER ( final ChannelHandlerContext ctx, final byte b, final ByteBuf msg )
{
    if ( b != Constants.LF )
    {
        throw new CodecException ( String.format ( "Expected trailer byte (LF) but found 0x%02X: Remaining buffer: %s", b, ByteBufUtil.hexDump ( msg, msg.readerIndex (), msg.readableBytes () ) ) );
    }

    final int length = ctx.attr ( ATTR_EXPECTED_LENGTH ).get ();
    final long txnr = Long.parseLong ( ctx.attr ( ATTR_TXNR_BUFFER ).get ().toString ( TXNR_CHARSET ) );
    final String command = ctx.attr ( ATTR_COMMAND_BUFFER ).get ().toString ( COMMAND_CHARSET );
    final ByteBuf data = ctx.attr ( ATTR_DATA_BUFFER ).get ().readSlice ( length );

    final Frame frame = new Frame ( txnr, command, data );

    ctx.fireChannelRead ( frame );

    ctx.attr ( ATTR_STATE ).set ( State.TXNR );
    ctx.attr ( ATTR_TXNR_BUFFER ).get ().clear ();
    ctx.attr ( ATTR_COMMAND_BUFFER ).get ().clear ();
    ctx.attr ( ATTR_LENGTH_BUFFER ).get ().clear ();
    ctx.attr ( ATTR_DATA_BUFFER ).get ().clear ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:FrameCodec.java

示例2: processMessage

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
protected void processMessage ( final ChannelHandlerContext ctx, final ByteBuf msg )
{
    if ( msg.readByte () != PRI_START )
    {
        throw new CodecException ( "PRI start not found" );
    }

    final int prival = decodePrival ( msg );

    final Severity severity = Severity.values ()[prival % 8];
    final Facility facility = Facility.values ()[prival / 8];

    final Calendar timestamp = this.timestampParser.parseTimestamp ( msg );
    final String hostname = decodeHostname ( msg );
    final String[] process = decodeProcess ( msg );
    final String processName = process[0];
    final Long processId = process.length > 1 ? Long.parseLong ( process[1] ) : null;
    final String message = decodeMessage ( msg );

    ctx.fireChannelRead ( new SyslogMessage ( facility, severity, timestamp, hostname, processName, processId, message ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:SyslogCodec.java

示例3: decodeProcess

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
private String[] decodeProcess ( final ByteBuf msg )
{
    // split by colon
    final int spaceIndex = msg.bytesBefore ( COLON );
    if ( spaceIndex < 0 )
    {
        throw new CodecException ( "Unable to find process name" );
    }

    final String process = msg.readSlice ( spaceIndex ).toString ( StandardCharsets.US_ASCII );
    msg.skipBytes ( 1 ); // COLON
    if ( msg.isReadable () )
    {
        msg.skipBytes ( 1 ); // SPACE
    }

    final Matcher m = PROCESS_PATTERN.matcher ( process );
    if ( m.matches () )
    {
        return new String[] { m.group ( 1 ), m.group ( 2 ) };
    }

    return new String[] { process };
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:SyslogCodec.java

示例4: decodePrival

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
private int decodePrival ( final ByteBuf msg )
{
    final ByteBuffer privalBuffer = ByteBuffer.wrap ( new byte[3] );
    byte b;
    do
    {
        b = msg.readByte ();
        if ( b == PRI_END )
        {
            break;
        }
        if ( !privalBuffer.hasRemaining () )
        {
            throw new CodecException ( "PRI value must be <=3 bytes" );
        }
        privalBuffer.put ( b );
    } while ( true );

    privalBuffer.flip ();
    final int prival = Integer.parseInt ( StandardCharsets.US_ASCII.decode ( privalBuffer ).toString () );
    return prival;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:SyslogCodec.java

示例5: printAggregatedRedisResponse

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
private static void printAggregatedRedisResponse(RedisMessage msg) {
    if (msg instanceof SimpleStringRedisMessage) {
        System.out.println(((SimpleStringRedisMessage) msg).content());
    } else if (msg instanceof ErrorRedisMessage) {
        System.out.println(((ErrorRedisMessage) msg).content());
    } else if (msg instanceof IntegerRedisMessage) {
        System.out.println(((IntegerRedisMessage) msg).value());
    } else if (msg instanceof FullBulkStringRedisMessage) {
        System.out.println(getString((FullBulkStringRedisMessage) msg));
    } else if (msg instanceof ArrayRedisMessage) {
        for (RedisMessage child : ((ArrayRedisMessage) msg).children()) {
            printAggregatedRedisResponse(child);
        }
    } else {
        throw new CodecException("unknown message type: " + msg);
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:18,代码来源:RedisClientHandler.java

示例6: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    final String channel;
    final ByteBuffer content;
    if (message instanceof MessagePlayInOutChannelPayload) {
        final MessagePlayInOutChannelPayload message1 = (MessagePlayInOutChannelPayload) message;
        content = message1.getContent();
        channel = message1.getChannel();
    } else if (message instanceof MessagePlayInOutRegisterChannels) {
        content = encodeChannels(((MessagePlayInOutRegisterChannels) message).getChannels());
        channel = "REGISTER";
    } else if (message instanceof MessagePlayInOutUnregisterChannels) {
        content = encodeChannels(((MessagePlayInOutUnregisterChannels) message).getChannels());
        channel = "UNREGISTER";
    } else {
        final MessageResult result = encode0(context, message);
        channel = result.channel;
        content = result.byteBuf;
    }
    buf.writeString(channel);
    buf.writeBytes(content);
    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:AbstractCodecPlayInOutCustomPayload.java

示例7: process

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public void process(CodecContext context, MessageForgeHandshakeOutRegistryData message, List<Message> output) throws CodecException {
    final Iterator<Entry> it = message.getEntries().iterator();
    if (!it.hasNext()) {
        throw new CodecException("There must be at least one entry present!");
    }
    while (it.hasNext()) {
        final Entry entry = it.next();
        final ByteBuffer buf = context.byteBufAlloc().buffer();
        buf.writeByte((byte) CodecPlayInOutCustomPayload.FML_HANDSHAKE_REGISTRY_DATA);
        buf.writeBoolean(it.hasNext());
        buf.writeString(entry.getName());
        final Map<String, Integer> ids = entry.getIds();
        buf.writeVarInt(ids.size());
        for (Map.Entry<String, Integer> en : ids.entrySet()) {
            buf.writeString(en.getKey());
            buf.writeVarInt(en.getValue());
        }
        final List<String> substitutions = entry.getSubstitutions();
        buf.writeVarInt(substitutions.size());
        substitutions.forEach(buf::writeString);
        output.add(new MessagePlayInOutChannelPayload("FML|HS", buf));
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:ProcessorForgeHandshakeOutRegistryData.java

示例8: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutSpawnParticle message) throws CodecException {
    Vector3f position = message.getPosition();
    Vector3f offset = message.getOffset();
    int[] extra = message.getExtra();
    ByteBuffer buf = context.byteBufAlloc().buffer(BASE_LENGTH);
    buf.writeInteger(message.getParticleId());
    buf.writeBoolean(message.isLongDistance());
    buf.writeFloat(position.getX());
    buf.writeFloat(position.getY());
    buf.writeFloat(position.getZ());
    buf.writeFloat(offset.getX());
    buf.writeFloat(offset.getY());
    buf.writeFloat(offset.getZ());
    buf.writeFloat(message.getData());
    buf.writeInteger(message.getCount());
    for (int value : extra) {
        buf.writeVarInt(value);
    }
    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:22,代码来源:CodecPlayOutSpawnParticle.java

示例9: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutPlayerJoinGame message) throws CodecException {
    context.getChannel().attr(PLAYER_ENTITY_ID).set(message.getEntityId());
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    buf.writeInteger(message.getEntityId());
    byte gameMode = (byte) message.getGameMode().getInternalId();
    if (message.isHardcore()) {
        gameMode |= 0x8;
    }
    buf.writeByte(gameMode);
    buf.writeInteger(message.getDimensionType().getInternalId());
    buf.writeByte((byte) message.getDifficulty().getInternalId());
    buf.writeByte((byte) Math.min(message.getPlayerListSize(), 255));
    buf.writeString(message.isLowHorizon() ? "flat" : "default");
    buf.writeBoolean(message.getReducedDebug());
    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:CodecPlayOutPlayerJoinGame.java

示例10: readLimitedDataView

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Nullable
@Override
public DataView readLimitedDataView(int maximumDepth, int maxBytes) {
    final int index = this.buf.readerIndex();
    if (this.buf.readByte() == 0) {
        return null;
    }
    this.buf.readerIndex(index);
    try {
        try (NbtDataContainerInputStream input = new NbtDataContainerInputStream(
                new LimitInputStream(new ByteBufInputStream(this.buf), maxBytes), false, maximumDepth)) {
            return input.read();
        }
    } catch (IOException e) {
        throw new CodecException(e);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:LanternByteBuffer.java

示例11: process

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public void process(CodecContext context, MessagePlayOutTabListEntries message, List<Message> output) throws CodecException {
    final Multimap<Class<?>, Entry> entriesByType = HashMultimap.create();
    for (Entry entry : message.getEntries()) {
        entriesByType.put(entry.getClass(), entry);
    }
    if (entriesByType.isEmpty()) {
        return;
    }
    if (entriesByType.keySet().size() == 1) {
        output.add(message);
    } else {
        for (java.util.Map.Entry<Class<?>, Collection<Entry>> en : entriesByType.asMap().entrySet()) {
            output.add(new MessagePlayOutTabListEntries(en.getValue()));
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:ProcessorPlayOutTabListEntries.java

示例12: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, MessageLoginOutEncryptionRequest message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();

    byte[] publicKey = message.getPublicKey();
    byte[] verifyToken = message.getVerifyToken();

    buf.writeString(message.getSessionId());

    // Write the public key
    buf.writeByteArray(publicKey);
    // Write the verify token
    buf.writeByteArray(verifyToken);

    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:CodecLoginOutEncryptionRequest.java

示例13: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTitle message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    if (message instanceof MessagePlayOutTitle.Clear) {
        buf.writeVarInt(CLEAR);
    } else if (message instanceof MessagePlayOutTitle.Reset) {
        buf.writeVarInt(RESET);
    } else if (message instanceof MessagePlayOutTitle.SetTitle) {
        buf.writeVarInt(SET_TITLE);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetTitle) message).getTitle());
    } else if (message instanceof MessagePlayOutTitle.SetSubtitle) {
        buf.writeVarInt(SET_SUBTITLE);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetSubtitle) message).getTitle());
    } else if (message instanceof MessagePlayOutTitle.SetActionbarTitle) {
        buf.writeVarInt(SET_ACTIONBAR_TITLE);
        buf.write(Types.LOCALIZED_TEXT, ((MessagePlayOutTitle.SetActionbarTitle) message).getTitle());
    } else {
        final MessagePlayOutTitle.SetTimes message0 = (MessagePlayOutTitle.SetTimes) message;
        buf.writeVarInt(SET_TIMES);
        buf.writeInteger(message0.getFadeIn());
        buf.writeInteger(message0.getStay());
        buf.writeInteger(message0.getFadeOut());
    }
    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:26,代码来源:CodecPlayOutTitle.java

示例14: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutUnlockRecipes message) throws CodecException {
    final ByteBuffer buf = context.byteBufAlloc().buffer();
    if (message instanceof MessagePlayOutUnlockRecipes.Remove) {
        buf.writeVarInt((short) 2);
    } else if (message instanceof MessagePlayOutUnlockRecipes.Add) {
        buf.writeVarInt((short) 1);
    } else if (message instanceof MessagePlayOutUnlockRecipes.Init) {
        buf.writeVarInt((short) 0);
    } else {
        throw new EncoderException();
    }
    buf.writeBoolean(message.hasOpenCraftingBook());
    buf.writeBoolean(message.hasCraftingFilter());
    IntList recipeIds = message.getRecipeIds();
    buf.writeVarInt(recipeIds.size());
    recipeIds.forEach(buf::writeVarInt);
    if (message instanceof MessagePlayOutUnlockRecipes.Init) {
        recipeIds = ((MessagePlayOutUnlockRecipes.Init) message).getRecipeIdsToBeDisplayed();
        buf.writeVarInt(recipeIds.size());
        recipeIds.forEach(buf::writeVarInt);
    }
    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:CodecPlayOutUnlockRecipes.java

示例15: encode

import io.netty.handler.codec.CodecException; //导入依赖的package包/类
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTabListHeaderAndFooter message) throws CodecException {
    ByteBuffer buf = context.byteBufAlloc().buffer();
    Text header = message.getHeader();
    Text footer = message.getFooter();
    if (header != null) {
        buf.write(Types.TEXT, header);
    } else {
        buf.writeString(EMPTY_TEXT);
    }
    if (footer != null) {
        buf.write(Types.TEXT, footer);
    } else {
        buf.writeString(EMPTY_TEXT);
    }
    return buf;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:CodecPlayOutTabListHeaderAndFooter.java


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