|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.io.RandomStream
ewe.io.CompressedRandomStream
A CompressedRandomStream is a read-only RandomStream that has been compressed for storage, but optimized for random access reading. This is unlike a stream that has been zipped where the entire stream is zipped into one entire zipped file. A CompressedRandomStream is compressed in blocks (of a size that you can select on creation) and a directory of the locations of each block is maintained, allowing for quick location and decompression of specific bytes within the file.
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.
| Field Summary | |
protected RandomStream |
inputStream
|
static byte[] |
signature
These are the signature bytes of a CompressedRandomStream. |
| Fields inherited from class ewe.io.RandomStream |
closed, noWritingAllowed, ras |
| Constructor Summary | |
CompressedRandomStream(RandomAccessStream compressedFile)
Create a CompressedRandomStream from a RandomAccessStream. |
|
CompressedRandomStream(RandomStream compressedFile)
Create a CompressedRandomStream from a RandomStream. |
|
| Method Summary | |
boolean |
canWrite()
|
void |
close()
|
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 compressionLevel,
long knownSize)
Compress an InputStream into a CompressedRandomStream. |
long |
getCacheSize()
Get the number of bytes to cache in memory. |
static boolean |
isCompressedRandomStream(File input)
Check if a File has the CompressedRandomStream signature. |
long |
length()
|
static void |
main(String[] args)
This method can be used to convert a File into a CompressedRandomStream. |
int |
read()
Reads the next byte of data from this input stream. |
int |
read(byte[] buffer,
int start,
int length)
Read in a number of bytes of data from the input stream. |
void |
seek(long position)
|
void |
setCacheSize(long cacheSize)
Set the number of bytes to cache in memory. |
long |
tell()
|
| Methods inherited from class ewe.io.RandomStream |
available, cantWrite, checkClosed, flush, getFastStream, read, readSingleByteFromMultiByteRead, setLength, shutdown, skip, toInputStream, toOutputStream, toRandomAccessStream, toReadableStream, toWritableStream, write, write, write, writeSingleByteToMultiByteWrite |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public static final byte[] signature
protected RandomStream inputStream
| Constructor Detail |
public CompressedRandomStream(RandomAccessStream 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.| Method Detail |
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 compressionLevel,
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.compressionLevel - 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 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
RandomStream
read in class RandomStreambuffer - a destination buffer for the data.start - The start offset in the destination buffer.length - The number of bytes to read.
IOException - if an I/O error occurs during reading.
public int read()
throws IOException
RandomStream
read in class RandomStreamIOException - if an I/O error occured.
public void close()
throws IOException
close in class RandomStreamIOException
public void seek(long position)
throws IOException
seek in class RandomStreamIOException
public long tell()
throws IOException
tell in class RandomStreamIOException
public long length()
throws IOException
length in class RandomStreamIOExceptionpublic boolean canWrite()
canWrite in class RandomStream
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||