public void build(final Path pathToExistingFile) throws Exception { try (final JarOutputStream output = buildPluginJar(pathToExistingFile, this.manifest)) { for (String entryName : new TreeSet<String>(this.entries.keySet())) { final Path pathToRealFile = this.entries.get(entryName); if (pathToRealFile == null) { final JarEntry entry = new JarEntry(entryName + "/"); entry.setMethod(JarEntry.STORED); entry.setSize(0); entry.setCrc(0); output.putNextEntry(entry); output.closeEntry(); } else { final JarEntry entry = new JarEntry(entryName); output.putNextEntry(entry); Files.copy(pathToRealFile, output); output.closeEntry(); } } } }
entry.setMethod(ZipEntry.DEFLATED); jarFile.putNextEntry(entry); streamOut = jarFile;
/** * Saves a directory entry to the jar output. */ private void saveDirEntry(String path, Set<String> entries, JarOutputStream jarOut) { if (entries.contains(path)) { return; } try { String entry = ""; for (String dir : Splitter.on('/').omitEmptyStrings().split(path)) { entry += dir + '/'; if (entries.add(entry)) { JarEntry jarEntry = new JarEntry(entry); jarEntry.setMethod(JarOutputStream.STORED); jarEntry.setSize(0L); jarEntry.setCrc(0L); jarOut.putNextEntry(jarEntry); jarOut.closeEntry(); } } } catch (IOException e) { throw Throwables.propagate(e); } }
/** * Saves a directory entry to the jar output. */ private void saveDirEntry(String path, Set<String> entries, JarOutputStream jarOut) { if (entries.contains(path)) { return; } try { String entry = ""; for (String dir : Splitter.on('/').omitEmptyStrings().split(path)) { entry += dir + '/'; if (entries.add(entry)) { JarEntry jarEntry = new JarEntry(entry); jarEntry.setMethod(JarOutputStream.STORED); jarEntry.setSize(0L); jarEntry.setCrc(0L); jarOut.putNextEntry(jarEntry); jarOut.closeEntry(); } } } catch (IOException e) { throw Throwables.propagate(e); } }
private void addFile(File file, IPath path) throws IOException { if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(path); JarEntry newEntry= new JarEntry(path.toString().replace(File.separatorChar, '/')); if (fJarPackage.isCompressed()) newEntry.setMethod(ZipEntry.DEFLATED); // Entry is filled automatically. else { newEntry.setMethod(ZipEntry.STORED); JarPackagerUtil.calculateCrcAndSize(newEntry, new FileInputStream(file), new byte[4096]); } newEntry.setTime(file.lastModified()); addEntry(newEntry, new FileInputStream(file)); } }
/** * Creates the directory entries for the given path and writes it to the current archive. * * @param destPath the path to add * * @throws IOException if an I/O error has occurred * @since 3.5 */ protected void addDirectories(String destPath) throws IOException { String path= destPath.replace(File.separatorChar, '/'); int lastSlash= path.lastIndexOf('/'); List<JarEntry> directories= new ArrayList<>(2); while (lastSlash != -1) { path= path.substring(0, lastSlash + 1); if (!fDirectories.add(path)) break; JarEntry newEntry= new JarEntry(path); newEntry.setMethod(ZipEntry.STORED); newEntry.setSize(0); newEntry.setCrc(0); newEntry.setTime(System.currentTimeMillis()); directories.add(newEntry); lastSlash= path.lastIndexOf('/', lastSlash - 1); } for (int i= directories.size() - 1; i >= 0; --i) { fJarOutputStream.putNextEntry(directories.get(i)); } }
private void addFile(File file, IPath path) throws IOException { if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(path); JarEntry newEntry= new JarEntry(path.toString().replace(File.separatorChar, '/')); if (fJarPackage.isCompressed()) newEntry.setMethod(ZipEntry.DEFLATED); // Entry is filled automatically. else { newEntry.setMethod(ZipEntry.STORED); JarPackagerUtil.calculateCrcAndSize(newEntry, new FileInputStream(file), new byte[4096]); } newEntry.setTime(file.lastModified()); addEntry(newEntry, new FileInputStream(file)); } }
public void setupStoredEntry(JarEntry entry) { entry.setSize(this.size); entry.setCompressedSize(this.size); entry.setCrc(this.crc.getValue()); entry.setMethod(ZipEntry.STORED); }
public void setupStoredEntry(JarEntry entry) { entry.setSize(this.size); entry.setCompressedSize(this.size); entry.setCrc(this.crc.getValue()); entry.setMethod(ZipEntry.STORED); }
@Override public void writeArchive(ZipFile jarFile, IProgressMonitor progressMonitor) { File jarPathFile= new File(jarFile.getName()); String jarName = jarPathFile.getName(); while (jarNames.contains(jarName)) { jarName= FatJarPackagerUtil.nextNumberedFileName(jarName); } jarNames.add(jarName); JarEntry newEntry = new JarEntry(jarName); newEntry.setMethod(ZipEntry.STORED); byte[] readBuffer= new byte[4096]; try { if (!fJarPackage.isCompressed()) JarPackagerUtil.calculateCrcAndSize(newEntry, new FileInputStream(jarPathFile), readBuffer); getJarWriter().addZipEntryStream(newEntry, new FileInputStream(jarPathFile), jarName); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void writeArchive(ZipFile jarFile, IProgressMonitor progressMonitor) { File jarPathFile= new File(jarFile.getName()); String jarName = jarPathFile.getName(); while (jarNames.contains(jarName)) { jarName= FatJarPackagerUtil.nextNumberedFileName(jarName); } jarNames.add(jarName); JarEntry newEntry = new JarEntry(jarName); newEntry.setMethod(ZipEntry.STORED); byte[] readBuffer= new byte[4096]; try { if (!fJarPackage.isCompressed()) JarPackagerUtil.calculateCrcAndSize(newEntry, new FileInputStream(jarPathFile), readBuffer); getJarWriter().addZipEntryStream(newEntry, new FileInputStream(jarPathFile), jarName); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException { if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(path); JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/')); if (fJarPackage.isCompressed()) newEntry.setMethod(ZipEntry.DEFLATED); // Entry is filled automatically. else { newEntry.setMethod(ZipEntry.STORED); newEntry.setSize(zipEntry.getSize()); newEntry.setCrc(zipEntry.getCrc()); } long lastModified= System.currentTimeMillis(); // Set modification time newEntry.setTime(lastModified); addEntry(newEntry, zipFile.getInputStream(zipEntry)); }
public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException { if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(path); JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/')); if (fJarPackage.isCompressed()) newEntry.setMethod(ZipEntry.DEFLATED); // Entry is filled automatically. else { newEntry.setMethod(ZipEntry.STORED); newEntry.setSize(zipEntry.getSize()); newEntry.setCrc(zipEntry.getCrc()); } long lastModified= System.currentTimeMillis(); // Set modification time newEntry.setTime(lastModified); addEntry(newEntry, zipFile.getInputStream(zipEntry)); }
public void addZipEntryStream(ZipEntry zipEntry, InputStream is, String path) throws IOException { if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(path); JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/')); if (fJarPackage.isCompressed()) newEntry.setMethod(ZipEntry.DEFLATED); // Entry is filled automatically. else { newEntry.setMethod(ZipEntry.STORED); newEntry.setSize(zipEntry.getSize()); newEntry.setCrc(zipEntry.getCrc()); } long lastModified= System.currentTimeMillis(); // Set modification time newEntry.setTime(lastModified); addEntry(newEntry, is); }
public void addZipEntryStream(ZipEntry zipEntry, InputStream is, String path) throws IOException { if (fJarPackage.areDirectoryEntriesIncluded()) addDirectories(path); JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/')); if (fJarPackage.isCompressed()) newEntry.setMethod(ZipEntry.DEFLATED); // Entry is filled automatically. else { newEntry.setMethod(ZipEntry.STORED); newEntry.setSize(zipEntry.getSize()); newEntry.setCrc(zipEntry.getCrc()); } long lastModified= System.currentTimeMillis(); // Set modification time newEntry.setTime(lastModified); addEntry(newEntry, is); }
/** * @param string * @param is * @throws IOException */ public void addContents(String entryName, InputStream is) throws IOException { ensureOpen(); if ( entriesSet.contains( entryName ) ){ //Duplicate entry return; } JarEntry entry = new JarEntry( entryName ); entry.setMethod( ZipEntry.DEFLATED ); CRC32 checksumCalculator= new CRC32(); ByteStreamCache bsc = new ByteStreamCache(); entry.setSize( StreamUtil.copyStream( is, bsc.getOutputStream() )); checksumCalculator.update( bsc.toByteArray() ); entry.setCrc(checksumCalculator.getValue()); jarOS.putNextEntry( entry ); //Now that we have the correct size, we can copy it to the jar stream StreamUtil.copyStream( bsc.getInputStream(), jarOS ); entriesSet.add( entryName ); }
private static void configureStoredEntry(JarEntry entry, File inputFile) throws IOException { ByteSource byteSource = Files.asByteSource(inputFile); long size = inputFile.length(); entry.setMethod(ZipEntry.STORED); entry.setSize(size); entry.setCompressedSize(size); entry.setCrc(byteSource.hash(Hashing.crc32()).padToLong()); }
private static JarEntry smartClone(JarEntry originalJarEntry) { final JarEntry newJarEntry = new JarEntry(originalJarEntry.getName()); newJarEntry.setComment(originalJarEntry.getComment()); newJarEntry.setExtra(originalJarEntry.getExtra()); newJarEntry.setMethod(originalJarEntry.getMethod()); newJarEntry.setTime(originalJarEntry.getTime()); //Must set size and CRC for STORED entries if (newJarEntry.getMethod() == ZipEntry.STORED) { newJarEntry.setSize(originalJarEntry.getSize()); newJarEntry.setCrc(originalJarEntry.getCrc()); } return newJarEntry; }
@Override public JarEntry transform(JarEntry entry) { JarEntry renamedEntry = new JarEntry(this.namePrefix + entry.getName()); renamedEntry.setTime(entry.getTime()); renamedEntry.setSize(entry.getSize()); renamedEntry.setMethod(entry.getMethod()); if (entry.getComment() != null) { renamedEntry.setComment(entry.getComment()); } renamedEntry.setCompressedSize(entry.getCompressedSize()); renamedEntry.setCrc(entry.getCrc()); //setCreationTimeIfPossible(entry, renamedEntry); if (entry.getExtra() != null) { renamedEntry.setExtra(entry.getExtra()); } return renamedEntry; }
@Override public JarEntry transform(JarEntry entry) { JarEntry renamedEntry = new JarEntry(this.namePrefix + entry.getName()); renamedEntry.setTime(entry.getTime()); renamedEntry.setSize(entry.getSize()); renamedEntry.setMethod(entry.getMethod()); if (entry.getComment() != null) { renamedEntry.setComment(entry.getComment()); } renamedEntry.setCompressedSize(entry.getCompressedSize()); renamedEntry.setCrc(entry.getCrc()); //setCreationTimeIfPossible(entry, renamedEntry); if (entry.getExtra() != null) { renamedEntry.setExtra(entry.getExtra()); } return renamedEntry; }