i2p.susi.util

## Class FileBuffer

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

- All Implemented Interfaces:
    Buffer
  Direct Known Subclasses:
    GzipFileBuffer

      public class FileBuffer
      extends Object
      implements Buffer

  Buffer implementation backed by a file.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected File` | `_file`
    `protected int` | `_offset`
    `protected int` | `_sublen`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileBuffer(File file)`
    `FileBuffer(File file, int offset, int sublen)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `File` | `getFile()`
    `InputStream` | `getInputStream()` Caller must call readComplete()
    `int` | `getLength()` Always valid if file exists
    `int` | `getOffset()` Always valid
    `OutputStream` | `getOutputStream()` Caller must call writeComplete()
    `void` | `readComplete(boolean success)` Top-level reader MUST call this to close the input stream.
    `String` | `toString()`
    `void` | `writeComplete(boolean success)` Deletes the file if success is false

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

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

- - ### Field Detail

    - #### _file

          protected final File _file

    - #### _offset

          protected final int _offset

    - #### _sublen

          protected final int _sublen

  - ### Constructor Detail

    - #### FileBuffer

          public FileBuffer(File file)

    - #### FileBuffer

          public FileBuffer(File file,
                            int offset,
                            int sublen)

  - ### Method Detail

    - #### getFile

          public File getFile()

      Returns:
        the underlying file

    - #### getInputStream

          public InputStream getInputStream()
                                     throws IOException

      Caller must call readComplete()
      Specified by:
        `getInputStream` in interface `Buffer`
      Returns:
        new FileInputStream
      Throws:
        `IOException`

    - #### getLength

          public int getLength()

      Always valid if file exists
      Specified by:
        `getLength` in interface `Buffer`

    - #### getOffset

          public int getOffset()

      Always valid
      Specified by:
        `getOffset` in interface `Buffer`

    - #### getOutputStream

          public OutputStream getOutputStream()
                                       throws IOException

      Caller must call writeComplete()
      Specified by:
        `getOutputStream` in interface `Buffer`
      Returns:
        new FileOutputStream
      Throws:
        `IOException`

    - #### 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 file if success is false
      Specified by:
        `writeComplete` in interface `Buffer`
      Parameters:
        `success` - if false, deletes any resources