public void run()
{
Vector<byte[]> outVector = new Vector<byte[]>();
HelloYenc yencDecoder = null;
UUDecoderStream uuDecoder = null;
FileOutputStream fileOutStream = null;
int uuLength = 0;
// prepare suitable decoder
if(encoding.equals("yenc"))
yencDecoder = new HelloYenc(logger);
else if(encoding.equals("uu"))
uuDecoder = null;
else
{
logger.msg("Could not find a suitable decoder!", MyLogger.SEV_ERROR);
return;
}
try
{
int i = 0;
while(articleData.size() > 0)
{
// check for corrupt download
if(articleData.get(0) == null || articleData.get(0).length == 0)
{
logger.msg("FileDecoder: Corrupt data found", MyLogger.SEV_WARNING);
articleData.remove(0);
continue;
}
// set data input stream of the yenc decoder object
if(encoding.equals("yenc"))
{
yencDecoder.setInputData(articleData.get(0));
yencDecoder.setPartNum(i + 1);
yencDecoder.setRunnable(this);
}
// set data for the UUDecoder object
else if(encoding.equals("uu"))
{
byte[] src = articleData.get(0);
uuLength = src.length;
ByteArrayInputStream inStream = new ByteArrayInputStream(src);
uuDecoder = new UUDecoderStream(inStream);
}
// do we have the first (yenc) part loaded (then get filename)?
if(i == 0)
{
File resultFile = createOutFile(yencDecoder, uuDecoder);
fileOutStream = new FileOutputStream(resultFile);
}
// now decode the current article data block
if(articleData.get(0).length > 0)
{
if(encoding.equals("yenc"))
outVector.add(yencDecoder.decode());
else if(encoding.equals("uu"))
{
byte[] bytes = new byte[uuLength];
int b;
b = uuDecoder.read();
int outBufCounter = 0;
for(; b != -1 && outBufCounter < uuLength; outBufCounter++)
{
bytes[outBufCounter] = (byte) b;
b = uuDecoder.read();
}
byte[] newOutBuf = new byte[outBufCounter];
System.arraycopy(bytes, 0, newOutBuf, 0, outBufCounter);
outVector.add(newOutBuf);