@Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof ByteBufHolder) { return data.equals(((ByteBufHolder) o).content()); } return false; }
private void releaseCurrentMessage() { if (currentMessage != null) { currentMessage.release(); currentMessage = null; handlingOversizedMessage = false; } } }
private static Object safeDuplicate(Object message) { if (message instanceof ByteBuf) { return ((ByteBuf) message).retainedDuplicate(); } else if (message instanceof ByteBufHolder) { return ((ByteBufHolder) message).retainedDuplicate(); } else { return ReferenceCountUtil.retain(message); } }
handlingOversizedMessage = false; if (currentMessage != null) { currentMessage.release(); currentMessage = null; throw new MessageAggregationException(); O aggregated; if (m instanceof ByteBufHolder) { aggregated = beginAggregation(m, ((ByteBufHolder) m).content().retain()); } else { aggregated = beginAggregation(m, EMPTY_BUFFER); appendPartialContent(content, ((ByteBufHolder) m).content()); CompositeByteBuf content = (CompositeByteBuf) currentMessage.content(); if (content.readableBytes() > maxContentLength - m.content().readableBytes()) { appendPartialContent(content, m.content());
/** * Generates the default log message of the specified event whose argument is a {@link ByteBufHolder}. */ private static String formatByteBufHolder(ChannelHandlerContext ctx, String eventName, ByteBufHolder msg) { String chStr = ctx.channel().toString(); String msgStr = msg.toString(); ByteBuf content = msg.content(); int length = content.readableBytes(); if (length == 0) { StringBuilder buf = new StringBuilder(chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 4); buf.append(chStr).append(' ').append(eventName).append(", ").append(msgStr).append(", 0B"); return buf.toString(); } else { int rows = length / 16 + (length % 15 == 0? 0 : 1) + 4; StringBuilder buf = new StringBuilder( chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 2 + 10 + 1 + 2 + rows * 80); buf.append(chStr).append(' ').append(eventName).append(": ") .append(msgStr).append(", ").append(length).append('B').append(NEWLINE); appendPrettyHexDump(buf, content); return buf.toString(); } }
@Override public int size(Object msg) { if (msg instanceof ByteBuf) { return ((ByteBuf) msg).readableBytes(); } if (msg instanceof ByteBufHolder) { return ((ByteBufHolder) msg).content().readableBytes(); } if (msg instanceof FileRegion) { return 0; } return unknownSize; } }
/** * Calculate the size of the given {@link Object}. * * This implementation supports {@link ByteBuf} and {@link ByteBufHolder}. Sub-classes may override this. * @param msg the msg for which the size should be calculated. * @return size the size of the msg or {@code -1} if unknown. */ protected long calculateSize(Object msg) { if (msg instanceof ByteBuf) { return ((ByteBuf) msg).readableBytes(); } if (msg instanceof ByteBufHolder) { return ((ByteBufHolder) msg).content().readableBytes(); } return -1; } }
private static long total(Object msg) { if (msg instanceof ByteBuf) { return ((ByteBuf) msg).readableBytes(); } if (msg instanceof FileRegion) { return ((FileRegion) msg).count(); } if (msg instanceof ByteBufHolder) { return ((ByteBufHolder) msg).content().readableBytes(); } return -1; }
private static Map<String, String> buildAliasMap(DnsResponse response) { final int answerCount = response.count(DnsSection.ANSWER); Map<String, String> cnames = null; for (int i = 0; i < answerCount; i ++) { final DnsRecord r = response.recordAt(DnsSection.ANSWER, i); final DnsRecordType type = r.type(); if (type != DnsRecordType.CNAME) { continue; } if (!(r instanceof DnsRawRecord)) { continue; } final ByteBuf recordContent = ((ByteBufHolder) r).content(); final String domainName = decodeDomainName(recordContent); if (domainName == null) { continue; } if (cnames == null) { cnames = new HashMap<String, String>(min(8, answerCount)); } cnames.put(r.name().toLowerCase(Locale.US), domainName.toLowerCase(Locale.US)); } return cnames != null? cnames : Collections.<String, String>emptyMap(); }
private InetAddress parseAddress(DnsRecord r, String name) { if (!(r instanceof DnsRawRecord)) { return null; } final ByteBuf content = ((ByteBufHolder) r).content(); final int contentLen = content.readableBytes(); if (contentLen != INADDRSZ4 && contentLen != INADDRSZ6) { return null; } final byte[] addrBytes = new byte[contentLen]; content.getBytes(content.readerIndex(), addrBytes); try { return InetAddress.getByAddress( parent.isDecodeIdn() ? IDN.toUnicode(name) : name, addrBytes); } catch (UnknownHostException e) { // Should never reach here. throw new Error(e); } }
final ByteBuf recordContent = ((ByteBufHolder) r).content(); final String domainName = decodeDomainName(recordContent); if (domainName == null) {
if (!((ByteBufHolder) res).content().isReadable()) { out.add(ReferenceCountUtil.retain(res)); break;