|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.sevenzipjbinding.util.ByteArrayStream
public class ByteArrayStream
A byte array based implementation of
Provide read/write access to the content represented as a byte array. Provide bridge toInputStream
and
OutputStream
through various methods.
Field Summary |
---|
Fields inherited from interface net.sf.sevenzipjbinding.ISeekableStream |
---|
SEEK_CUR, SEEK_END, SEEK_SET |
Fields inherited from interface net.sf.sevenzipjbinding.ISeekableStream |
---|
SEEK_CUR, SEEK_END, SEEK_SET |
Constructor Summary | |
---|---|
ByteArrayStream(byte[] content,
boolean copyContentArray)
Create new empty instance of ByteArrayStream with content content without specifying maximal length
of the stored data.WARNING: The maximal length of the byte array stream will be set to content.length . |
|
ByteArrayStream(byte[] content,
boolean copyContentArray,
int maxSize)
Create new empty instance of ByteArrayStream with content content specifying maximal length of the
stored data. |
|
ByteArrayStream(int maxSize)
Create new empty instance of ByteArrayStream specifying maximal length of the stored data. |
|
ByteArrayStream(int initialSize,
int maxSize)
Create new empty instance of ByteArrayStream specifying maximal length of the stored data. |
Method Summary | |
---|---|
void |
close()
Empty method. |
byte[] |
getBytes()
Return the content of the byte array stream in a new byte array. |
int |
getCurrentPosition()
Return current position in the byte array stream. |
java.io.InputStream |
getDetachedInputStream()
Get a detached input stream associated with the entire byte stream content. |
java.io.InputStream |
getInputStream()
Get an attached input stream associated with the byte stream content. |
java.io.OutputStream |
getOutputStream()
Get an attached output stream associated with the byte stream content. |
int |
getSize()
Return the size of the byte array stream content in bytes. |
boolean |
isEOF()
Retrieve "End Of Stream" status of the byte array stream. |
int |
read(byte[] data)
Reads at least 1 and maximum data.length bytes from the in-stream. |
int |
read(byte[] data,
int startPosition,
int length)
Reads length bytes from the byte array stream. |
void |
rewind()
Set current pointer back to zero. |
long |
seek(long offset,
int seekOrigin)
Move current location pointer to the new offset depending on seekOrigin .Note: depending on the archive format and the data size this method may be called from different threads. |
void |
setBytes(byte[] newContent,
boolean copyNewContentArray)
Reinitialize byte array stream, replace current content with the new content newContent and set the
current position to the beginning of the stream. |
void |
setSize(long newSize)
Set new size for the out stream. Note: depending on the archive format and the data size this method may be called from different threads. |
void |
truncate()
Clear all content of the stream |
int |
write(byte[] data)
Write data byte array to the stream. |
int |
write(byte[] data,
int startPosition,
int length)
Write length byte from the byte array data beginning from the position
startPosition . |
void |
writeFromInputStream(java.io.InputStream inputStream,
boolean closeStreamAfterReading)
Write entire data from InputStream inputStream into byte array stream. |
void |
writeToOutputStream(java.io.OutputStream outputStream,
boolean closeStreamAfterWriting)
Write entire content of the stream to the output stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteArrayStream(byte[] content, boolean copyContentArray, int maxSize)
content
specifying maximal length of the
stored data.
content
- content to initialize byte array stream with. The current position will be set at the beginning of the
stream.copyContentArray
- true
- copy newContent
byte array, so the original array can be modified
safely, without affecting the byte streamfalse
- don't copy byte array newContent
. Any change to the byte array
newContent
will be reflected by the byte array stream.maxSize
- maximal length of the stored data. Use Integer.MAX_VALUE
to disable maximal length constraint.public ByteArrayStream(byte[] content, boolean copyContentArray)
content
without specifying maximal length
of the stored data.content.length
. This
means, that no more data can be added to such byte array stream. However it's still possible to override or
truncate existing data.
content
- content to initialize byte array stream with. The current position will be set at the beginning of the
stream.copyContentArray
- true
- copy newContent
byte array, so the original array can be modified
safely, without affecting the byte streamfalse
- don't copy byte array newContent
. Any change to the byte array
newContent
will be reflected by the byte array stream.public ByteArrayStream(int maxSize)
maxSize
- maximal length of the stored data. Use Integer.MAX_VALUE
to disable maximal length constraint.public ByteArrayStream(int initialSize, int maxSize)
maxSize
- maximal length of the stored data. Use Integer.MAX_VALUE
to disable maximal length constraint.initialSize
- size of the first data chunk. The first data chunk (byte array) will be allocated after first writing
request.Method Detail |
---|
public int read(byte[] data) throws SevenZipException
data.length
bytes from the in-stream. If data.length == 0
0 should be returned. If data.length != 0
, then return value 0 indicates end-of-stream (EOF). This
means no more bytes can be read from the stream. data.length
. You must call read()
function in loop, if you need exact amount of data.
read
in interface ISequentialInStream
data
- buffer to get read data
data
array. 0 - represents end of stream.
SevenZipException
- in error case. If this method ends with an exception, the current operation will be reported to 7-Zip
as failed. There are no guarantee, that there are no further call back methods will get called. The
first and last thrown exceptions will be saved and thrown later on from the originally called method
such as ISevenZipInArchive.extract()
or SevenZip.openInArchive()
. Up to
four exceptions depending on the situation can be saved for further analysis. See
SevenZipException
and SevenZipException.printStackTraceExtended()
for details.public int read(byte[] data, int startPosition, int length)
length
bytes from the byte array stream. If length == 0
0 is returned. If
length != 0
, then return value 0 indicates end-of-stream (EOF). This means no more bytes can be read
from the stream. The read bytes will be stored in the data
array beginning from the position
startPosition
data
- buffer to get read data.startPosition
- position (index) in the array data
to store first read byte.length
- count of the bytes to read.
data
array. 0 - represents end of stream.
java.lang.IllegalStateException
- will be thrown, if startPosition
is an invalid index for the array data
or
if startPosition + length > data.length
.public boolean isEOF()
true
the current position is at the end of the stream. The read operation will return 0, the
write operation will expand the byte array stream.false
-the current position is not at the end of the stream.public long seek(long offset, int seekOrigin) throws SevenZipException
seekOrigin
.
seek
in interface ISeekableStream
offset
- absolute or relative offset in the stream to move toseekOrigin
- on of three possible seek origins:ISeekableStream.SEEK_SET
- offset
is an absolute offset to move to,
ISeekableStream.SEEK_CUR
- offset
is a relative offset to the current position in stream,
ISeekableStream.SEEK_END
- offset
is an offset from the end of the stream
(offset <= 0)
.
SevenZipException
- in error case. If this method ends with an exception, the current operation will be reported to 7-Zip
as failed. There are no guarantee, that there are no further call back methods will get called. The
first and last thrown exceptions will be saved and thrown later on from the originally called method
such as ISevenZipInArchive.extract()
or SevenZip.openInArchive()
. Up to
four exceptions depending on the situation can be saved for further analysis. See
SevenZipException
and SevenZipException.printStackTraceExtended()
for details.public void rewind()
public void setSize(long newSize)
setSize
in interface IOutStream
newSize
- new sizepublic int write(byte[] data)
data
byte array to the stream. If data.length > 0
this function must write at least 1
byte. This function is allowed to write less than data.length
bytes. You must call Write function in
loop, if you need to write exact amount of data.
write
in interface ISequentialOutStream
data
- data to write
public int write(byte[] data, int startPosition, int length)
length
byte from the byte array data
beginning from the position
startPosition
.
data
- data to writestartPosition
- index of the first byte to write (beginning with 0)length
- count of bytes to write
java.lang.IllegalStateException
- will be thrown, if startPosition
is an invalid index for the array data
or
if startPosition + length > data.length
.public java.io.InputStream getDetachedInputStream()
public java.io.InputStream getInputStream()
InputStream
implementation for this byte array streampublic java.io.OutputStream getOutputStream()
OutputStream
implementation for this byte array streampublic void writeToOutputStream(java.io.OutputStream outputStream, boolean closeStreamAfterWriting) throws java.io.IOException
outputStream
- output stream to write the entire content tocloseStreamAfterWriting
- true
close output stream outputStream
by calling
OutputStream.close()
method, false
don't close output stream
java.io.IOException
- if I/O exception occurspublic void writeFromInputStream(java.io.InputStream inputStream, boolean closeStreamAfterReading) throws java.io.IOException
InputStream
inputStream
into byte array stream. The new data will be
written at the current position of the byte array stream.
inputStream
- input stream to read from.closeStreamAfterReading
- close input stream after reading.
java.io.IOException
- exceptions during reading and optional closing of input stream.public void truncate()
public int getSize()
public int getCurrentPosition()
seek(long, int)
method.
getSize()
, that means, that end of stream (EOF) was reached. All subsequent read operations will
return EOF. All subsequent write operation will expand the stream until maximal size of stream will be
reached. (See ByteArrayStream(int)
).public byte[] getBytes()
public void setBytes(byte[] newContent, boolean copyNewContentArray)
newContent
and set the
current position to the beginning of the stream.
newContent
- new content of the byte array streamcopyNewContentArray
- true
- copy newContent
byte array, so the original array can be modified
safely, without affecting the byte streamfalse
- don't copy byte array newContent
. Any change to the byte array
newContent
will be reflected by the byte array stream.public void close() throws java.io.IOException
close
in interface java.io.Closeable
java.io.IOException
- neverCloseable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |