code
stringlengths
146
466k
prompt
stringlengths
54
1.5k
Of course, here is the Java code you requested: ```java @SuppressWarnings({ "unchecked", "deprecation" }) public B channelFactory(io.netty.channel.ChannelFactory<? extends C> channelFactory) { return channelFactory((ChannelFactory<C>) channelFactory); } ``` Hope this helps!
Create a Java method that does the following: "A convenience method for creating a new instance of the class.".
Of course, here is the Java code you requested: ```java public <T> B attr(AttributeKey<T> key, T value) { if (key == null) { throw new NullPointerException("key"); } if (value == null) { synchronized (attrs) { attrs.remove(key); } } el...
Create a Java method that does the following: "A method to add an attribute to the attribute set.".
Of course, here is the Java code you requested: ```java public ChannelFuture bind() { validate(); SocketAddress localAddress = this.localAddress; if (localAddress == null) { throw new IllegalStateException("localAddress not set"); } return doBind(localAddress); }...
Create a Java method that does the following: "Bind to the local address.".
Of course, here is the Java code you requested: ```java public ChannelFuture bind(String inetHost, int inetPort) { return bind(SocketUtils.socketAddress(inetHost, inetPort)); } ``` Hope this helps!
Create a Java method that does the following: "Binds the socket to the specified host and port.".
Of course, here is the Java code you requested: ```java public ChannelFuture bind(SocketAddress localAddress) { validate(); if (localAddress == null) { throw new NullPointerException("localAddress"); } return doBind(localAddress); } ``` Hope this helps!
Create a Java method that does the following: "Bind to the specified local address.".
Of course, here is the Java code you requested: ```java public B handler(ChannelHandler handler) { if (handler == null) { throw new NullPointerException("handler"); } this.handler = handler; return self(); } ``` Hope this helps!
Create a Java method that does the following: "Sets the channel handler.".
Of course, here is the Java code you requested: ```java static void encodeLiteral(ByteBuf in, ByteBuf out, int length) { if (length < 61) { out.writeByte(length - 1 << 2); } else { int bitLength = bitsToEncode(length - 1); int bytesToEncode = 1 + bitLength / 8; ...
Create a Java method that does the following: "Encode a literal in a UTF - 8 encoded string.".
Of course, here is the Java code you requested: ```java private static int readPreamble(ByteBuf in) { int length = 0; int byteIndex = 0; while (in.isReadable()) { int current = in.readUnsignedByte(); length |= (current & 0x7f) << byteIndex++ * 7; if ((current...
Create a Java method that does the following: "Read the entire page of a record header.".
Of course, here is the Java code you requested: ```java private static int decodeCopyWith1ByteOffset(byte tag, ByteBuf in, ByteBuf out, int writtenSoFar) { if (!in.isReadable()) { return NOT_ENOUGH_INPUT; } int initialIndex = out.writerIndex(); int length = 4 + ((tag & 0x01...
Create a Java method that does the following: "Decodes a copy with 1 byte offset.".
Of course, here is the Java code you requested: ```java private static void validateOffset(int offset, int chunkSizeSoFar) { if (offset == 0) { throw new DecompressionException("Offset is less than minimum permissible value"); } if (offset < 0) { // Due to arithmetic ov...
Create a Java method that does the following: "Validate the offset.".
Of course, here is the Java code you requested: ```java static int calculateChecksum(ByteBuf data, int offset, int length) { Crc32c crc32 = new Crc32c(); try { crc32.update(data, offset, length); return maskChecksum((int) crc32.getValue()); } finally { crc32....
Create a Java method that does the following: "Calculate the checksum of the given data.".
Of course, here is the Java code you requested: ```java static void validateChecksum(int expectedChecksum, ByteBuf data) { validateChecksum(expectedChecksum, data, data.readerIndex(), data.readableBytes()); } ``` Hope this helps!
Create a Java method that does the following: "Validate the checksum of the given data.".
Of course, here is the Java code you requested: ```java public EpollDatagramChannelConfig setReusePort(boolean reusePort) { try { ((EpollDatagramChannel) channel).socket.setReusePort(reusePort); return this; } catch (IOException e) { throw new ChannelException(e); ...
Create a Java method that does the following: "Sets whether the socket should be used to reuse the port.".
Of course, here is the Java code you requested: ```java public EpollDatagramChannelConfig setIpTransparent(boolean ipTransparent) { try { ((EpollDatagramChannel) channel).socket.setIpTransparent(ipTransparent); return this; } catch (IOException e) { throw new Channel...
Create a Java method that does the following: "Sets the ipTransparent flag.".
Of course, here is the Java code you requested: ```java static boolean isJ2OCached(String key, String value) { return value.equals(j2o.get(key)); } ``` Hope this helps!
Create a Java method that does the following: "Checks if the value is the same as the one in the cache.".
Of course, here is the Java code you requested: ```java static boolean isO2JCached(String key, String protocol, String value) { Map<String, String> p2j = o2j.get(key); if (p2j == null) { return false; } else { return value.equals(p2j.get(protocol)); } } ``` ...
Create a Java method that does the following: "Is O2J cached?".
Of course, here is the Java code you requested: ```java static String toOpenSsl(String javaCipherSuite, boolean boringSSL) { String converted = j2o.get(javaCipherSuite); if (converted != null) { return converted; } return cacheFromJava(javaCipherSuite, boringSSL); } ``` ...
Create a Java method that does the following: "Converts a javaCipherSuite to an open SSL string.".
Of course, here is the Java code you requested: ```java static String toJava(String openSslCipherSuite, String protocol) { Map<String, String> p2j = o2j.get(openSslCipherSuite); if (p2j == null) { p2j = cacheFromOpenSsl(openSslCipherSuite); // This may happen if this method is q...
Create a Java method that does the following: "Returns the Java cipher suite for the given OpenSSL cipher suite and protocol.".
Of course, here is the Java code you requested: ```java static void convertToCipherStrings(Iterable<String> cipherSuites, StringBuilder cipherBuilder, StringBuilder cipherTLSv13Builder, boolean boringSSL) { for (String c: cipherSuites) { if (c == null) { ...
Create a Java method that does the following: "Convert to cipher strings.".
Of course, here is the Java code you requested: ```java @UnstableApi public final void executeAfterEventLoopIteration(Runnable task) { ObjectUtil.checkNotNull(task, "task"); if (isShutdown()) { reject(); } if (!tailTasks.offer(task)) { reject(task); ...
Create a Java method that does the following: "Execute after event loop iteration.".
Of course, here is the Java code you requested: ```java protected void interruptThread() { Thread currentThread = thread; if (currentThread == null) { interrupted = true; } else { currentThread.interrupt(); } } ``` Hope this helps!
Create a Java method that does the following: "Interrupt the current thread.".
Of course, here is the Java code you requested: ```java protected Runnable takeTask() { assert inEventLoop(); if (!(taskQueue instanceof BlockingQueue)) { throw new UnsupportedOperationException(); } BlockingQueue<Runnable> taskQueue = (BlockingQueue<Runnable>) this.taskQue...
Create a Java method that does the following: "This method is called by the event loop to get a Runnable from the scheduled tasks.".
Of course, here is the Java code you requested: ```java protected void addTask(Runnable task) { if (task == null) { throw new NullPointerException("task"); } if (!offerTask(task)) { reject(task); } } ``` Hope this helps!
Create a Java method that does the following: "Add a task to the queue.".
Of course, here is the Java code you requested: ```java protected boolean runAllTasks() { assert inEventLoop(); boolean fetchedAll; boolean ranAtLeastOne = false; do { fetchedAll = fetchFromScheduledTaskQueue(); if (runAllTasksFrom(taskQueue)) { ...
Create a Java method that does the following: "Run all scheduled tasks.".
Of course, here is the Java code you requested: ```java protected final boolean runAllTasksFrom(Queue<Runnable> taskQueue) { Runnable task = pollTaskFrom(taskQueue); if (task == null) { return false; } for (;;) { safeExecute(task); task = pollTaskFrom...
Create a Java method that does the following: "Run all tasks from the given queue.".
Of course, here is the Java code you requested: ```java protected boolean runAllTasks(long timeoutNanos) { fetchFromScheduledTaskQueue(); Runnable task = pollTask(); if (task == null) { afterRunningAllTasks(); return false; } final long deadline = Schedu...
Create a Java method that does the following: "Run all tasks in the scheduled task queue.".
Of course, here is the Java code you requested: ```java public void addShutdownHook(final Runnable task) { if (inEventLoop()) { shutdownHooks.add(task); } else { execute(new Runnable() { @Override public void run() { shutdownHo...
Create a Java method that does the following: "Add a shutdown hook to the Runnable.".
Of course, here is the Java code you requested: ```java protected boolean confirmShutdown() { if (!isShuttingDown()) { return false; } if (!inEventLoop()) { throw new IllegalStateException("must be invoked from an event loop"); } cancelScheduledTasks();...
Create a Java method that does the following: "Confirm shutdown.".
Of course, here is the Java code you requested: ```java boolean add(DatagramPacket packet) { if (count == packets.length) { // We already filled up to UIO_MAX_IOV messages. This is the max allowed per sendmmsg(...) call, we will // try again later. return false; } ...
Create a Java method that does the following: "Add a new packet to the end of the list.".
Of course, here is the Java code you requested: ```java void writeUnary(ByteBuf out, int value) { if (value < 0) { throw new IllegalArgumentException("value: " + value + " (expected 0 or more)"); } while (value-- > 0) { writeBoolean(out, true); } writeBoo...
Create a Java method that does the following: "Write a single unary integer to the given byte buffer.".
Of course, here is the Java code you requested: ```java void flush(ByteBuf out) { final int bitCount = this.bitCount; if (bitCount > 0) { final long bitBuffer = this.bitBuffer; final int shiftToRight = 64 - bitCount; if (bitCount <= 8) { out.writeBy...
Create a Java method that does the following: "Flushes the buffer to the output.".
Of course, here is the Java code you requested: ```java private void encodeHeader(ByteBuf out, CharSequence name, CharSequence value, boolean sensitive, long headerSize) { // If the header value is sensitive then it must never be indexed if (sensitive) { int nameIndex = getNameIndex(name); ...
Create a Java method that does the following: "Encode a single header.".
Of course, here is the Java code you requested: ```java private static void encodeInteger(ByteBuf out, int mask, int n, int i) { encodeInteger(out, mask, n, (long) i); } ``` Hope this helps!
Create a Java method that does the following: "Encode a single integer into the buffer.".
Of course, here is the Java code you requested: ```java private void encodeStringLiteral(ByteBuf out, CharSequence string) { int huffmanLength = hpackHuffmanEncoder.getEncodedLength(string); if (huffmanLength < string.length()) { encodeInteger(out, 0x80, 7, huffmanLength); hpack...
Create a Java method that does the following: "Encode a string in UTF - 8 format.".
Of course, here is the Java code you requested: ```java private HeaderEntry getEntry(CharSequence name, CharSequence value) { if (length() == 0 || name == null || value == null) { return null; } int h = AsciiString.hashCode(name); int i = index(h); for (HeaderEntry e...
Create a Java method that does the following: "Gets the entry for the given name and value.".
Of course, here is the Java code you requested: ```java private void add(CharSequence name, CharSequence value, long headerSize) { // Clear the table if the header field size is larger than the maxHeaderTableSize. if (headerSize > maxHeaderTableSize) { clear(); return; }...
Create a Java method that does the following: "Add a new entry to the header table.".
Of course, here is the Java code you requested: ```java public static boolean isCipherSuiteAvailable(String cipherSuite) { String converted = CipherSuiteConverter.toOpenSsl(cipherSuite, IS_BORINGSSL); if (converted != null) { cipherSuite = converted; } return AVAILABLE_OPENS...
Create a Java method that does the following: "Check if the specified cipher suite is available in the OpenSSL library.".
Of course, here is the Java code you requested: ```java protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { if (discardingTooLongFrame) { discardingTooLongFrame(in); } if (in.readableBytes() < lengthFieldEndOffset) { return null; } ...
Create a Java method that does the following: "Decode a single frame from the input buffer.".
Of course, here is the Java code you requested: ```java protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) { return buffer.retainedSlice(index, length); } ``` Hope this helps!
Create a Java method that does the following: "Extract a frame from the buffer.".
Of course, here is the Java code you requested: ```java public String encode(Cookie cookie) { final String name = checkNotNull(cookie, "cookie").name(); final String value = cookie.value() != null ? cookie.value() : ""; validateCookie(name, value); StringBuilder buf = stringBuilder();...
Create a Java method that does the following: "Encode a Cookie object into a String.".
Of course, here is the Java code you requested: ```java public List<String> encode(Collection<? extends Cookie> cookies) { if (checkNotNull(cookies, "cookies").isEmpty()) { return Collections.emptyList(); } List<String> encoded = new ArrayList<String>(cookies.size()); Map<S...
Create a Java method that does the following: "Encode a collection of cookies into a list of strings.".
Of course, here is the Java code you requested: ```java public List<String> encode(Iterable<? extends Cookie> cookies) { Iterator<? extends Cookie> cookiesIt = checkNotNull(cookies, "cookies").iterator(); if (!cookiesIt.hasNext()) { return Collections.emptyList(); } List<St...
Create a Java method that does the following: "Encode a collection of cookies into a list of strings.".
Of course, here is the Java code you requested: ```java @Override public void trace(String msg, Throwable t) { logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msg, t); } ``` Hope this helps!
Create a Java method that does the following: "Log a message at the TRACE level.".
Of course, here is the Java code you requested: ```java public static SslContextBuilder forServer( File keyCertChainFile, File keyFile, String keyPassword) { return new SslContextBuilder(true).keyManager(keyCertChainFile, keyFile, keyPassword); } ``` Hope this helps!
Create a Java method that does the following: "Create a SslContextBuilder for a server using the specified key certificates.".
Of course, here is the Java code you requested: ```java public static SslContextBuilder forServer( InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword) { return new SslContextBuilder(true).keyManager(keyCertChainInputStream, keyInputStream, keyPassword); } ``` H...
Create a Java method that does the following: "Create a SslContextBuilder for a server using the specified key certificates.".
Of course, here is the Java code you requested: ```java public SslContextBuilder trustManager(File trustCertCollectionFile) { try { return trustManager(SslContext.toX509Certificates(trustCertCollectionFile)); } catch (Exception e) { throw new IllegalArgumentException("File does ...
Create a Java method that does the following: "Create a SslContextBuilder using the specified trust certificate collection file.".
Of course, here is the Java code you requested: ```java public SslContextBuilder trustManager(X509Certificate... trustCertCollection) { this.trustCertCollection = trustCertCollection != null ? trustCertCollection.clone() : null; trustManagerFactory = null; return this; } ``` Hope this help...
Create a Java method that does the following: "Set the trust manager certificate collection.".
Of course, here is the Java code you requested: ```java public SslContextBuilder keyManager(File keyCertChainFile, File keyFile) { return keyManager(keyCertChainFile, keyFile, null); } ``` Hope this helps!
Create a Java method that does the following: "Set the key manager.".
Of course, here is the Java code you requested: ```java public SslContextBuilder keyManager(InputStream keyCertChainInputStream, InputStream keyInputStream, String keyPassword) { X509Certificate[] keyCertChain; PrivateKey key; try { keyCertChain = SslContext.toX509Certif...
Create a Java method that does the following: "Key manager method.".
Of course, here is the Java code you requested: ```java public SslContextBuilder protocols(String... protocols) { this.protocols = protocols == null ? null : protocols.clone(); return this; } ``` Hope this helps!
Create a Java method that does the following: "Set the protocols to use for this SslContext.".
Of course, here is the Java code you requested: ```java public SslContext build() throws SSLException { if (forServer) { return SslContext.newServerContextInternal(provider, sslContextProvider, trustCertCollection, trustManagerFactory, keyCertChain, key, keyPassword, keyManagerFacto...
Create a Java method that does the following: "Build the SslContext.".
Of course, here is the Java code you requested: ```java private int distributeToChildren(int maxBytes, Writer writer, State state) throws Http2Exception { long oldTotalQueuedWeights = state.totalQueuedWeights; State childState = state.pollPseudoTimeQueue(); State nextChildState = state.peekPseu...
Create a Java method that does the following: "Distribute to children.".
Of course, here is the Java code you requested: ```java int numChildren(int streamId) { State state = state(streamId); return state == null ? 0 : state.children.size(); } ``` Hope this helps!
Create a Java method that does the following: "Returns number of children of a given stream.".
Of course, here is the Java code you requested: ```java void notifyParentChanged(List<ParentChangedEvent> events) { for (int i = 0; i < events.size(); ++i) { ParentChangedEvent event = events.get(i); stateOnlyRemovalQueue.priorityChanged(event.state); if (event.state.parent ...
Create a Java method that does the following: "Notify parent changed.".
Of course, here is the Java code you requested: ```java public int length() { int length; if (head < tail) { length = hpackHeaderFields.length - tail + head; } else { length = head - tail; } return length; } ``` Hope this helps!
Create a Java method that does the following: "Returns the length of the record.".
Of course, here is the Java code you requested: ```java public HpackHeaderField getEntry(int index) { if (index <= 0 || index > length()) { throw new IndexOutOfBoundsException(); } int i = head - index; if (i < 0) { return hpackHeaderFields[i + hpackHeaderFields....
Create a Java method that does the following: "Gets the entry at the specified index in the HpackHeader.".
Of course, here is the Java code you requested: ```java public void add(HpackHeaderField header) { int headerSize = header.size(); if (headerSize > capacity) { clear(); return; } while (capacity - size < headerSize) { remove(); } hpack...
Create a Java method that does the following: "Add a new HpackHeaderField to the set.".
Of course, here is the Java code you requested: ```java public HpackHeaderField remove() { HpackHeaderField removed = hpackHeaderFields[tail]; if (removed == null) { return null; } size -= removed.size(); hpackHeaderFields[tail++] = null; if (tail == hpackHea...
Create a Java method that does the following: "Removes the first instance of the HpackHeaderField from this array.".
Of course, here is the Java code you requested: ```java public void clear() { while (tail != head) { hpackHeaderFields[tail++] = null; if (tail == hpackHeaderFields.length) { tail = 0; } } head = 0; tail = 0; size = 0; } ``...
Create a Java method that does the following: "Clear the array of all the records in this record.".
Of course, here is the Java code you requested: ```java public final ChannelFuture spliceTo(final AbstractEpollStreamChannel ch, final int len, final ChannelPromise promise) { if (ch.eventLoop() != eventLoop()) { throw new IllegalArgumentException("EventLoops...
Create a Java method that does the following: "Splice the given channel to the given length.".
Of course, here is the Java code you requested: ```java private int writeDefaultFileRegion(ChannelOutboundBuffer in, DefaultFileRegion region) throws Exception { final long offset = region.transferred(); final long regionCount = region.count(); if (offset >= regionCount) { in.remove...
Create a Java method that does the following: "Write a DefaultFileRegion to the socket.".
Of course, here is the Java code you requested: ```java protected int doWriteSingle(ChannelOutboundBuffer in) throws Exception { // The outbound buffer contains only one message or it contains a file region. Object msg = in.current(); if (msg instanceof ByteBuf) { return writeBytes(...
Create a Java method that does the following: "Write a single message to the outbound buffer.".
Of course, here is the Java code you requested: ```java private void setUpgradeRequestHeaders(ChannelHandlerContext ctx, HttpRequest request) { // Set the UPGRADE header on the request. request.headers().set(HttpHeaderNames.UPGRADE, upgradeCodec.protocol()); // Add all protocol-specific header...
Create a Java method that does the following: "Set the UPGRADE and CONNECTION headers on the request.".
Of course, here is the Java code you requested: ```java private void sendNotModified(ChannelHandlerContext ctx) { FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED); setDateHeader(response); this.sendAndCleanupConnection(ctx, response); } ``` Hope this helps!
Create a Java method that does the following: "Sends a 304 Not Modified response.".
Of course, here is the Java code you requested: ```java private void sendAndCleanupConnection(ChannelHandlerContext ctx, FullHttpResponse response) { final FullHttpRequest request = this.request; final boolean keepAlive = HttpUtil.isKeepAlive(request); HttpUtil.setContentLength(response, respon...
Create a Java method that does the following: "Send and cleanup connection.".
Of course, here is the Java code you requested: ```java private static void setContentTypeHeader(HttpResponse response, File file) { MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeTypesMap.getContentType(file.getPath())); } `...
Create a Java method that does the following: "Sets the content type header.".
Of course, here is the Java code you requested: ```java private EmbeddedChannel newCompressor(ChannelHandlerContext ctx, Http2Headers headers, boolean endOfStream) throws Http2Exception { if (endOfStream) { return null; } CharSequence encoding = headers.get(CONTENT_ENCO...
Create a Java method that does the following: "Create a new compressor for the given headers.".
Of course, here is the Java code you requested: ```java public static void loadLibrary(String libName, boolean absolute) { if (absolute) { System.load(libName); } else { System.loadLibrary(libName); } } ``` Hope this helps!
Create a Java method that does the following: "Load the class file.".
Of course, here is the Java code you requested: ```java protected ByteBuf allocateBuffer( ChannelHandlerContext ctx, @SuppressWarnings("unused") AddressedEnvelope<DnsResponse, InetSocketAddress> msg) throws Exception { return ctx.alloc().ioBuffer(1024); } ``` Hope this helps!
Create a Java method that does the following: "Allocate a buffer for a single record.".
Of course, here is the Java code you requested: ```java private static void encodeHeader(DnsResponse response, ByteBuf buf) { buf.writeShort(response.id()); int flags = 32768; flags |= (response.opCode().byteValue() & 0xFF) << 11; if (response.isAuthoritativeAnswer()) { flag...
Create a Java method that does the following: "Encode the header of a DNS response.".
Of course, here is the Java code you requested: ```java protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { final int eol = findEndOfLine(buffer); if (!discarding) { if (eol >= 0) { final ByteBuf frame; final int length = eol...
Create a Java method that does the following: "Decodes the message.".
Of course, here is the Java code you requested: ```java public boolean isSharable() { /** * Cache the result of {@link Sharable} annotation detection to workaround a condition. We use a * {@link ThreadLocal} and {@link WeakHashMap} to eliminate the volatile write/reads. Using different ...
Create a Java method that does the following: "Returns true if the class is a Sharable class.".
Of course, here is the Java code you requested: ```java private static MqttFixedHeader decodeFixedHeader(ByteBuf buffer) { short b1 = buffer.readUnsignedByte(); MqttMessageType messageType = MqttMessageType.valueOf(b1 >> 4); boolean dupFlag = (b1 & 0x08) == 0x08; int qosLevel = (b1 & 0...
Create a Java method that does the following: "Decodes a fixed header from the buffer.".
Of course, here is the Java code you requested: ```java public final ByteBuf remove(ByteBufAllocator alloc, int bytes, ChannelPromise aggregatePromise) { checkPositiveOrZero(bytes, "bytes"); checkNotNull(aggregatePromise, "aggregatePromise"); // Use isEmpty rather than readableBytes==0 as we m...
Create a Java method that does the following: "Removes the specified number of bytes from this buffer.".
Of course, here is the Java code you requested: ```java protected final ByteBuf copyAndCompose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) { ByteBuf newCumulation = alloc.ioBuffer(cumulation.readableBytes() + next.readableBytes()); try { newCumulation.writeBytes(cumulation).wr...
Create a Java method that does the following: "Copy and compose.".
Of course, here is the Java code you requested: ```java private static void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) throws Exception { if (headers.isEndStream()) { ByteBuf content = ctx.alloc().buffer(); content.writeBytes(RESPONSE_BYTES.duplicate...
Create a Java method that does the following: "On headers read.".
Of course, here is the Java code you requested: ```java private static void sendResponse(ChannelHandlerContext ctx, ByteBuf payload) { // Send a frame for the response status Http2Headers headers = new DefaultHttp2Headers().status(OK.codeAsText()); ctx.write(new DefaultHttp2HeadersFrame(headers...
Create a Java method that does the following: "Send a response frame to the client.".
Of course, here is the Java code you requested: ```java final int calculateOutNetBufSize(int plaintextBytes, int numBuffers) { // Assuming a max of one frame per component in a composite buffer. long maxOverhead = (long) Conscrypt.maxSealOverhead(getWrappedEngine()) * numBuffers; // TODO(nmittl...
Create a Java method that does the following: "Calculate the size of the output net buffer.".
Of course, here is the Java code you requested: ```java private static int findEndOfHeader(final ByteBuf buffer) { final int n = buffer.readableBytes(); // per spec, the 15th and 16th bytes contain the address length in bytes if (n < 16) { return -1; } int offset =...
Create a Java method that does the following: "Find the end of the header.".
Of course, here is the Java code you requested: ```java private static int findEndOfLine(final ByteBuf buffer) { final int n = buffer.writerIndex(); for (int i = buffer.readerIndex(); i < n; i++) { final byte b = buffer.getByte(i); if (b == '\r' && i < n - 1 && buffer.getByte(i ...
Create a Java method that does the following: "Find the end of line.".
Of course, here is the Java code you requested: ```java private ByteBuf decodeStruct(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { final int eoh = findEndOfHeader(buffer); if (!discarding) { if (eoh >= 0) { final int length = eoh - buffer.readerIndex(); ...
Create a Java method that does the following: "Decode a single struct from the buffer.".
Of course, here is the Java code you requested: ```java public static ProtocolDetectionResult<HAProxyProtocolVersion> detectProtocol(ByteBuf buffer) { if (buffer.readableBytes() < 12) { return ProtocolDetectionResult.needsMoreData(); } int idx = buffer.readerIndex(); if (m...
Create a Java method that does the following: "Detect protocol from buffer.".
Of course, here is the Java code you requested: ```java public EpollTcpInfo tcpInfo(EpollTcpInfo info) { try { socket.getTcpInfo(info); return info; } catch (IOException e) { throw new ChannelException(e); } } ``` Hope this helps!
Create a Java method that does the following: "Get the tcp info.".
Of course, here is the Java code you requested: ```java void createGlobalTrafficCounter(ScheduledExecutorService executor) { // Default setMaxDeviation(DEFAULT_DEVIATION, DEFAULT_SLOWDOWN, DEFAULT_ACCELERATION); if (executor == null) { throw new IllegalArgumentException("Executor mu...
Create a Java method that does the following: "Create a TrafficCounter object and start it.".
Of course, here is the Java code you requested: ```java public Collection<TrafficCounter> channelTrafficCounters() { return new AbstractCollection<TrafficCounter>() { @Override public Iterator<TrafficCounter> iterator() { return new Iterator<TrafficCounter>() { ...
Create a Java method that does the following: "Returns a collection of traffic counters for all channels.".
Of course, here is the Java code you requested: ```java int readBits(final int count) { if (count < 0 || count > 32) { throw new IllegalArgumentException("count: " + count + " (expected: 0-32 )"); } int bitCount = this.bitCount; long bitBuffer = this.bitBuffer; if (...
Create a Java method that does the following: "Read bits from the input stream.".
Of course, here is the Java code you requested: ```java boolean hasReadableBytes(int count) { if (count < 0 || count > MAX_COUNT_OF_READABLE_BYTES) { throw new IllegalArgumentException("count: " + count + " (expected: 0-" + MAX_COUNT_OF_READABLE_BYTES + ')'); } r...
Create a Java method that does the following: "Check if a byte array contains readable bytes.".
Of course, here is the Java code you requested: ```java private static int parseCode(ByteBuf buffer) { final int first = parseNumber(buffer.readByte()) * 100; final int second = parseNumber(buffer.readByte()) * 10; final int third = parseNumber(buffer.readByte()); return first + second ...
Create a Java method that does the following: "Parse a code from the buffer.".
Of course, here is the Java code you requested: ```java public String substring(int start, int end) { int length = end - start; if (start > pos || length > pos) { throw new IndexOutOfBoundsException(); } return new String(chars, start, length); } ``` Hope this helps!
Create a Java method that does the following: "Returns a substring of this string.".
Of course, here is the Java code you requested: ```java private int getStreamId(HttpHeaders httpHeaders) throws Exception { return httpHeaders.getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), connection().local().incrementAndGetNextStreamId()); } ``` Hope ...
Create a Java method that does the following: "Gets the stream id from the HTTP headers.".
Of course, here is the Java code you requested: ```java @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (!(msg instanceof HttpMessage || msg instanceof HttpContent)) { ctx.write(msg, promise); return; } boolean releas...
Create a Java method that does the following: "Write the message to the channel.".
Of course, here is the Java code you requested: ```java public final <T> ResourceLeakDetector<T> newResourceLeakDetector(Class<T> resource) { return newResourceLeakDetector(resource, ResourceLeakDetector.SAMPLING_INTERVAL); } ``` Hope this helps!
Create a Java method that does the following: "Create a new resource leak detector.".
Of course, here is the Java code you requested: ```java @SuppressWarnings("deprecation") public <T> ResourceLeakDetector<T> newResourceLeakDetector(Class<T> resource, int samplingInterval) { return newResourceLeakDetector(resource, ResourceLeakDetector.SAMPLING_INTERVAL, Long.MAX_VALUE); } ``` Hope th...
Create a Java method that does the following: "Create a new instance of the ResourceLeakDetector class.".
Of course, here is the Java code you requested: ```java public static ProtocolFamily convert(InternetProtocolFamily family) { switch (family) { case IPv4: return StandardProtocolFamily.INET; case IPv6: return StandardProtocolFamily.INET6; default: thr...
Create a Java method that does the following: "Convert the InternetProtocolFamily to the standard protocol family.".
Of course, here is the Java code you requested: ```java protected S state(S newState) { S oldState = state; state = newState; return oldState; } ``` Hope this helps!
Create a Java method that does the following: "Sets the state of the resource.".
Of course, here is the Java code you requested: ```java public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents) { if (maxCumulationBufferComponents < 2) { throw new IllegalArgumentException( "maxCumulationBufferComponents: " + maxCumulationBufferCom...
Create a Java method that does the following: "Sets the maximum number of cumulation buffers that should be used for a single message.".
Of course, here is the Java code you requested: ```java protected NameResolver<InetAddress> newNameResolver(EventLoop eventLoop, ChannelFactory<? extends DatagramChannel> channelFactory, DnsServerAddressStre...
Create a Java method that does the following: "This method is called to create a new NameResolver instance.".
Of course, here is the Java code you requested: ```java @SuppressWarnings("unchecked") public static <T> AttributeKey<T> valueOf(String name) { return (AttributeKey<T>) pool.valueOf(name); } ``` Hope this helps!
Create a Java method that does the following: "Get an AttributeKey from the name.".
Of course, here is the Java code you requested: ```java @SuppressWarnings("unchecked") public static <T> AttributeKey<T> newInstance(String name) { return (AttributeKey<T>) pool.newInstance(name); } ``` Hope this helps!
Create a Java method that does the following: "Create an instance of an attribute key.".
Of course, here is the Java code you requested: ```java private static boolean isLast(HttpMessage httpMessage) { if (httpMessage instanceof FullHttpMessage) { FullHttpMessage fullMessage = (FullHttpMessage) httpMessage; if (fullMessage.trailingHeaders().isEmpty() && !fullMessage.content...
Create a Java method that does the following: "Is the message a last message?".