Class TemporaryBuffer.LocalFile
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
- Enclosing class:
- 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()
.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jgit.util.TemporaryBuffer
TemporaryBuffer.Block, TemporaryBuffer.Heap, TemporaryBuffer.LocalFile
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final File
Directory to store the temporary file under.private File
Location of our temporary file if we are on disk; otherwise null.Fields inherited from class org.eclipse.jgit.util.TemporaryBuffer
blocks, DEFAULT_IN_CORE_LIMIT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Clear this buffer so it has no data, and cannot be used again.long
length()
Obtain the length (in bytes) of the buffer.Open an input stream to read from the buffered data.Same asTemporaryBuffer.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[]
Convert this buffer's contents into a contiguous byte array.byte[]
toByteArray
(int limit) 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, toString, write, write
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
directory
Directory to store the temporary file under. -
onDiskFile
Location of our temporary file if we are on disk; otherwise null.If we exceeded the
TemporaryBuffer.inCoreLimit
we nulled outTemporaryBuffer.blocks
and created this file instead. All output goes here throughoverflow()
.
-
-
Constructor Details
-
LocalFile
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
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 Details
-
overflow
Description copied from class:TemporaryBuffer
Open the overflow output stream, so the remaining output can be stored.- Specified by:
overflow
in classTemporaryBuffer
- 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 classTemporaryBuffer
- Returns:
- total length of the buffer, in bytes.
-
toByteArray
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 classTemporaryBuffer
- Returns:
- the complete byte array; length matches
TemporaryBuffer.length()
. - Throws:
IOException
- an error occurred reading from a local temporary file
-
toByteArray
Description copied from class:TemporaryBuffer
Convert this buffer's contents into a contiguous byte array. If this size of the buffer exceeds the limit only return the firstlimit
bytesThe buffer is only complete after
TemporaryBuffer.close()
has been invoked.- Overrides:
toByteArray
in classTemporaryBuffer
- Parameters:
limit
- the maximum number of bytes to be returned- Returns:
- the byte array limited to
limit
bytes. - Throws:
IOException
- an error occurred reading from a local temporary file
-
writeTo
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 classTemporaryBuffer
- 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 toTemporaryBuffer.length()
/1024- Throws:
IOException
- an error occurred reading from a temporary file on the local system, or writing to the output stream.
-
openInputStream
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 classTemporaryBuffer
- 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.
-
openInputStreamWithAutoDestroy
Description copied from class:TemporaryBuffer
Same asTemporaryBuffer.openInputStream()
but handling destruction of any associated resources automatically when closing the returned stream.- Overrides:
openInputStreamWithAutoDestroy
in classTemporaryBuffer
- Returns:
- an InputStream which will automatically destroy any associated
temporary file on
TemporaryBuffer.close()
- Throws:
IOException
- in case of an error.
-
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 classTemporaryBuffer
-