Revision 8160
Added by ben leinfelder over 11 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
87 | 87 |
import edu.ucsb.nceas.metacat.common.query.stream.ContentTypeInputStream; |
88 | 88 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
89 | 89 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
90 |
import edu.ucsb.nceas.metacat.util.DeleteOnCloseFileInputStream; |
|
90 | 91 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
91 | 92 |
|
92 | 93 |
/** |
... | ... | |
1293 | 1294 |
id.setValue(pid); |
1294 | 1295 |
InputStream is = MNodeService.getInstance(request).getPackage(session, id); |
1295 | 1296 |
|
1296 |
// TODO: handle special characters in pid and use that for the filename |
|
1297 |
String filename = id.getValue(); |
|
1298 |
filename = "dataPackage." + System.currentTimeMillis(); |
|
1299 |
filename = filename + ".zip"; |
|
1297 |
// use the provided filename |
|
1298 |
String filename = null; |
|
1299 |
if (is instanceof DeleteOnCloseFileInputStream) { |
|
1300 |
filename = ((DeleteOnCloseFileInputStream)is).getFile().getName(); |
|
1301 |
} else { |
|
1302 |
filename = "dataPackage-" + System.currentTimeMillis() + ".zip"; |
|
1303 |
} |
|
1300 | 1304 |
response.setHeader("Content-Disposition", "inline; filename=" + filename); |
1301 | 1305 |
response.setContentType("application/zip"); |
1302 | 1306 |
response.setStatus(200); |
src/edu/ucsb/nceas/metacat/util/DeleteOnCloseFileInputStream.java | ||
---|---|---|
24 | 24 |
super(file); |
25 | 25 |
this.file = file; |
26 | 26 |
} |
27 |
|
|
27 | 28 |
/** |
29 |
* Allow access to the underlying file - careful! |
|
30 |
* @return |
|
31 |
*/ |
|
32 |
public File getFile() { |
|
33 |
return file; |
|
34 |
} |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
28 | 38 |
* Delete the file when the InputStream is closed |
29 | 39 |
*/ |
30 | 40 |
public void close() throws IOException { |
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
1745 | 1745 |
String extension = ObjectFormatInfo.instance().getExtension(entrySysMeta.getFormatId().getValue()); |
1746 | 1746 |
String prefix = entryPid.getValue(); |
1747 | 1747 |
prefix = "entry"; |
1748 |
File tempFile = File.createTempFile(prefix + ".", extension);
|
|
1748 |
File tempFile = File.createTempFile(prefix + "-", extension);
|
|
1749 | 1749 |
tempFiles.add(tempFile); |
1750 | 1750 |
InputStream entryInputStream = this.get(session, entryPid); |
1751 | 1751 |
IOUtils.copy(entryInputStream, new FileOutputStream(tempFile)); |
... | ... | |
1754 | 1754 |
} |
1755 | 1755 |
|
1756 | 1756 |
//add the the pid to data file map |
1757 |
File pidMappingFile = File.createTempFile("pid-mapping.", ".txt");
|
|
1757 |
File pidMappingFile = File.createTempFile("pid-mapping-", ".txt");
|
|
1758 | 1758 |
IOUtils.write(pidMapping.toString(), new FileOutputStream(pidMappingFile)); |
1759 | 1759 |
bag.addFileAsTag(pidMappingFile); |
1760 | 1760 |
tempFiles.add(pidMappingFile); |
1761 | 1761 |
|
1762 | 1762 |
bag = bag.makeComplete(); |
1763 |
File bagFile = File.createTempFile("bag.", ".zip"); |
|
1764 | 1763 |
|
1764 |
// TODO: consider using mangled-PID for filename |
|
1765 |
File bagFile = File.createTempFile("dataPackage-", ".zip"); |
|
1766 |
|
|
1765 | 1767 |
bag.setFile(bagFile); |
1766 | 1768 |
ZipWriter zipWriter = new ZipWriter(bagFactory); |
1767 | 1769 |
bag.write(zipWriter, bagFile); |
Also available in: Unified diff
use consistent file names and zip content names. Opted for "-" separator so that the zip writer does not remove the unique part of the filename. https://projects.ecoinformatics.org/ecoinfo/issues/6054