org.apache.sling.bgservlets.impl.nodestream

## Class NodeOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.sling.bgservlets.impl.nodestream.NodeOutputStream

All Implemented Interfaces:
  Closeable, Flushable, AutoCloseable

    public class NodeOutputStream
    extends OutputStream

An OutputStream stored in properties under a JCR node. The content is persisted on each flush() call, using sequentially-named properties so that `NodeInputStream` can reconstruct the stream from permanent storage. flush() is also called automatically every BUFFER_SWITCH_SIZE bytes, to keep our memory requirements low. Meant to be used when running background servlets: we want to save their output in a way that survives system restart.

### Field Summary

Fields
`static int` `BUFFER_SIZE`
`static int` `BUFFER_SWITCH_SIZE`
`static String` `STREAM_NODE_TYPE` Node type for our stream nodes

### Constructor Summary

Constructors
Constructor and Description
`NodeOutputStream(javax.jcr.Node n)`

### Method Summary

Methods
`void` `close()` Calls flush to persist our stream, before closing
`void` `flush()` Store the contents of our buffer to a new Property under our node, numbered sequentially.
`void` `write(byte[] b)`
`void` `write(byte[] b, int off, int len)`
`void` `write(int b)`

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

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

### Field Detail

#### STREAM_NODE_TYPE

    public static final String STREAM_NODE_TYPE

Node type for our stream nodes

See Also:
  Constant Field Values

#### BUFFER_SIZE

    public static final int BUFFER_SIZE

See Also:
  Constant Field Values

#### BUFFER_SWITCH_SIZE

    public static final int BUFFER_SWITCH_SIZE

See Also:
  Constant Field Values

### Constructor Detail

#### NodeOutputStream

    public NodeOutputStream(javax.jcr.Node n)

### Method Detail

#### close

    public void close()
               throws IOException

Calls flush to persist our stream, before closing

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Overrides:
  `close` in class `OutputStream`
Throws:
  `IOException`

#### flush

    public void flush()
               throws IOException

Store the contents of our buffer to a new Property under our node, numbered sequentially.

Specified by:
  `flush` in interface `Flushable`
Overrides:
  `flush` in class `OutputStream`
Throws:
  `IOException`

#### write

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

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

#### write

    public void write(byte[] b)
               throws IOException

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

#### write

    public void write(int b)
               throws IOException

Specified by:
  `write` in class `OutputStream`
Throws:
  `IOException`