private static ZipEntrySource streamToEntrySource(InputStream stream, String path, int compressLevel) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[16384]; while ((nRead = stream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); return new ByteSource(path, buffer.toByteArray(), compressLevel); }
public boolean act(File tmpFile) { return replaceEntry(zip, new ByteSource(path, bytes), tmpFile); } });
public boolean act(File tmpFile) { return replaceEntry(zip, new ByteSource(path, bytes, compressionMethod), tmpFile); } });
/** * Copies an existing ZIP file and appends it with one new entry. * * @param zip * an existing ZIP file (only read). * @param path * new ZIP entry path. * @param bytes * new entry bytes (or <code>null</code> if directory). * @param destZip * new ZIP file created. */ public static void addEntry(File zip, String path, byte[] bytes, File destZip) { addEntry(zip, new ByteSource(path, bytes), destZip); }
/** * Copies an existing ZIP file and replaces a given entry in it. * * @param zip * an existing ZIP file (only read). * @param path * new ZIP entry path. * @param bytes * new entry bytes (or <code>null</code> if directory). * @param destZip * new ZIP file created. * @return <code>true</code> if the entry was replaced. */ public static boolean replaceEntry(File zip, String path, byte[] bytes, File destZip) { return replaceEntry(zip, new ByteSource(path, bytes), destZip); }
/** * Copies an existing ZIP file and appends it with one new entry. * * @param zip * an existing ZIP file (only read). * @param path * new ZIP entry path. * @param bytes * new entry bytes (or <code>null</code> if directory). * @param destZip * new ZIP file created. * @param compressionMethod * the new compression method (<code>ZipEntry.STORED</code> or <code>ZipEntry.DEFLATED</code>). */ public static void addEntry(File zip, String path, byte[] bytes, File destZip, final int compressionMethod) { addEntry(zip, new ByteSource(path, bytes, compressionMethod), destZip); }
public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { String data = IOUtils.toString(in, encoding); data = transform(zipEntry, data); byte[] bytes = encoding == null ? data.getBytes() : data.getBytes(encoding); ByteSource source = new ByteSource(zipEntry.getName(), bytes); ZipEntrySourceZipEntryTransformer.addEntry(source, out); }
/** * Transforms the zip entry given as an input stream and ZipEntry metadata. * The result is written to a ZipOutputStream * * @param in input stream of the entry contents * @param zipEntry zip entry metadata * @param out output stream to write transformed entry * * @throws IOException if anything goes wrong */ public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { byte[] bytes = IOUtils.toByteArray(in); bytes = transform(zipEntry, bytes); ByteSource source; if (preserveTimestamps()) { source = new ByteSource(zipEntry.getName(), bytes, zipEntry.getTime()); } else { source = new ByteSource(zipEntry.getName(), bytes); } ZipEntrySourceZipEntryTransformer.addEntry(source, out); }
@Signature public void addFromString(Environment env, String path, Memory string, int compressLevel) { ZipUtil.addOrReplaceEntries(zipFile, new ZipEntrySource[] { new ByteSource(path, string.getBinaryBytes(env.getDefaultCharset()), compressLevel) }); }
public ZipEntrySource create() { ZipEntrySource zipEntrySource; try (InputStream in = inputStream) { zipEntrySource = new ByteSource(name, IOUtils.toByteArray(in)); } catch (IOException e) { throw new RuntimeException(e); } return zipEntrySource; } }
public ZipEntrySource create() { ZipEntrySource zipEntrySource; try (InputStream in = inputStream) { zipEntrySource = new ByteSource(name, IOUtils.toByteArray(in)); } catch (IOException e) { throw new RuntimeException(e); } return zipEntrySource; } }
public boolean act(File tmpFile) { return replaceEntry(zip, new ByteSource(path, bytes), tmpFile); } });
public boolean act(File tmpFile) { return replaceEntry(zip, new ByteSource(path, bytes, compressionMethod), tmpFile); } });
/** * Copies an existing ZIP file and appends it with one new entry. * * @param zip * an existing ZIP file (only read). * @param path * new ZIP entry path. * @param bytes * new entry bytes (or <code>null</code> if directory). * @param destZip * new ZIP file created. */ public static void addEntry(File zip, String path, byte[] bytes, File destZip) { addEntry(zip, new ByteSource(path, bytes), destZip); }
/** * Copies an existing ZIP file and replaces a given entry in it. * * @param zip * an existing ZIP file (only read). * @param path * new ZIP entry path. * @param bytes * new entry bytes (or <code>null</code> if directory). * @param destZip * new ZIP file created. * @return <code>true</code> if the entry was replaced. */ public static boolean replaceEntry(File zip, String path, byte[] bytes, File destZip) { return replaceEntry(zip, new ByteSource(path, bytes), destZip); }
/** * Copies an existing ZIP file and appends it with one new entry. * * @param zip * an existing ZIP file (only read). * @param path * new ZIP entry path. * @param bytes * new entry bytes (or <code>null</code> if directory). * @param destZip * new ZIP file created. * @param compressionMethod * the new compression method (<code>ZipEntry.STORED</code> or <code>ZipEntry.DEFLATED</code>). */ public static void addEntry(File zip, String path, byte[] bytes, File destZip, final int compressionMethod) { addEntry(zip, new ByteSource(path, bytes, compressionMethod), destZip); }
private ZipEntrySource createZipEntrySource(Object item, Date lastModifiedDate, String zipEntryName, boolean useFileAttributes) { if (item instanceof File) { final File filePayload = (File) item; final String fileName = useFileAttributes ? filePayload.getName() : zipEntryName; if (((File) item).isDirectory()) { throw new UnsupportedOperationException("Zipping of directories is not supported."); } return new FileSource(fileName, filePayload); } else if (item instanceof byte[] || item instanceof String) { byte[] bytesToCompress = null; if (item instanceof String) { bytesToCompress = ((String) item).getBytes(this.charset); } else { bytesToCompress = (byte[]) item; } return new ByteSource(zipEntryName, bytesToCompress, lastModifiedDate.getTime()); } else { throw new IllegalArgumentException("Unsupported payload type. The only supported payloads are " + "java.io.File, java.lang.String, and byte[]"); } }
public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { String data = IOUtils.toString(in, encoding); data = transform(zipEntry, data); byte[] bytes = encoding == null ? data.getBytes() : data.getBytes(encoding); ByteSource source = new ByteSource(zipEntry.getName(), bytes); ZipEntrySourceZipEntryTransformer.addEntry(source, out); }
/** * Transforms the zip entry given as an input stream and ZipEntry metadata. * The result is written to a ZipOutputStream * * @param in input stream of the entry contents * @param zipEntry zip entry metadata * @param out output stream to write transformed entry * * @throws IOException if anything goes wrong */ public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { byte[] bytes = IOUtils.toByteArray(in); bytes = transform(zipEntry, bytes); ByteSource source; if (preserveTimestamps()) { source = new ByteSource(zipEntry.getName(), bytes, zipEntry.getTime()); } else { source = new ByteSource(zipEntry.getName(), bytes); } ZipEntrySourceZipEntryTransformer.addEntry(source, out); }