public class TempByteHolder extends Object
Constructor and Description |
---|
TempByteHolder(byte[] byte_array)
Creates a new instance of TempByteHolder using passed byte[] as memory buffer.
|
TempByteHolder(byte[] byte_array,
int offset,
int prefilled_data_size)
Creates a new instance of TempByteHolder using passed byte[] which
contains prefilled data as memory buffer.
|
TempByteHolder(int in_memory_capacity)
Creates a new instance of TempByteHolder allocating memory buffer of given capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Erases all unread buffered data and prepares for next use cycle.
|
void |
close()
Clears all data and closes/deletes backing temporary file if used.
|
protected void |
finalize() |
byte[] |
getBytes()
Returns byte[] that holds all buffered data in its first getLength() bytes.
|
InputStream |
getInputStream()
Returns InputSream for reading buffered data.
|
int |
getLength()
Returns number of bytes buffered so far.
|
OutputStream |
getOutputStream()
Returns OutputStream filling this buffer.
|
String |
getString(String character_encoding)
Returns buffered data as String using given character encoding.
|
boolean |
isLarge()
Tells whether buffered data is small enough to fit in memory buffer
so that it can be returned as byte[].
|
void |
readFrom(InputStream is)
Reads all available data from input stream.
|
void |
seek(int offset)
Repositions InputStream at given offset within buffered data.
|
void |
setTempDirectory(File dir)
Override directory to create temporary file in.
|
void |
truncate(int offset)
Truncates buffered data to specified size.
|
void |
writeTo(OutputStream os)
Writes efficiently whole content to output stream.
|
void |
writeTo(OutputStream os,
int start_offset,
int length)
Writes efficiently part of the content to output stream.
|
public TempByteHolder(int in_memory_capacity)
in_memory_capacity
- Size in bytes of memory buffer to allocate.public TempByteHolder(byte[] byte_array)
byte_array
- byte array to be used as memory buffer.public TempByteHolder(byte[] byte_array, int offset, int prefilled_data_size)
byte_array
- byte array to be used as memory buffer.offset
- offset of prefilled data in buffer.prefilled_data_size
- number of bytes that contain valid data.public void clear()
public void close() throws IOException
IOException
- when something goes wrong.public void seek(int offset) throws IOException
IOException
- when something goes wrong.public void truncate(int offset) throws IOException
IOException
public void setTempDirectory(File dir) throws IOException
dir
- File object representing temporary directory.
May be null which means that system default
(java.io.tmpdir system property) should be used.IOException
public int getLength()
public boolean isLarge()
getBytes()
,
getString(String)
public byte[] getBytes()
IllegalStateException
- when data is too big to be read this way.isLarge()
,
getLength()
,
getString(String)
,
getInputStream()
public String getString(String character_encoding) throws UnsupportedEncodingException
character_encoding
- Name of character encoding to use for
converting bytes to String.IllegalStateException
- when data is too large to be read this way.UnsupportedEncodingException
- when this encoding is not supported.public OutputStream getOutputStream()
public InputStream getInputStream()
public void writeTo(OutputStream os) throws IOException
os
- OutputStream to write toIOException
public void writeTo(OutputStream os, int start_offset, int length) throws IOException
os
- OutputStream to write tostart_offset
- Offset of data fragment to be writtenlength
- Length of data fragment to be writtenIOException
public void readFrom(InputStream is) throws IOException
is
- IOException
Copyright © 2013. All rights reserved.