Class ByteArrayWriter

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
com.sshtools.common.util.ByteArrayWriter
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ByteArrayWriter extends ByteArrayOutputStream

Utility class to write common parameter types to a byte array.

Author:
Lee David Painter
  • Constructor Details

    • ByteArrayWriter

      public ByteArrayWriter()
      Contruct an empty writer.
    • ByteArrayWriter

      public ByteArrayWriter(int length)
      Construct a writer with an array size of the length supplied.
      Parameters:
      length -
  • Method Details

    • array

      public byte[] array()
      Get the underlying byte array
      Returns:
      the underlying byte array.
    • move

      public void move(int numBytes)
      Move the position of the next byte to be written.
      Parameters:
      numBytes -
    • writeBigInteger

      public void writeBigInteger(BigInteger bi) throws IOException
      Write a BigInteger to the array.
      Parameters:
      bi -
      Throws:
      IOException
    • writeBoolean

      public void writeBoolean(boolean b)
      Write a boolean value to the array.
      Parameters:
      b -
      Throws:
      IOException
    • writeBinaryString

      public void writeBinaryString(byte[] data) throws IOException
      Write a binary string to the array.
      Parameters:
      data -
      Throws:
      IOException
    • writeBinaryString

      public void writeBinaryString(byte[] data, int offset, int len) throws IOException
      Write a binary string to the array.
      Parameters:
      data -
      offset -
      len -
      Throws:
      IOException
    • writeMPINT

      public void writeMPINT(BigInteger b)
    • writeShort

      public void writeShort(short s)
    • writeInt

      public void writeInt(long i) throws IOException
      Write an integer to the array
      Parameters:
      i -
      Throws:
      IOException
    • writeInt

      public void writeInt(int i) throws IOException
      Write an integer to the array.
      Parameters:
      i -
      Throws:
      IOException
    • encodeInt

      public static byte[] encodeInt(int i)
      Encode an integer into a 4 byte array.
      Parameters:
      i -
      Returns:
      a byte[4] containing the encoded integer.
    • encodeInt

      public static byte[] encodeInt(long i)
    • encodeInt

      public static byte[] encodeInt(UnsignedInteger32 val)
    • encodeInt

      public static void encodeInt(byte[] buf, int off, int i)
    • writeUINT32

      public void writeUINT32(UnsignedInteger32 value) throws IOException
      Throws:
      IOException
    • writeUINT64

      public void writeUINT64(UnsignedInteger64 value) throws IOException
      Throws:
      IOException
    • stripLeadingZeros

      public static byte[] stripLeadingZeros(byte[] data)
    • writeUINT64

      public void writeUINT64(long value) throws IOException
      Throws:
      IOException
    • writeString

      public void writeString(String str) throws IOException
      Write a string to the byte array.
      Parameters:
      str -
      Throws:
      IOException
    • writeString

      public void writeString(String str, String charset) throws IOException
      Write a String to the byte array converting the bytes using the given character set.
      Parameters:
      str -
      charset -
      Throws:
      IOException
    • silentClose

      public void silentClose()
    • dispose

      public void dispose()
    • encodeString

      public static byte[] encodeString(String memo) throws IOException
      Throws:
      IOException