throw new IOException(message);
}
// Set up the zip file.
ZipFile zipFile = new ZipFile(file);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Add all of the product's references to the zip file.
// Assumes that for hierarchical products, the first reference is the root
// directory and all of its contents are included in the product.
List<Reference> references = resource.getProductReferences();
Reference rootReference = references.get(0);
File rootFile = new File(new URI(rootReference.getDataStoreReference()));
if (rootFile.isDirectory())
{
// Add the directory and all of its contents.
zipFile.addFolder(rootFile, parameters);
}
else
{
// Add each file in the list of references.
for (Reference reference : references)
{
zipFile.addFile(new File(new URI(reference.getDataStoreReference())),
parameters);
}
}
// Add the product's metadata to the zip file.
MetadataResource metadataResource = resource.getMetadataResource();
Metadata metadata = metadataResource.getMetadata();
ByteArrayOutputStream os = new ByteArrayOutputStream();
SerializableMetadata serMetadata = new SerializableMetadata(metadata);
serMetadata.writeMetadataToXmlStream(os);
ByteArrayInputStream bis = new ByteArrayInputStream(os.toByteArray());
parameters.setFileNameInZip(resource.getProductName() + ".met");
parameters.setSourceExternalStream(true);
zipFile.addStream(bis, parameters);
return file;
}