/// Decompresses the given Huffman coded string literal.
/// </summary>
/// <param name="buf">the string literal to be decoded</param>
/// <returns>the output stream for the compressed data</returns>
/// <exception cref="IOException">throws IOException if an I/O error occurs. In particular, an <code>IOException</code> may be thrown if the output stream has been closed.</exception>
publicstringDecode(byte[]buf)
{
varresultBuf=newbyte[buf.Length*2];
intresultSize=0;
varnode=root;
intcurrent=0;
intbits=0;
for(inti=0;i<buf.Length;i++)
{
intb=buf[i];
current=(current<<8)|b;
bits+=8;
while(bits>=8)
{
intc=(current>>(bits-8))&0xFF;
node=node.Children[c];
bits-=node.Bits;
if(node.IsTerminal)
{
if(node.Symbol==HpackUtil.HuffmanEos)
{
thrownewIOException("EOS Decoded");
}
resultBuf[resultSize++]=(byte)node.Symbol;
node=root;
}
}
}
while(bits>0)
{
intc=(current<<(8-bits))&0xFF;
node=node.Children[c];
if(node.IsTerminal&&node.Bits<=bits)
{
bits-=node.Bits;
resultBuf[resultSize++]=(byte)node.Symbol;
node=root;
}
else
{
break;
}
}
// Section 5.2. String Literal Representation
// Padding not corresponding to the most significant bits of the code
// for the EOS symbol (0xFF) MUST be treated as a decoding error.
/// Compresses the input string literal using the Huffman coding.
/// </summary>
/// <param name="output">the output stream for the compressed data</param>
/// <param name="data">the string literal to be Huffman encoded</param>
/// <param name="off">the start offset in the data</param>
/// <param name="len">the number of bytes to encode</param>
/// <exception cref="IOException">if an I/O error occurs. In particular, an <code>IOException</code> may be thrown if the output stream has been closed.</exception>