Package jadex.common

Class BufferOutputStream

java.lang.Object
java.io.OutputStream
jadex.common.BufferOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BufferOutputStream extends OutputStream
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected byte[]
     
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new BufferOutputStream with a default initial size.
    BufferOutputStream(int capacity)
    Creates a new BufferOutputStream with the specified initial size.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Checks if there is enough capacity for an operation and expands as necessary.
    void
    Since this is backed by a buffer, this does nothing.
    void
    Resets the buffer, all data lost.
    int
    Returns the buffer size.
    Converts the buffer to a ByteBuffer.
    byte[]
    Converts the buffer to an appropriately sizes array.
    Converts the buffer to a direct ByteBuffer.
    void
    write(byte[] arr, int off, int len)
    Writes the specified bytes from the byte array, starting at the provided offset.
    void
    write(int b)
    Writes a byte to the stream.
    void
    writeBytes(byte[] arr)
    Writes a byte array to the stream.
    void
    Writes the stream content to an output stream..

    Methods inherited from class java.io.OutputStream

    flush, nullOutputStream, write

    Methods inherited from class java.lang.Object

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

    • buffer

      protected byte[] buffer
    • bufsize

      protected int bufsize
  • Constructor Details

    • BufferOutputStream

      public BufferOutputStream()
      Creates a new BufferOutputStream with a default initial size.
    • BufferOutputStream

      public BufferOutputStream(int capacity)
      Creates a new BufferOutputStream with the specified initial size.
      Parameters:
      capacity - The initial capacity, grows as necessary.
  • Method Details

    • write

      public void write(int b)
      Writes a byte to the stream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - The byte to write.
    • write

      public void write(byte[] arr, int off, int len)
      Writes the specified bytes from the byte array, starting at the provided offset.
      Overrides:
      write in class OutputStream
      Parameters:
      arr - The array.
      off - The array offset..
      len - Number of bytes to write.
    • writeBytes

      public void writeBytes(byte[] arr)
      Writes a byte array to the stream.
      Parameters:
      arr - the data.
    • writeTo

      public void writeTo(OutputStream os) throws IOException
      Writes the stream content to an output stream..
      Parameters:
      os - The output stream target.
      Throws:
      IOException - Thrown on IO issues.
    • reset

      public void reset()
      Resets the buffer, all data lost.
    • toByteArray

      public byte[] toByteArray()
      Converts the buffer to an appropriately sizes array.
      Returns:
      Stream content as an array.
    • toBuffer

      public ByteBuffer toBuffer()
      Converts the buffer to a ByteBuffer.
      Returns:
      Stream content as a ByteBuffer.
    • toDirectBuffer

      public ByteBuffer toDirectBuffer()
      Converts the buffer to a direct ByteBuffer.
      Returns:
      Stream content as a direct ByteBuffer.
    • size

      public int size()
      Returns the buffer size.
      Returns:
      Buffer size.
    • close

      public void close() throws IOException
      Since this is backed by a buffer, this does nothing.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • checkAndExpandCapacity

      protected void checkAndExpandCapacity(int reqcap)
      Checks if there is enough capacity for an operation and expands as necessary.
      Parameters:
      reqcap - The required capacity.