Class ReadableBuffers


  • public final class ReadableBuffers
    extends java.lang.Object
    Utility methods for creating ReadableBuffer instances.
    • Constructor Detail

      • ReadableBuffers

        private ReadableBuffers()
    • Method Detail

      • wrap

        public static ReadableBuffer wrap​(byte[] bytes)
        Shortcut for wrap(bytes, 0, bytes.length.
      • wrap

        public static ReadableBuffer wrap​(byte[] bytes,
                                          int offset,
                                          int length)
        Creates a new ReadableBuffer that is backed by the given byte array.
        Parameters:
        bytes - the byte array being wrapped.
        offset - the starting offset for the buffer within the byte array.
        length - the length of the buffer from the offset index.
      • wrap

        public static ReadableBuffer wrap​(java.nio.ByteBuffer bytes)
        Creates a new ReadableBuffer that is backed by the given ByteBuffer. Calls to read from the buffer will increment the position of the ByteBuffer.
      • readArray

        public static byte[] readArray​(ReadableBuffer buffer)
        Reads an entire ReadableBuffer to a new array. After calling this method, the buffer will contain no readable bytes.
      • readAsString

        public static java.lang.String readAsString​(ReadableBuffer buffer,
                                                    java.nio.charset.Charset charset)
        Reads the entire ReadableBuffer to a new String with the given charset.
      • readAsStringUtf8

        public static java.lang.String readAsStringUtf8​(ReadableBuffer buffer)
        Reads the entire ReadableBuffer to a new String using UTF-8 decoding.
      • openStream

        public static java.io.InputStream openStream​(ReadableBuffer buffer,
                                                     boolean owner)
        Creates a new InputStream backed by the given buffer. Any read taken on the stream will automatically increment the read position of this buffer. Closing the stream, however, does not affect the original buffer.
        Parameters:
        buffer - the buffer backing the new InputStream.
        owner - if true, the returned stream will close the buffer when closed.