Class ByteBufferOutput

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, ByteOutput

    public class ByteBufferOutput
    extends java.io.OutputStream
    implements ByteOutput
    An OutputStream implementing ByteOutput which writes to a ByteBuffer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer buffer  
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBufferOutput​(java.nio.ByteBuffer buffer)
      Create a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      void flush()
      private static java.io.IOException readOnlyBuffer()  
      void write​(byte[] b)
      Write all the bytes from the given array to the stream.
      void write​(byte[] b, int off, int len)
      Write some of the bytes from the given array to the stream.
      void write​(int b)
      Writes to the output stream the eight low-order bits of the argument b.
      private static java.io.EOFException writePastEnd()  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • buffer

        private final java.nio.ByteBuffer buffer
    • Constructor Detail

      • ByteBufferOutput

        public ByteBufferOutput​(java.nio.ByteBuffer buffer)
        Create a new instance.
        Parameters:
        buffer - the buffer to write to
    • Method Detail

      • writePastEnd

        private static java.io.EOFException writePastEnd()
      • readOnlyBuffer

        private static java.io.IOException readOnlyBuffer()
      • write

        public void write​(int b)
                   throws java.io.IOException
        Writes to the output stream the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.
        Specified by:
        write in interface ByteOutput
        Specified by:
        write in class java.io.OutputStream
        Parameters:
        b - the byte to write
        Throws:
        java.io.IOException - if an error occurs
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Write all the bytes from the given array to the stream.
        Specified by:
        write in interface ByteOutput
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        b - the byte array
        Throws:
        java.io.IOException - if an error occurs
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Write some of the bytes from the given array to the stream.
        Specified by:
        write in interface ByteOutput
        Overrides:
        write in class java.io.OutputStream
        Parameters:
        b - the byte array
        off - the index to start writing from
        len - the number of bytes to write
        Throws:
        java.io.IOException - if an error occurs
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException