public long compress(InputStream is, OutputStream os, long maxReadLength, long maxWriteLength) throws IOException, CompressionOutputSizeException {
CountedInputStream cis = null;
CountedOutputStream cos = null;
cis = new CountedInputStream(is);
cos = new CountedOutputStream(os);
Encoder encoder = new Encoder();
encoder.SetEndMarkerMode( true );
int dictionarySize = 1;
if(maxReadLength == Long.MAX_VALUE || maxReadLength < 0) {
dictionarySize = MAX_DICTIONARY_SIZE;
Logger.error(this, "No indication of size, having to use maximum dictionary size", new Exception("debug"));
} else {
while(dictionarySize < maxReadLength && dictionarySize < MAX_DICTIONARY_SIZE)
dictionarySize <<= 1;
}
encoder.SetDictionarySize( dictionarySize );
encoder.WriteCoderProperties(os);
encoder.Code( cis, cos, maxReadLength, maxWriteLength, null );
if(cos.written() > maxWriteLength)
throw new CompressionOutputSizeException(cos.written());
cos.flush();
if(logMINOR)
Logger.minor(this, "Read "+cis.count()+" written "+cos.written());