All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ByteLimitOutputStreamextends LimitOutputStream
An OutputStream that limits how many bytes are written, throwing EOFException when the limit is exceeded.
  • Field Details

    • _limit

      private final long _limit
      Most bytes the stream will accept.
    • _count

      private long _count
      Bytes written so far.
  • Constructor Details

    • ByteLimitOutputStream

      public ByteLimitOutputStream(OutputStream out, LimitOutputStream.DoneCallback done, long limit)
      Creates a new byte-limited output stream.
      Parameters:
      out - the underlying output stream
      done - callback invoked when the limit is reached
      limit - maximum number of bytes allowed, must be greater than zero
      Throws:
      IllegalArgumentException - if limit is not greater than zero
  • Method Details

    • write

      public void write(byte[] src, int off, int len) throws IOException
      Description copied from class: LimitOutputStream
      Subclasses MUST override the following method such that it calls done() when finished and throws EOFException if called again.
      Overrides:
      write in class LimitOutputStream
      Throws:
      IOException