public void process() throws IOException {
byte buffer[] = new byte[BUFFER_SIZE];
int got = -1;
int off = 0;
int count = 0;
while ((got = in.read(buffer, off, BUFFER_SIZE - off)) > 0)
{
if (got >= 3)
{
got += off;
off = 0;
while (off + 3 < = got)
{
int c1 = get1(buffer, off);
int c2 = get2(buffer, off);
int c3 = get3(buffer, off);
int c4 = get4(buffer, off);
switch (count)
{
case 73 :
out.write(encoding[c1]);
out.write(encoding[c2]);
out.write(encoding[c3]);
out.write('\n");
out.write(encoding[c4]);
count = 1;
break;
case 74 :
out.write(encoding[c1]);
out.write(encoding[c2]);
out.write('\n");
out.write(encoding[c3]);
out.write(encoding[c4]);
count = 2;
break;
case 75 :
out.write(encoding[c1]);
out.write('\n");
out.write(encoding[c2]);
out.write(encoding[c3]);
out.write(encoding[c4]);
count = 3;
break;
case 76 :
out.write('\n");
out.write(encoding[c1]);
out.write(encoding[c2]);
out.write(encoding[c3]);
out.write(encoding[c4]);
count = 4;
break;
default :
out.write(encoding[c1]);
out.write(encoding[c2]);
out.write(encoding[c3]);
out.write(encoding[c4]);
count += 4;
break;
}
off += 3;
}
// Copy remaining bytes to beginning of buffer:
for (int i = 0; i < 3; i++)
buffer[i] = (i < got - off) ? buffer[off + i] : ((byte) 0);
off = got - off;
}
else
{
// Total read amount is less then 3 bytes:
off += got;
}
}
// Manage the last bytes, from 0 to off:
switch (off)
{
case 1 :
out.write(encoding[get1(buffer, 0)]);
out.write(encoding[get2(buffer, 0)]);
out.write('=");
out.write('=");
break;
case 2 :
out.write(encoding[get1(buffer, 0)]);
out.write(encoding[get2(buffer, 0)]);
out.write(encoding[get3(buffer, 0)]);
out.write('=");
}
return;
}
Process the data: encode the input stream to the output stream.
This method runs through the input stream, encoding it to the output
stream. |