/// Fills up the input buffer.
/// No-op if there are at least 36 bytes present after current position.
///
After encountering the end of the input stream, 64 additional zero bytes are copied to the
/// buffer.
///
internal static void ReadMoreInput(Org.Brotli.Dec.BitReader br)
{
// TODO: Split to check and read; move read outside of decoding loop.
if (br.intOffset <= Capacity - 9)
{
return;
}
if (br.endOfStreamReached)
{
if (IntAvailable(br) >= -2)
{
return;
}
throw new Org.Brotli.Dec.BrotliRuntimeException("No more input");
}
int readOffset = br.intOffset << 2;
int bytesRead = ByteReadSize - readOffset;
System.Array.Copy(br.byteBuffer, readOffset, br.byteBuffer, 0, bytesRead);
br.intOffset = 0;
try
{
while (bytesRead < ByteReadSize)
{
int len = br.input.Read(br.byteBuffer, bytesRead, ByteReadSize - bytesRead);
// EOF is -1 in Java, but 0 in C#.
if (len <= 0)
{
br.endOfStreamReached = true;
br.tailBytes = bytesRead;
bytesRead += 3;
break;
}
bytesRead += len;
}
}
catch (System.IO.IOException e)
{
throw new Org.Brotli.Dec.BrotliRuntimeException("Failed to read input", e);
}
Org.Brotli.Dec.IntReader.Convert(br.intReader, bytesRead >> 2);
}
internal static void CheckHealth(Org.Brotli.Dec.BitReader br, bool endOfStream)
{
if (!br.endOfStreamReached)
{
return;
}
int byteOffset = (br.intOffset << 2) + ((br.bitOffset + 7) >> 3) - 8;
if (byteOffset > br.tailBytes)
{
throw new Org.Brotli.Dec.BrotliRuntimeException("Read after end");
}
if (endOfStream && (byteOffset != br.tailBytes))
{
throw new Org.Brotli.Dec.BrotliRuntimeException("Unused bytes after end");
}
}
///