Class Utils



  • public final class Utils
    extends java.lang.Object
    Miscellaneous utilities
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.charset.Charset charsetFrom(HttpHeaders headers)
      Get the Charset from the Content-encoding header.
      static void checkNetPermission(java.lang.String target)  
      static void close(java.io.Closeable... closeables)  
      static void close(java.lang.Throwable t, java.io.Closeable... closeables)  
      static java.nio.ByteBuffer copy(java.nio.ByteBuffer src)  
      static int copy(java.nio.ByteBuffer src, java.nio.ByteBuffer dst)
      Copies as much of src to dst as possible.
      static void copy(java.nio.ByteBuffer src, java.nio.ByteBuffer dst, int amount)
      Copy amount bytes from src to dst.
      static javax.net.ssl.SSLParameters copySSLParameters(javax.net.ssl.SSLParameters p)  
      static int copyUpTo(java.nio.ByteBuffer src, java.nio.ByteBuffer dst, int amount)  
      static java.lang.String dump(java.lang.Object... objects)  
      static void flipToMark(java.nio.ByteBuffer buffer, int mark)
      Set limit to position, and position to mark.
      static java.nio.ByteBuffer getBuffer()  
      static java.nio.ByteBuffer getExchangeBuffer()
      We use the same buffer for reading all headers and dummy bodies in an Exchange.
      static int getIntegerNetProperty(java.lang.String name, int defaultValue)  
      static java.io.IOException getIOException(java.lang.Throwable t)  
      static java.net.URLPermission getPermission(java.net.URI uri, java.lang.String method, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
      Returns the security permission required for the given details.
      static java.util.concurrent.ExecutorService innocuousThreadPool()  
      static boolean isValidName(java.lang.String token)  
      static boolean isValidValue(java.lang.String token)  
      static java.nio.ByteBuffer[] reduce(java.nio.ByteBuffer[] bufs, int start, int number)
      Returns an array with the same buffers, but starting at position zero in the array.
      static int remaining(java.nio.ByteBuffer[] bufs)  
      static int remaining(java.util.List<java.nio.ByteBuffer> bufs)  
      static int remaining(ByteBufferReference[] refs)  
      static java.util.concurrent.Executor singleThreadExecutor(java.util.concurrent.Executor parent)
      Returns a single threaded executor which uses one invocation of the parent executor to execute tasks (in sequence).
      static java.nio.ByteBuffer slice(java.nio.ByteBuffer buffer, int amount)  
      static java.lang.String stackTrace(java.lang.Throwable t)  
      static java.lang.String stringOf(java.util.Collection<?> source)  
      static java.io.UncheckedIOException unchecked(java.io.IOException e)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_BUFSIZE

        public static final int DEFAULT_BUFSIZE
        Allocated buffer size. Must never be higher than 16K. But can be lower if smaller allocation units preferred. HTTP/2 mandates that all implementations support frame payloads of at least 16K.
        See Also:
        Constant Field Values
      • BUFSIZE

        public static final int BUFSIZE
      • ALLOWED_HEADERS

        public static final java.util.function.Predicate<java.lang.String> ALLOWED_HEADERS
      • ALL_HEADERS

        public static final java.util.function.Predicate<java.lang.String> ALL_HEADERS
      • EMPTY_CFARRAY

        public static final java.util.concurrent.CompletableFuture[] EMPTY_CFARRAY
      • EMPTY_BYTEBUFFER

        public static final java.nio.ByteBuffer EMPTY_BYTEBUFFER
      • EMPTY_BB_ARRAY

        public static final java.nio.ByteBuffer[] EMPTY_BB_ARRAY
    • Method Detail

      • getBuffer

        public static java.nio.ByteBuffer getBuffer()
      • getIOException

        public static java.io.IOException getIOException(java.lang.Throwable t)
      • getExchangeBuffer

        public static java.nio.ByteBuffer getExchangeBuffer()
        We use the same buffer for reading all headers and dummy bodies in an Exchange.
      • innocuousThreadPool

        public static java.util.concurrent.ExecutorService innocuousThreadPool()
      • isValidName

        public static boolean isValidName(java.lang.String token)
      • isValidValue

        public static boolean isValidValue(java.lang.String token)
      • getPermission

        public static java.net.URLPermission getPermission(java.net.URI uri,
                                                           java.lang.String method,
                                                           java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
        Returns the security permission required for the given details. If method is CONNECT, then uri must be of form "scheme://host:port"
      • checkNetPermission

        public static void checkNetPermission(java.lang.String target)
      • getIntegerNetProperty

        public static int getIntegerNetProperty(java.lang.String name,
                                                int defaultValue)
      • copySSLParameters

        public static javax.net.ssl.SSLParameters copySSLParameters(javax.net.ssl.SSLParameters p)
      • flipToMark

        public static void flipToMark(java.nio.ByteBuffer buffer,
                                      int mark)
        Set limit to position, and position to mark.
      • stackTrace

        public static java.lang.String stackTrace(java.lang.Throwable t)
      • copy

        public static int copy(java.nio.ByteBuffer src,
                               java.nio.ByteBuffer dst)
        Copies as much of src to dst as possible. Return number of bytes copied
      • copyUpTo

        public static int copyUpTo(java.nio.ByteBuffer src,
                                   java.nio.ByteBuffer dst,
                                   int amount)
      • copy

        public static void copy(java.nio.ByteBuffer src,
                                java.nio.ByteBuffer dst,
                                int amount)
        Copy amount bytes from src to dst. at least amount must be available in both dst and in src
      • copy

        public static java.nio.ByteBuffer copy(java.nio.ByteBuffer src)
      • dump

        public static java.lang.String dump(java.lang.Object... objects)
      • stringOf

        public static java.lang.String stringOf(java.util.Collection<?> source)
      • remaining

        public static int remaining(java.nio.ByteBuffer[] bufs)
      • remaining

        public static int remaining(java.util.List<java.nio.ByteBuffer> bufs)
      • close

        public static void close(java.io.Closeable... closeables)
      • close

        public static void close(java.lang.Throwable t,
                                 java.io.Closeable... closeables)
      • reduce

        public static java.nio.ByteBuffer[] reduce(java.nio.ByteBuffer[] bufs,
                                                   int start,
                                                   int number)
        Returns an array with the same buffers, but starting at position zero in the array.
      • singleThreadExecutor

        public static java.util.concurrent.Executor singleThreadExecutor(java.util.concurrent.Executor parent)
        Returns a single threaded executor which uses one invocation of the parent executor to execute tasks (in sequence). Use a null valued Runnable to terminate.
      • slice

        public static java.nio.ByteBuffer slice(java.nio.ByteBuffer buffer,
                                                int amount)
      • charsetFrom

        public static java.nio.charset.Charset charsetFrom(HttpHeaders headers)
        Get the Charset from the Content-encoding header. Defaults to UTF_8
      • unchecked

        public static java.io.UncheckedIOException unchecked(java.io.IOException e)