file = File.createTempFile("gatein-export", ".zip");
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
}
catch (IOException e)
{
throw new BindingException("Could not create temp file for export.", e);
}
try
{
if (model.getTasks().isEmpty())
{
zos.putNextEntry(new ZipEntry(""));
}
else
{
for (ExportTask task : model.getTasks())
{
String entry = task.getEntry();
zos.putNextEntry(new ZipEntry(entry));
// Call export task responsible for writing the data.
task.export(zos);
zos.closeEntry();
}
}
zos.flush();
zos.finish();
}
catch (Throwable t)
{
throw new BindingException("Exception writing data to zip.", t);
}
finally
{
IOTools.safeClose(zos);
}
try
{
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
IOTools.copy(inputStream, outputStream);
}
catch (FileNotFoundException e)
{
throw new BindingException("Could not read from temporary zip file " + file, e);
}
catch (IOException e)
{
throw new BindingException("IOException writing data to final output stream.", e);
}
}