Search in sources :

Example 6 with ByteArrayWrapper

use of org.jbei.ice.lib.entry.sequence.ByteArrayWrapper in project ice by JBEI.

the class EntriesAsCSV method writeZip.

private boolean writeZip(String userId, Set<Long> sequenceSet) {
    SequenceController sequenceController = new SequenceController();
    Path tmpPath = Paths.get(Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY));
    try {
        File tmpZip = File.createTempFile("zip-", ".zip", tmpPath.toFile());
        // out
        FileOutputStream fos = new FileOutputStream(tmpZip);
        ZipOutputStream zos = new ZipOutputStream(fos);
        // get sequence formats
        for (long entryId : sequenceSet) {
            for (String format : formats) {
                ByteArrayWrapper wrapper = sequenceController.getSequenceFile(userId, entryId, format);
                putZipEntry(wrapper, zos);
            }
        }
        // write the csv file
        FileInputStream fis = new FileInputStream(csvPath.toFile());
        ByteArrayWrapper wrapper = new ByteArrayWrapper(IOUtils.toByteArray(fis), "entries.csv");
        putZipEntry(wrapper, zos);
        zos.close();
        csvPath = tmpZip.toPath();
        return true;
    } catch (Exception e) {
        Logger.error(e);
        return false;
    }
}
Also used : Path(java.nio.file.Path) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) ZipOutputStream(java.util.zip.ZipOutputStream) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController)

Aggregations

ByteArrayWrapper (org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)6 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)3 EntryField (org.jbei.ice.lib.dto.entry.EntryField)3 URI (java.net.URI)2 SequenceController (org.jbei.ice.lib.entry.sequence.SequenceController)2 GenbankFormatter (org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter)2 ByteStreams (com.google.common.io.ByteStreams)1 java.io (java.io)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 javax.ws.rs (javax.ws.rs)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1