Package org.eclipse.jgit.util

## Class TemporaryBuffer.LocalFile

- java.lang.Object
- - java.io.OutputStream
  - - org.eclipse.jgit.util.TemporaryBuffer
    - - org.eclipse.jgit.util.TemporaryBuffer.LocalFile

All Implemented Interfaces:
  `Closeable`, `Flushable`, `AutoCloseable`

Enclosing class:
  TemporaryBuffer

    public static class TemporaryBuffer.LocalFile
    extends TemporaryBuffer

A fully buffered output stream using local disk storage for large data.

Initially this output stream buffers to memory and is therefore similar to ByteArrayOutputStream, but it shifts to using an on disk temporary file if the output gets too large.

The content of this buffered stream may be sent to another OutputStream only after this stream has been properly closed by `TemporaryBuffer.close()`.

### Nested Class Summary

### Nested classes/interfaces inherited from class org.eclipse.jgit.util.TemporaryBuffer

`TemporaryBuffer.Heap, TemporaryBuffer.LocalFile`

### Field Summary

### Fields inherited from class org.eclipse.jgit.util.TemporaryBuffer

`DEFAULT_IN_CORE_LIMIT`

### Constructor Summary

Constructors
`LocalFile()` Deprecated. Use the `File` overload to supply a directory.
`LocalFile​(int inCoreLimit)` Deprecated. Use the `File,int` overload to supply a directory.
`LocalFile​(File directory)` Create a new temporary buffer, limiting memory usage.
`LocalFile​(File directory, int inCoreLimit)` Create a new temporary buffer, limiting memory usage.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `destroy()` Clear this buffer so it has no data, and cannot be used again.
`long` `length()` Obtain the length (in bytes) of the buffer.
`InputStream` `openInputStream()` Open an input stream to read from the buffered data.
`protected OutputStream` `overflow()` Open the overflow output stream, so the remaining output can be stored.
`byte[]` `toByteArray()` Convert this buffer's contents into a contiguous byte array.
`void` `writeTo​(OutputStream os, ProgressMonitor pm)` Send this buffer to an output stream.

### Methods inherited from class org.eclipse.jgit.util.TemporaryBuffer

`close, copy, doFlush, reset, write, write`

### Methods inherited from class java.io.OutputStream

`flush, nullOutputStream, write`

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

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

### Constructor Detail

#### LocalFile

    @Deprecated
    public LocalFile()

Deprecated.
Use the `File` overload to supply a directory.
Create a new temporary buffer.

#### LocalFile

    @Deprecated
    public LocalFile​(int inCoreLimit)

Deprecated.
Use the `File,int` overload to supply a directory.
Create a new temporary buffer, limiting memory usage.

Parameters:
  `inCoreLimit` - maximum number of bytes to store in memory. Storage beyond this limit will use the local file.

#### LocalFile

    public LocalFile​(File directory)

Create a new temporary buffer, limiting memory usage.

Parameters:
  `directory` - if the buffer has to spill over into a temporary file, the directory where the file should be saved. If null the system default temporary directory (for example /tmp) will be used instead.

#### LocalFile

    public LocalFile​(File directory,
                     int inCoreLimit)

Create a new temporary buffer, limiting memory usage.

Parameters:
  `directory` - if the buffer has to spill over into a temporary file, the directory where the file should be saved. If null the system default temporary directory (for example /tmp) will be used instead.
  `inCoreLimit` - maximum number of bytes to store in memory. Storage beyond this limit will use the local file.

### Method Detail

#### overflow

    protected OutputStream overflow()
                             throws IOException

Description copied from class: `TemporaryBuffer`
Open the overflow output stream, so the remaining output can be stored.

Specified by:
  `overflow` in class `TemporaryBuffer`
Returns:
  the output stream to receive the buffered content, followed by the remaining output.
Throws:
  `IOException` - the buffer cannot create the overflow stream.

#### length

    public long length()

Description copied from class: `TemporaryBuffer`
Obtain the length (in bytes) of the buffer.

The length is only accurate after `TemporaryBuffer.close()` has been invoked.

Overrides:
  `length` in class `TemporaryBuffer`
Returns:
  total length of the buffer, in bytes.

#### toByteArray

    public byte[] toByteArray()
                       throws IOException

Description copied from class: `TemporaryBuffer`
Convert this buffer's contents into a contiguous byte array.

The buffer is only complete after `TemporaryBuffer.close()` has been invoked.

Overrides:
  `toByteArray` in class `TemporaryBuffer`
Returns:
  the complete byte array; length matches `TemporaryBuffer.length()`.
Throws:
  `IOException` - an error occurred reading from a local temporary file

#### writeTo

    public void writeTo​(OutputStream os,
                        ProgressMonitor pm)
                 throws IOException

Description copied from class: `TemporaryBuffer`
Send this buffer to an output stream.

This method may only be invoked after `TemporaryBuffer.close()` has completed normally, to ensure all data is completely transferred.

Overrides:
  `writeTo` in class `TemporaryBuffer`
Parameters:
  `os` - stream to send this buffer's complete content to.
  `pm` - if not null progress updates are sent here. Caller should initialize the task and the number of work units to ``TemporaryBuffer.length()`/1024`.
Throws:
  `IOException` - an error occurred reading from a temporary file on the local system, or writing to the output stream.

#### openInputStream

    public InputStream openInputStream()
                                throws IOException

Description copied from class: `TemporaryBuffer`
Open an input stream to read from the buffered data.

This method may only be invoked after `TemporaryBuffer.close()` has completed normally, to ensure all data is completely transferred.

Overrides:
  `openInputStream` in class `TemporaryBuffer`
Returns:
  a stream to read from the buffer. The caller must close the stream when it is no longer useful.
Throws:
  `IOException` - an error occurred opening the temporary file.

#### destroy

    public void destroy()

Description copied from class: `TemporaryBuffer`
Clear this buffer so it has no data, and cannot be used again.

Overrides:
  `destroy` in class `TemporaryBuffer`