APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http.common

public final Class Utils

extends Object
Class Inheritance
Imports
javax.net.ssl.ExtendedSSLSession, .SSLException, .SSLHandshakeException, .SSLParameters, .SSLSession, java.io.ByteArrayOutputStream, .Closeable, .IOException, .PrintStream, .UncheckedIOException, java.lang.System.Logger.Level, java.net.ConnectException, .Inet6Address, .InetSocketAddress, .ProtocolException, .SocketAddress, .StandardSocketOptions, .Proxy, .URI, java.net.http.HttpHeaders, .HttpRequest, .HttpTimeoutException, java.nio.ByteBuffer, .CharBuffer, java.nio.channels.CancelledKeyException, .NetworkChannel, .SelectionKey, java.nio.charset.CharacterCodingException, .Charset, .CodingErrorAction, .StandardCharsets, java.text.Normalizer, java.time.Instant, java.time.temporal.ChronoUnit, java.util.Arrays, .Collection, .Collections, .HexFormat, .Iterator, .List, .Set, .TreeSet, java.util.concurrent.CancellationException, .Callable, .CompletableFuture, .CompletionException, .ConcurrentHashMap, .ExecutionException, .Executor, .ExecutorService, .Future, .RejectedExecutionException, .TimeUnit, .TimeoutException, java.util.function.BiConsumer, .BiPredicate, .Consumer, .Function, .Predicate, .Supplier, java.util.stream.Collectors, .Stream, jdk.internal.net.http.common.DebugLogger.LoggerConfig, jdk.internal.net.http.HttpRequestImpl, sun.net.NetProperties, sun.net.www.HeaderParser

Miscellaneous utilities

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static record
public static class
public static class
public static enum

Field Summary

Modifier and TypeField and Description
public static final BiPredicate<String, String>
private static final Predicate<String>
public static final BiPredicate<String, String>
public static final BiPredicate<String, String>
public static final boolean
public static final int
BUFSIZE

The capacity of ephemeral ByteBuffers allocated to pass data to and from the client.

private static final int
COPY_THRESHOLD

Threshold beyond which data is no longer copied into the current buffer, if that buffer has enough unused space.

public static final boolean
public static final DebugLogger.LoggerConfig
public static final DebugLogger.LoggerConfig
public static final boolean
public static final DebugLogger.LoggerConfig
private static final Set<String>
private static final Set<String>
public static final ByteBuffer[]
public static final List<ByteBuffer>
public static final ByteBuffer
private static final boolean[]
private static final String
private static final String
private static final Predicate<String>
private static final Predicate<String>
public static final boolean
private static final boolean[]
private static final Predicate<String>
public static final BiPredicate<String, String>
private static final ConcurrentHashMap<Integer, String>
private static final Set<String>
private static final Set<String>
public static final BiPredicate<String, String>
public static final BiPredicate<String, String>
public static final int
private static final boolean[]
public static final boolean
public static final BiPredicate<String, String>
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the number of bytes added
accumulateBuffers
(List<ByteBuffer> currentList, List<ByteBuffer> buffersToAdd)

Adds the data from buffersToAdd to currentList.

public static String

Returns:

a message describing the conflict, if any, or null if no conflict was detected.
addressConflict
(SocketAddress
local address
local
,
SocketAddress
peer address
peer
)

Try to figure out whether local and remote addresses are compatible.

public static <T extends Throwable> T
addSuppressed(T x, Throwable suppressed)

public static String

Returns:

the content of the buffer as an hexadecimal string
asHexString
(ByteBuffer
a byte buffer
buffer
)

Returns the content of the buffer as an hexadecimal string.

public static String

Returns:

a string built from the bytes contained in the buffer decoded using the given charset
asString
(ByteBuffer
a buffer containing bytes encoded using a charset
buffer
,
Charset
the charset to use to decode the bytes into a string
charset
)

Converts a ByteBuffer containing bytes encoded using the given charset into a string.

public static String

Returns:

a string built from the decoded UTF-8 bytes contained in the buffer
asString
(ByteBuffer
a buffer containing UTF-8 bytes
buffer
)

Converts a ByteBuffer containing UTF-8 bytes into a string.

public static Charset
charsetFrom(HttpHeaders headers)

Get the Charset from the Content-encoding header.

public static void
close(Closeable... closeables)

public static <T extends NetworkChannel> T
configureChannelBuffers(Consumer<String> logSink, T chan, int receiveBufSize, int sendBufSize)

public static int
copy(ByteBuffer src, ByteBuffer dst)

Copies as much of src to dst as possible.

public static ByteBuffer
public static ByteBuffer
public static Proxy
copyProxy(Proxy proxy)

Creates a new Proxy instance for the given proxy iff it is neither null, Proxy.NO_PROXY, nor already a Proxy instance.

public static SSLParameters
public static HttpHeaders

Returns:

pseudo headers for that request
createPseudoHeaders
(HttpRequest
the request
request
)

Creates HTTP/2 HTTP/3 pseudo headers for the given request.

public static String

Returns:

a string comparing the given deadline with now, typically something like "due since Nms" or "due in Nms"
debugDeadline
(Deadline
now
now
,
Deadline
the deadline
deadline
)

Returns a string comparing the given deadline with now, typically something like "due since Nms" or "due in Nms".

public static String
describeOps(int interestOps)

public static String
dump(Object... objects)

public static String
public static Throwable

Returns:

the exception the given cf was completed with, or a CancellationException if the given cf was cancelled
exceptionNow
(CompletableFuture<?>
a CompletableFuture exceptionally completed
cf
)

Returns the exception the given cf was completed with, or a CancellationException if the given cf was cancelled.

public static void
flipToMark(ByteBuffer buffer, int mark)

Set limit to position, and position to mark.

public static boolean
getBooleanProperty(String name, boolean def)

public static ByteBuffer

Returns:

a new ByteBuffer instance of BUFSIZE capacity
getBuffer
()

Returns a new ByteBuffer instance of BUFSIZE capacity.

public static ByteBuffer

Returns:

a new ByteBuffer instance whose capacity is set to the smaller of the specified maxCapacity and the default (BUFSIZE)
getBufferWithAtMost
(long
a buffer capacity, in bytes
maxCapacity
)

Returns a new ByteBuffer instance whose capacity is set to the smaller of the specified maxCapacity and the default (BUFSIZE).

public static Throwable
public static Throwable
public static Logger

Returns:

A logger for HTTP internal debug traces
getDebugLogger
(Supplier<String>
A lambda that returns a string that identifies the caller (e.g: "SocketTube(3)", or "Http2Connection(SocketTube(3))")
dbgTag
)

Get a logger for debug HTTP traces.

public static Logger

Returns:

A logger for HTTP internal debug traces
getDebugLogger
(Supplier<String>
A lambda that returns a string that identifies the caller (e.g: "SocketTube(3)", or "Http2Connection(SocketTube(3))")
dbgTag
,
boolean
Whether the logger is enabled.
on
)

Get a logger for debug HTTP traces.The logger should only be used with levels whose severity is <= DEBUG.

private static Set<String>
private static Set<String>
public static Logger

Returns:

A logger for HPACK internal debug traces
getHpackLogger
(Supplier<String>
A lambda that returns a string that identifies the caller (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)")
dbgTag
,
System.Logger.Level
The level above which messages will be also printed on stderr (in addition to be forwarded to the internal logger).
errLevel
)

Get a logger for debug HPACK traces.The logger should only be used with levels whose severity is <= DEBUG.

public static Logger

Returns:

A logger for HPACK internal debug traces
getHpackLogger
(Supplier<String>
A lambda that returns a string that identifies the caller (e.g: "Http2Connection(SocketTube(3))/hpack.Decoder(3)")
dbgTag
)

Get a logger for debug HPACK traces.The logger should only be used with levels whose severity is <= DEBUG.

public static int
getIntegerNetProperty(String name, int defaultValue)

public static int
getIntegerNetProperty(String property, int min, int max, int defaultValue, boolean log)

public static int
getIntegerProperty(String name, int defaultValue)

public static IOException
private static DebugLogger.LoggerConfig
public static long
getLongProperty(String name, long defaultValue)

public static String
public static String
public static int
public static int
public static Logger

Returns:

A logger for WebSocket internal debug traces
getWebSocketLogger
(Supplier<String>
A lambda that returns a string that identifies the caller (e.g: "WebSocket(3)")
dbgTag
)

Get a logger for debug WebSocket traces.The logger should only be used with levels whose severity is <= DEBUG.

public static boolean
public static boolean
private static boolean
public static SSLSession
immutableSession(SSLSession session)

SSLSessions returned to user are wrapped in an immutable object

public static String
private static final boolean
isAllowedForProxy(String name, String value, Set<String> disabledSchemes, Predicate<String> allowedKeys)

public static boolean
isHostnameVerificationDisabled()

Enabled by default.

public static boolean
public static boolean
public static boolean
public static String
millis(Instant now, Instant deadline)

public static String
millis(Deadline now, Deadline deadline)

public static long

Returns:

the relative consolidated position in bytes at which the two input mismatch, or -1L if there is no mismatch.
mismatch
(List<ByteBuffer>
a first list of byte buffers
these
,
List<ByteBuffer>
a second list of byte buffers
those
)

Compute the relative consolidated position in bytes at which the two input mismatch, or -1 if there is no mismatch.

public static IllegalArgumentException
newIAE(String message, Object... args)

public static ByteBuffer

Returns:

the next buffer that has remaining bytes, or null
next
(Iterator<ByteBuffer>
an iterator
iterator
)

Returns the next buffer that has remaining bytes, or null.

public static int

Returns:

the size of the array
pow2Size
(int
capacity
n
)

Returns the smallest (closest to zero) positive number m (which is also a power of 2) such that n <= m.

public static final BiPredicate<String, String>
public static boolean
proxyHasDisabledSchemes(boolean tunnel)

public static int

Returns:

the amount of bytes read and written to the byte array
read
(List<ByteBuffer>
A list of byte buffer
bufs
,
byte[]
A byte array to write into
data
,
int
Where to start writing in the byte array
offset
)

Reads as much bytes as possible from the buffer list, and write them in the provided data byte array.

public static long
readContentLength(HttpHeaders headers, String errorPrefix, long defaultIfMissing)

public static int
readStatusCode(HttpHeaders headers, String errorPrefix)

public static String
public static long
public static long
public static long
remaining(List<ByteBuffer> bufs, long max)

public static int
remaining(List<ByteBuffer> bufs, int max)

public static long
remaining(ByteBuffer[] refs, long max)

public static int
remaining(ByteBuffer[] refs, int max)

public static InetSocketAddress
public static ExecutorService
public static void
setUserAuthFlags(HttpRequestImpl request, HttpHeaders userHeaders)

Check the user headers to see if the Authorization or ProxyAuthorization were set.

public static final void
public static ByteBuffer

Returns:

a new ByteBuffer for the given slice
sliceOrCopy
(ByteBuffer
the original buffer
src
,
int
where to start copying/slicing from src
start
,
int
how many byte to slice/copy
len
)

Creates a slice of a buffer, possibly copying the data instead of slicing.

public static ByteBuffer

Returns:

a new ByteBuffer for the given slice
sliceOrCopy
(ByteBuffer
the original buffer
src
,
int
where to start copying/slicing from src
start
,
int
how many byte to slice/copy
len
,
int
a threshold to decide whether to slice or copy
threshold
)

Creates a slice of a buffer, possibly copying the data instead of slicing.

public static ByteBuffer
sliceWithLimitedCapacity(ByteBuffer buffer, int amount)

Returns a slice of size amount from the given buffer.

public static String
public static String
stringOf(Collection<?> source)

public static long
public static Throwable
public static IOException
public static boolean
public static boolean
trySetSendBufferSize(Consumer<String> logSink, NetworkChannel chan, int bufsize)

public static UncheckedIOException
public static Utils.UseVTForSelector
useVTForSelector(String property, String defval)

public static <T> CompletableFuture<T>
public static Throwable

Returns:

a possibly new exception that has as its detail message, the message from the messageSupplier, and the given throwable as its cause. Otherwise returns the given throwable
wrapWithExtraDetail
(Throwable t, Supplier<String> messageSupplier)

Adds a more specific exception detail message, based on the given exception type and the message supplier.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait