Class LimitedByteOutput

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

    public class LimitedByteOutput
    extends ByteOutputStream
    A limited byte output stream. Throws an exception if too many bytes are written.
    • Constructor Summary

      Constructors 
      Constructor Description
      LimitedByteOutput​(ByteOutput byteOutput, long limit)
      Construct a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      • 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

      • limit

        private final long limit
      • count

        private long count
    • Constructor Detail

      • LimitedByteOutput

        public LimitedByteOutput​(ByteOutput byteOutput,
                                 long limit)
        Construct a new instance.
        Parameters:
        byteOutput - the byte output to write to
        limit - the byte limit
    • Method Detail

      • 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
        Overrides:
        write in class ByteOutputStream
        Parameters:
        b - the byte to write
        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 ByteOutputStream
        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