net.i2p.i2ptunnel.util

## Class LimitOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - net.i2p.i2ptunnel.util.LimitOutputStream

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable
  Direct Known Subclasses:
    ByteLimitOutputStream, DechunkedOutputStream

      public abstract class LimitOutputStream
      extends FilterOutputStream

  Abstract output stream that limits writes and provides completion callback.

  This class extends FilterOutputStream to provide a framework for implementing output streams with write limitations or size restrictions. It tracks completion state and calls a callback when the stream is finished, preventing multiple completion attempts.

  Subclasses implement specific limiting behavior while inheriting callback functionality and completion state management. Useful for implementing streams that need to enforce size limits or provide notification when writing is complete.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `LimitOutputStream.DoneCallback` Callback interface for notification when a limited output stream completes

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected LimitOutputStream.DoneCallback` | `_callback`
    `protected boolean` | `_isDone`

    - ### Fields inherited from class java.io.FilterOutputStream

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LimitOutputStream(OutputStream out, LimitOutputStream.DoneCallback done)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `isDone()`
    `protected void` | `setDone()` flush(), call the callback, and set _isDone
    `void` | `write(byte[] buf, int off, int len)` Subclasses MUST override the following method such that it calls done() when finished and throws EOFException if called again
    `void` | `write(int c)`

    - ### Methods inherited from class java.io.FilterOutputStream

      `close, flush, write`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _callback

          protected final LimitOutputStream.DoneCallback _callback

    - #### _isDone

          protected boolean _isDone

  - ### Constructor Detail

    - #### LimitOutputStream

          public LimitOutputStream(OutputStream out,
                                   LimitOutputStream.DoneCallback done)

      Parameters:
        `done` - non-null

  - ### Method Detail

    - #### isDone

          protected boolean isDone()

    - #### setDone

          protected void setDone()
                          throws IOException

      flush(), call the callback, and set _isDone
      Throws:
        `IOException`

    - #### write

          public void write(byte[] buf,
                            int off,
                            int len)
                     throws IOException

      Subclasses MUST override the following method such that it calls done() when finished and throws EOFException if called again
      Overrides:
        `write` in class `FilterOutputStream`
      Throws:
        `IOException`

    - #### write

          public void write(int c)
                     throws IOException

      Overrides:
        `write` in class `FilterOutputStream`
      Throws:
        `IOException`