tempFile = File.createTempFile("ogsadai-", null);
}
catch (Exception e)
{
throw new ActivityProcessingException(e);
}
InputStream input = null;
OutputStream output = null;
try
{
input = (InputStream) iterationData[1];
output = new FileOutputStream(tempFile);
IOUtilities.streamData(input, output);
String name=tempFile.getName();
if (filename!=null && filename.length() > 0)
{
if(filename.indexOf("../")>=0)
throw new IOException("Invalid filename");
File file=new File(filename);
relpath = file.getParent()!=null? new File(filename).getParent():relpath;
name=filename.substring(filename.lastIndexOf("/")+1, filename.length());
}
File outputDir = new File(mResource.getHomeDirectory().getAbsolutePath()+"/"+relpath);
if(!outputDir.exists())
outputDir.mkdirs();
if(!tempFile.renameTo(new File(outputDir,name)))
throw new IOException("Impossible to create file");
mOutput.write(outputDir.getAbsolutePath()+"/"+name);
}
catch (IOException e)
{
throw new ActivityProcessingException(e);
}
finally
{
try
{
if (input != null) input.close();
if (output != null) output.close();
}
catch (Exception e)
{
LOG.warn(e);
}
}
}
catch (PipeClosedException e)
{
iterativeStageComplete();
}
catch (PipeIOException e)
{
throw new ActivityProcessingException(e);
}
catch (PipeTerminatedException e)
{
throw new ActivityTerminatedException();
}