本文整理汇总了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 ();
}
示例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 ) );
}
示例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 };
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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()));
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}