InMemoryStreamCache (Apache FOP Core 2.11 API)
Date: 2025-04-24

org.apache.fop.pdf

## Class InMemoryStreamCache

- java.lang.Object
- - org.apache.fop.pdf.InMemoryStreamCache

- All Implemented Interfaces:
    StreamCache

      public class InMemoryStreamCache
      extends Object
      implements StreamCache

  StreamCache implementation that uses temporary files rather than heap.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InMemoryStreamCache()` Creates a new InMemoryStreamCache.
    `InMemoryStreamCache(int hintSize)` Creates a new InMemoryStreamCache.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clears and resets the cache.
    `OutputStream` | `getOutputStream()` Get the current OutputStream.
    `int` | `getSize()` Returns the current size of the stream.
    `int` | `outputContents(OutputStream out)` Outputs the cached bytes to the given stream.
    `void` | `write(byte[] data)` Convenience method for writing data to the stream cache.

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

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

- - ### Constructor Detail

    - #### InMemoryStreamCache

          public InMemoryStreamCache()

      Creates a new InMemoryStreamCache.

    - #### InMemoryStreamCache

          public InMemoryStreamCache(int hintSize)

      Creates a new InMemoryStreamCache.
      Parameters:
        `hintSize` - a hint about the approximate expected size of the buffer

  - ### Method Detail

    - #### getOutputStream

          public OutputStream getOutputStream()
                                       throws IOException

      Get the current OutputStream. Do not store it - it may change from call to call.
      Specified by:
        `getOutputStream` in interface `StreamCache`
      Returns:
        the output stream containing the data
      Throws:
        `IOException` - if there is an error getting the output stream

    - #### write

          public void write(byte[] data)
                     throws IOException

      Convenience method for writing data to the stream cache.
      Specified by:
        `write` in interface `StreamCache`
      Parameters:
        `data` - byte array to write
      Throws:
        `IOException` - if there is an IO error

    - #### outputContents

          public int outputContents(OutputStream out)
                             throws IOException

      Outputs the cached bytes to the given stream.
      Specified by:
        `outputContents` in interface `StreamCache`
      Parameters:
        `out` - the output stream to write to
      Returns:
        the number of bytes written
      Throws:
        `IOException` - if there is an IO error writing to the output stream

    - #### getSize

          public int getSize()
                      throws IOException

      Returns the current size of the stream.
      Specified by:
        `getSize` in interface `StreamCache`
      Returns:
        the length of the stream
      Throws:
        `IOException` - if there is an error getting the size

    - #### clear

          public void clear()
                     throws IOException

      Clears and resets the cache.
      Specified by:
        `clear` in interface `StreamCache`
      Throws:
        `IOException` - if there is an error closing the stream

Copyright © 2025 Apache Software Foundation. All rights reserved.