/**
* @param buf data to be compressed to output stream
* @exception IOException if underlying output stream error
**/
public void Compress(byte[] buf, int offset, int length)
{
int idx;
byte c;
short index;
int maxOffset = offset + length;
for (idx = offset; idx < maxOffset; ++idx)
{
c = buf[idx];
if ((index = lzss_.FindCharString(prefix_, c)) != -1)
{
prefix_ = index;
}
else
{
bf_.WriteBits(prefix_, numBits_);
if (lzss_.AddCharString(prefix_, c) > limit_)
{
if (numBits_ == 12)
{
bf_.WriteBits(clearCode_, numBits_);
lzss_.ClearTable(codeSize_);
numBits_ = codeSize_ + 1;
}
else
{
++numBits_;
}
limit_ = (1 << numBits_) - 1;
if (tiffFudge_)
{
--limit_;
}
}
prefix_ = (short)((short)c & 0xFF);
}
}
}