if ( directory == null || !directory.exists() || !directory.isDirectory() ) {
throw new RestletException( "No files for datastore " + datastore, Status.CLIENT_ERROR_NOT_FOUND );
}
//zip up all the files in the directory
StreamDataFormat fmt = new StreamDataFormat(MediaType.APPLICATION_ZIP) {
@Override
protected Object read(InputStream in) throws IOException {
return null;
}
@Override
protected void write(Object object, OutputStream out)
throws IOException {
ZipOutputStream zout = new ZipOutputStream( out );
File directory = (File) object;
for ( File f : directory.listFiles() ) {
ZipEntry entry = new ZipEntry( f.getName() );
zout.putNextEntry(entry);
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
IOUtils.copy(fis, zout);
} finally {
IOUtils.closeQuietly(fis);
}
zout.closeEntry();
}
zout.flush();
zout.close();
}
};
getResponse().setEntity( fmt.toRepresentation( directory ) );
}