public void writeTo(Map<String, byte[]> parts, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { ZipArchiveOutputStream zip = new ZipArchiveOutputStream(entityStream); zip.setMethod(ZipArchiveOutputStream.STORED); for (Map.Entry<String, byte[]> entry : parts.entrySet()) { zipStoreBuffer(zip, entry.getKey(), entry.getValue()); } zip.close(); } }
zipArchiveOutputStream.setEncoding( encoding ); zipArchiveOutputStream.setCreateUnicodeExtraFields( this.getUnicodeExtraFieldPolicy() ); zipArchiveOutputStream.setMethod( doCompress ? ZipArchiveOutputStream.DEFLATED : ZipArchiveOutputStream.STORED );
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); } File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip"); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); ArchiveEntry archiveEntry = newArchive(logFile); zipOutputStream.putArchiveEntry(archiveEntry); FileInputStream logFileInput = new FileInputStream(logFile); IOUtils.copyLarge(logFileInput, zipOutputStream); logFileInput.close(); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); FileInputStream tempFileInput = new FileInputStream(tempFile); IOUtils.copyLarge(tempFileInput, outputStream); tempFileInput.close(); FileUtils.deleteQuietly(tempFile); }
protected byte[] zipContent(Map<String, Object> stringObjectMap) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.STORED); zipOutputStream.setEncoding(ENCODING); for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) { byte[] data = (byte[]) entry.getValue(); ArchiveEntry archiveEntry = newStoredEntry(entry.getKey(), data); zipOutputStream.putArchiveEntry(archiveEntry); zipOutputStream.write(data); zipOutputStream.closeArchiveEntry(); } zipOutputStream.close(); return byteArrayOutputStream.toByteArray(); }
@Override public byte[] exportEntitiesToZIP(Collection<? extends Entity> entities) { String json = entitySerialization.toJson(entities, null, EntitySerializationOption.COMPACT_REPEATED_ENTITIES); byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.STORED); zipOutputStream.setEncoding(StandardCharsets.UTF_8.name()); ArchiveEntry singleDesignEntry = newStoredEntry("entities.json", jsonBytes); try { zipOutputStream.putArchiveEntry(singleDesignEntry); zipOutputStream.write(jsonBytes); zipOutputStream.closeArchiveEntry(); } catch (Exception e) { throw new RuntimeException("Error on creating zip archive during entities export", e); } finally { IOUtils.closeQuietly(zipOutputStream); } return byteArrayOutputStream.toByteArray(); }
@Override public byte[] exportFolder(Folder folder) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.STORED); zipOutputStream.setEncoding(StandardCharsets.UTF_8.name()); String xml = createXStream().toXML(folder); byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8); ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes); zipOutputStream.putArchiveEntry(zipEntryDesign); zipOutputStream.write(xmlBytes); try { zipOutputStream.closeArchiveEntry(); } catch (Exception ex) { throw new RuntimeException(String.format("Exception occurred while exporting folder %s.", folder.getName())); } zipOutputStream.close(); return byteArrayOutputStream.toByteArray(); }
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); } ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); byte[] content = getTailBytes(logFile); ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content); zipOutputStream.putArchiveEntry(archiveEntry); zipOutputStream.write(content); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); }
@Override public byte[] exportReports(Collection<Report> reports) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream); try { zipOutputStream.setMethod(ZipArchiveOutputStream.STORED); zipOutputStream.setEncoding(ENCODING); for (Report report : reports) { try { byte[] reportBytes = exportReport(report); ArchiveEntry singleReportEntry = newStoredEntry(replaceForbiddenCharacters(report.getName()) + ".zip", reportBytes); zipOutputStream.putArchiveEntry(singleReportEntry); zipOutputStream.write(reportBytes); zipOutputStream.closeArchiveEntry(); } catch (IOException e) { throw new ReportingException(String.format("Exception occurred while exporting report [%s]", report.getName()), e); } } } finally { IOUtils.closeQuietly(zipOutputStream); } return byteArrayOutputStream.toByteArray(); }
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED); zipOutputStream.setEncoding(ReportImportExport.ENCODING);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.STORED); zipOutputStream.setEncoding(ENCODING);