public void process() throws Base64FormatException, IOException {
byte buffer[] = new byte[BUFFER_SIZE];
byte chunk[] = new byte[4];
int got = -1;
int ready = 0;
fill : while ((got = in.read(buffer)) > 0)
{
int skiped = 0;
while (skiped < got)
{
// Check for un-understood characters:
while (ready < 4)
{
if (skiped >= got)
continue fill;
int ch = check(buffer[skiped++]);
if (ch >= 0)
chunk[ready++] = (byte) ch;
}
if (chunk[2] == 65)
{
out.write(get1(chunk, 0));
return;
}
else if (chunk[3] == 65)
{
out.write(get1(chunk, 0));
out.write(get2(chunk, 0));
return;
}
else
{
out.write(get1(chunk, 0));
out.write(get2(chunk, 0));
out.write(get3(chunk, 0));
}
ready = 0;
}
}
if (ready != 0)
throw new Base64FormatException("Invalid length.");
out.flush();
}
Do the actual decoding.
Process the input stream by decoding it and emiting the resulting bytes
into the output stream. |