/** * Creates a sequence of FileSource objects via mapping * a sequence of files to the sequence of corresponding names * for the entries * @param files file array to form the data of the objects * in the resulting array * @param names file array to form the names of the objects * in the resulting array * @return array of FileSource objects created by mapping * given files array to the given names array one by one * @throws java.lang.IllegalArgumentException if the names array * contains less items than the files array */ public static FileSource[] pair(File[] files, String[] names) { if (files.length > names.length) { throw new IllegalArgumentException("names array must contain " + "at least the same amount of items as files array or more"); } FileSource[] result = new FileSource[files.length]; for(int i = 0; i < files.length; i++) { result[i] = new FileSource(names[i], files[i]); } return result; } }
/** * Create zip with provided list of files * * @param fileList list of files * @return */ public SystemFile createZip(List<SystemFile> fileList, String filename) throws IOException, NoSuchAlgorithmException { File[] files = new File[fileList.size()]; String[] filenames = new String[fileList.size()]; for (int i = 0; i < fileList.size(); i += 1) { files[i] = new File(fileList.get(i).getAbsoluteFileLocation()); filenames[i] = fileList.get(i).getFilenameWithExtension(); } FileSource[] s = FileSource.pair(files, filenames); File temp = File.createTempFile("file-zip", ".tmp"); ZipUtil.pack(s, temp); return storeInFileRepository(temp, filename, "zip", LocalDateTime.now().plusMinutes(10)); } }
public boolean act(File tmpFile) { return replaceEntry(zip, new FileSource(path, file), 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 file * new entry to be added. * @param destZip * new ZIP file created. */ public static void addEntry(File zip, String path, File file, File destZip) { addEntry(zip, new FileSource(path, file), 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 file * new entry. * @param destZip * new ZIP file created. * @return <code>true</code> if the entry was replaced. */ public static boolean replaceEntry(File zip, String path, File file, File destZip) { return replaceEntry(zip, new FileSource(path, file), destZip); }
this.changedEntries.add(new FileSource(file.getName(), file)); return this; entryPath = entryPath.substring(1); this.changedEntries.add(new FileSource(entryPath, entryFile));
/** * Copies the input stream to the file, then transforms the file. * FileSource is added then to the output stream. * * @param in * input stream of the entry contents * @param zipEntry * zip entry metadata * @param out * ignored, because we're working on files * * @throws IOException if anything goes wrong */ public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { File inFile = null; File outFile = null; try { inFile = File.createTempFile("zip", null); outFile = File.createTempFile("zip", null); copy(in, inFile); transform(zipEntry, inFile, outFile); FileSource source = new FileSource(zipEntry.getName(), outFile); ZipEntrySourceZipEntryTransformer.addEntry(source, out); } finally { FileUtils.deleteQuietly(inFile); FileUtils.deleteQuietly(outFile); } }
public ZipEntrySource create() { ZipEntrySource zipEntrySource; zipEntrySource = new FileSource(name, file); return zipEntrySource; } }
public ZipEntrySource create() { ZipEntrySource zipEntrySource; zipEntrySource = new FileSource(name, file); return zipEntrySource; } }
/** * Creates a sequence of FileSource objects via mapping * a sequence of files to the sequence of corresponding names * for the entries * @param files file array to form the data of the objects * in the resulting array * @param names file array to form the names of the objects * in the resulting array * @return array of FileSource objects created by mapping * given files array to the given names array one by one * @throws java.lang.IllegalArgumentException if the names array * contains less items than the files array */ public static FileSource[] pair(File[] files, String[] names) { if (files.length > names.length) { throw new IllegalArgumentException("names array must contain " + "at least the same amount of items as files array or more"); } FileSource[] result = new FileSource[files.length]; for(int i = 0; i < files.length; i++) { result[i] = new FileSource(names[i], files[i]); } return result; } }
public boolean act(File tmpFile) { return replaceEntry(zip, new FileSource(path, file), 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 file * new entry to be added. * @param destZip * new ZIP file created. */ public static void addEntry(File zip, String path, File file, File destZip) { addEntry(zip, new FileSource(path, file), 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 file * new entry. * @param destZip * new ZIP file created. * @return <code>true</code> if the entry was replaced. */ public static boolean replaceEntry(File zip, String path, File file, File destZip) { return replaceEntry(zip, new FileSource(path, file), 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[]"); } }
this.changedEntries.add(new FileSource(file.getName(), file)); return this; entryPath = entryPath.substring(1); this.changedEntries.add(new FileSource(entryPath, entryFile));
/** * Copies the input stream to the file, then transforms the file. * FileSource is added then to the output stream. * * @param in * input stream of the entry contents * @param zipEntry * zip entry metadata * @param out * ignored, because we're working on files * * @throws IOException if anything goes wrong */ public void transform(InputStream in, ZipEntry zipEntry, ZipOutputStream out) throws IOException { File inFile = null; File outFile = null; try { inFile = File.createTempFile("zip", null); outFile = File.createTempFile("zip", null); copy(in, inFile); transform(zipEntry, inFile, outFile); FileSource source = new FileSource(zipEntry.getName(), outFile); ZipEntrySourceZipEntryTransformer.addEntry(source, out); } finally { FileUtils.deleteQuietly(inFile); FileUtils.deleteQuietly(outFile); } }