i2p.susi.util

## Class MemoryBuffer

- java.lang.Object
- - i2p.susi.util.MemoryBuffer

- All Implemented Interfaces:
    Buffer

      public class MemoryBuffer
      extends Object
      implements Buffer

  Buffer implementation backed by a byte array. Suitable for small amounts of data only.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MemoryBuffer()`
    `MemoryBuffer(int size)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `getContent()`
    `InputStream` | `getInputStream()`
    `int` | `getLength()` Current size.
    `int` | `getOffset()`
    `OutputStream` | `getOutputStream()`
    `void` | `readComplete(boolean success)` Top-level reader MUST call this to close the input stream.
    `String` | `toString()`
    `void` | `writeComplete(boolean success)` Deletes the data if success is false

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

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

- - ### Constructor Detail

    - #### MemoryBuffer

          public MemoryBuffer()

    - #### MemoryBuffer

          public MemoryBuffer(int size)

  - ### Method Detail

    - #### getContent

          public byte[] getContent()

      Returns:
        content if writeComplete(true) was called, otherwise null

    - #### getInputStream

          public InputStream getInputStream()
                                     throws IOException

      Specified by:
        `getInputStream` in interface `Buffer`
      Returns:
        new ByteArrayInputStream
      Throws:
        `IOException`

    - #### getLength

          public int getLength()

      Current size.
      Specified by:
        `getLength` in interface `Buffer`

    - #### getOffset

          public int getOffset()

      Specified by:
        `getOffset` in interface `Buffer`
      Returns:
        0 always

    - #### getOutputStream

          public OutputStream getOutputStream()

      Specified by:
        `getOutputStream` in interface `Buffer`
      Returns:
        new or existing ByteArrayOutputStream

    - #### readComplete

          public void readComplete(boolean success)

      Description copied from interface: `Buffer`
      Top-level reader MUST call this to close the input stream.
      Specified by:
        `readComplete` in interface `Buffer`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### writeComplete

          public void writeComplete(boolean success)

      Deletes the data if success is false
      Specified by:
        `writeComplete` in interface `Buffer`
      Parameters:
        `success` - if false, deletes any resources