public static class TemporaryBuffer.LocalFile extends TemporaryBuffer
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()
.
TemporaryBuffer.Heap, TemporaryBuffer.LocalFile
DEFAULT_IN_CORE_LIMIT
Constructor and Description |
---|
LocalFile(File directory)
Create a new temporary buffer, limiting memory usage.
|
LocalFile(File directory,
int inCoreLimit)
Create a new temporary buffer, limiting memory usage.
|
Modifier and Type | Method and Description |
---|---|
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.
|
InputStream |
openInputStreamWithAutoDestroy()
Same as
TemporaryBuffer.openInputStream() but handling destruction of any
associated resources automatically when closing the returned stream. |
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.
|
close, copy, doFlush, reset, toByteArray, write, write
flush, write
public LocalFile(File directory)
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.public LocalFile(File directory, int inCoreLimit)
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.protected OutputStream overflow() throws IOException
TemporaryBuffer
overflow
in class TemporaryBuffer
IOException
- the buffer cannot create the overflow stream.public long length()
TemporaryBuffer
The length is only accurate after TemporaryBuffer.close()
has been invoked.
length
in class TemporaryBuffer
public byte[] toByteArray() throws IOException
TemporaryBuffer
The buffer is only complete after TemporaryBuffer.close()
has been invoked.
toByteArray
in class TemporaryBuffer
TemporaryBuffer.length()
.IOException
- an error occurred reading from a local temporary filepublic void writeTo(OutputStream os, ProgressMonitor pm) throws IOException
TemporaryBuffer
This method may only be invoked after TemporaryBuffer.close()
has completed
normally, to ensure all data is completely transferred.
writeTo
in class TemporaryBuffer
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
.IOException
- an error occurred reading from a temporary file on the local
system, or writing to the output stream.public InputStream openInputStream() throws IOException
TemporaryBuffer
This method may only be invoked after TemporaryBuffer.close()
has completed
normally, to ensure all data is completely transferred.
openInputStream
in class TemporaryBuffer
IOException
- an error occurred opening the temporary file.public InputStream openInputStreamWithAutoDestroy() throws IOException
TemporaryBuffer
TemporaryBuffer.openInputStream()
but handling destruction of any
associated resources automatically when closing the returned stream.openInputStreamWithAutoDestroy
in class TemporaryBuffer
TemporaryBuffer.close()
IOException
- in case of an error.public void destroy()
TemporaryBuffer
destroy
in class TemporaryBuffer
Copyright © 2019 Eclipse JGit Project. All rights reserved.