Module swim.codec
Package swim.codec

Class Binary

java.lang.Object
swim.codec.Binary

public final class Binary extends Object
Byte Input/Output factory.

The Binary.byteArrayOutput(...) family of functions return an Output that writes bytes to a growable array, and bind a byte[] array containing all written bytes.

The Binary.byteBufferOutput(...) family of functions return an Output that writes bytes to a growable array, and bind a ByteBuffer containing all written bytes.

  • Method Details

    • input

      public static InputBuffer input(byte... bytes)
    • inputBuffer

      public static InputBuffer inputBuffer(byte[] array, int offset, int length)
    • inputBuffer

      public static InputBuffer inputBuffer(byte[] array)
    • inputBuffer

      public static InputBuffer inputBuffer(ByteBuffer buffer)
    • outputBuffer

      public static OutputBuffer<ByteBuffer> outputBuffer(byte[] array, int offset, int length)
    • outputBuffer

      public static OutputBuffer<ByteBuffer> outputBuffer(byte[] array)
    • outputBuffer

      public static OutputBuffer<ByteBuffer> outputBuffer(ByteBuffer buffer)
    • byteArrayOutput

      public static Output<byte[]> byteArrayOutput(int initialCapacity, OutputSettings settings)
      Returns a new Output that appends bytes to a growable array, pre-allocated with space for initialCapacity bytes, using the given settings. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a byte[] array with the current output state at any time.
    • byteArrayOutput

      public static Output<byte[]> byteArrayOutput(int initialCapacity)
      Returns a new Output that appends bytes to a growable array, pre-allocated with space for initialCapacity bytes. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a byte[] array with the current output state at any time.
    • byteArrayOutput

      public static Output<byte[]> byteArrayOutput(OutputSettings settings)
      Returns a new Output that appends bytes to a growable array, using the given settings. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a byte[] array with the current output state at any time.
    • byteArrayOutput

      public static Output<byte[]> byteArrayOutput(byte[] array)
    • byteArrayOutput

      public static Output<byte[]> byteArrayOutput()
      Returns a new Output that appends bytes to a growable array. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a byte[] array with the current output state at any time.
    • byteBufferOutput

      public static Output<ByteBuffer> byteBufferOutput(int initialCapacity, OutputSettings settings)
      Returns a new Output that appends bytes to a growable array, pre-allocated with space for initialCapacity bytes, using the given settings. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a ByteBuffer with the current output state at any time.
    • byteBufferOutput

      public static Output<ByteBuffer> byteBufferOutput(int initialCapacity)
      Returns a new Output that appends bytes to a growable array, pre-allocated with space for initialCapacity bytes. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a ByteBuffer with the current output state at any time.
    • byteBufferOutput

      public static Output<ByteBuffer> byteBufferOutput(OutputSettings settings)
      Returns a new Output that appends bytes to a growable array, using the given settings. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a ByteBuffer with the current output state at any time.
    • byteBufferOutput

      public static Output<ByteBuffer> byteBufferOutput(byte[] array)
    • byteBufferOutput

      public static Output<ByteBuffer> byteBufferOutput()
      Returns a new Output that appends bytes to a growable array. The returned Output accepts an unbounded number of bytes, remaining permanently in the cont state, and can bind a ByteBuffer with the current output state at any time.
    • outputParser

      public static <O> Parser<O> outputParser(Output<O> output)
      Returns a new Parser that writes decoded bytes to the given output.
    • parseOutput

      public static <O> Parser<O> parseOutput(Input input, Output<O> output)
      Writes the decoded bytes of the input buffer to the given output, returning a Parser continuation that knows how to decode subsequent input buffers.
    • nullParser

      public static <O> Parser<O> nullParser()
    • parseNull

      public static <O> Parser<O> parseNull(Input input)
    • byteArrayWriter

      public static Writer<byte[],?> byteArrayWriter()
    • byteArrayWriter

      public static Writer<Object,byte[]> byteArrayWriter(byte[] input)
    • byteArrayWriter

      public static <O> Writer<Object,O> byteArrayWriter(O value, byte[] input)
    • byteBufferWriter

      public static Writer<ByteBuffer,Object> byteBufferWriter()
    • byteBufferWriter

      public static Writer<Object,ByteBuffer> byteBufferWriter(ByteBuffer input)
    • byteBufferEWriter

      public static <O> Writer<Object,O> byteBufferEWriter(O value, ByteBuffer input)
    • writeByteArray

      public static Writer<Object,Object> writeByteArray(Output<?> output, byte[] input)
    • writeByteBuffer

      public static Writer<Object,Object> writeByteBuffer(Output<?> output, ByteBuffer input)
    • channelEncoder

      public static Encoder<ReadableByteChannel,ReadableByteChannel> channelEncoder()
    • channelEncoder

      public static Encoder<ReadableByteChannel,ReadableByteChannel> channelEncoder(ReadableByteChannel input)
    • decode

      public static <O> Decoder<O> decode(InputStream input, Decoder<O> decoder) throws IOException
      Throws:
      IOException
    • read

      public static <O> O read(InputStream input, Decoder<O> decoder) throws IOException
      Throws:
      IOException