public class CompressedRandomStream extends RandomStream
Any file may be converted to a CompressedRandomStream, using the static compressStream() methods or you can run the main() method of CompressedRandomStream to compress a File from the command line.
Modifier and Type | Field and Description |
---|---|
protected RandomStream |
inputStream |
static int |
OPTION_DONT_CLOSE_INPUT |
static int |
OPTION_DONT_CLOSE_OUTPUT |
static byte[] |
signature
These are the signature bytes of a CompressedRandomStream.
|
READ_ONLY, READ_WRITE
Constructor and Description |
---|
CompressedRandomStream(RandomAccessFile compressedFile)
Create a CompressedRandomStream from a RandomAccessStream.
|
CompressedRandomStream(RandomStream compressedFile)
Create a CompressedRandomStream from a RandomStream.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This method closes the stream.
|
static boolean |
compressStream(Handle handle,
InputStream input,
RandomStream out,
int blockSize)
Compress an InputStream into a CompressedRandomStream.
|
static boolean |
compressStream(Handle handle,
InputStream input,
RandomStream out,
int blockSize,
int compressionLevelAndOptions,
long knownSize)
Compress an InputStream into a CompressedRandomStream at the current location.
|
long |
getCacheSize()
Get the number of bytes to cache in memory.
|
long |
getLength()
Return the full length of the Stream.
|
long |
getPosition()
Return the current read/write stream pointer.
|
static boolean |
isCompressedRandomStream(File input)
Check if a File has the CompressedRandomStream signature.
|
static boolean |
isCompressedRandomStream(InputStream inputStream)
Check if an InputStream has the CompressedRandomStream signature.
|
static boolean |
isCompressedRandomStream(RandomAccessFile raf) |
boolean |
isOpenForWriting()
Returns true if this Stream was open in Read-Write mode as opposed to Read-Only mode.
|
static void |
main(String[] args)
This method can be used to convert a File into a CompressedRandomStream.
|
int |
read()
This method reads an unsigned byte from the input stream and returns it
as an int in the range of 0-255.
|
int |
read(byte[] buffer,
int start,
int length)
This method read bytes from a stream and stores them into a
caller supplied buffer.
|
void |
setCacheSize(long cacheSize)
Set the number of bytes to cache in memory.
|
void |
setPosition(long position)
Set the Stream position.
|
canSetLength, flush, isReadWrite, mark, markSupported, reset, setLength, setMode, skip, throwCantWrite, toOutputStream, validateMode, write, write, write
available, finalize, hashCode, read
public static final byte[] signature
public static final int OPTION_DONT_CLOSE_OUTPUT
public static final int OPTION_DONT_CLOSE_INPUT
protected RandomStream inputStream
public CompressedRandomStream(RandomAccessFile compressedFile) throws IOException
compressedFile
- the compressed file.IOException
- if there was an error reading the file.public CompressedRandomStream(RandomStream compressedFile) throws IOException
compressedFile
- the compressed file.IOException
- if there was an error reading the file.public static boolean compressStream(Handle handle, InputStream input, RandomStream out, int blockSize) throws IOException
handle
- an optional handle that can be used to abort the process.input
- the source stream.out
- an output RandomStream.blockSize
- the block size to use. A default of 1024 is used if this is zero.IOException
- if an IO error occured.public static boolean compressStream(Handle handle, InputStream input, RandomStream out, int blockSize, int compressionLevelAndOptions, long knownSize) throws IOException
handle
- an optional handle that can be used to abort the process.input
- the source stream.out
- an output RandomStream.blockSize
- the block size to use. A default of 1024 is used if this is zero.compressionLevelAndOptions
- one of the ZipConstant.Z_xxx_COMPRESSION values, or zero for default.knownSize
- the size of the input stream if it is known, or -1 if it is not known.IOException
- if an IO error occured.public static boolean isCompressedRandomStream(File input) throws IOException
input
- the input file.IOException
- if there is an error reading from the file.public static boolean isCompressedRandomStream(InputStream inputStream) throws IOException
inputStream
- the InputStream.IOException
- if there is an error reading from the file.public static boolean isCompressedRandomStream(RandomAccessFile raf) throws IOException
IOException
public void setCacheSize(long cacheSize)
cacheSize
- the number of bytes to cache in memory.public long getCacheSize()
public static void main(String[] args) throws IOException, InterruptedException
use the command line:
Ewe ewe.io.CompressedRandomStream input_file output_file [block_size]
The default block_size is 1024 bytes.
IOException
InterruptedException
public int read(byte[] buffer, int start, int length) throws IOException
InputStream
off
into the buffer and attempts to read
len
bytes. This method can return before reading the
number of bytes requested. The actual number of bytes read is
returned as an int. A -1 is returned to indicate the end of the
stream.
This method will block until some data can be read.
This method operates by calling the single byte read()
method
in a loop until the desired number of bytes are read. The read loop
stops short if the end of the stream is encountered or if an IOException
is encountered on any read operation except the first. If the first
attempt to read a bytes fails, the IOException is allowed to propagate
upward. And subsequent IOException is caught and treated identically
to an end of stream condition. Subclasses can (and should if possible)
override this method to provide a more efficient implementation.
read
in class InputStream
buffer
- The array into which the bytes read should be storedstart
- The offset into the array to start storing byteslength
- The requested number of bytes to readIOException
- If an error occurs.public int read() throws IOException
InputStream
This method will block until the byte can be read.
read
in class InputStream
IOException
- If an error occurspublic void close() throws IOException
InputStream
IOException
This method does nothing in this class, but subclasses may override this method in order to provide additional functionality.
close
in class InputStream
IOException
- If an error occurs, which can only happen
in a subclasspublic void setPosition(long position) throws IOException
RandomStream
setPosition
in class RandomStream
position
- the new position to set.IOException
- on error.public long getPosition() throws IOException
RandomStream
getPosition
in class RandomStream
IOException
- on error.public long getLength() throws IOException
RandomStream
getLength
in class RandomStream
IOException
- if an IO error occured.public boolean isOpenForWriting()
RandomStream
isOpenForWriting
in class RandomStream