public static void addFileToJar(JarOutputStream jar, File source, String entryName) throws IOException { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(source))) { JarEntry entry = new JarEntry(entryName); entry.setTime(source.lastModified()); jar.putNextEntry(entry); copyStream(in, jar); jar.closeEntry(); } }
private void createJar(String className, OutputStream outStream, byte[] bytes) throws IOException { JarOutputStream jarOutputStream = new JarOutputStream(outStream); // Add the class file to the JAR file String formattedName = className; if (!formattedName.endsWith(".class")) { formattedName = formattedName.concat(".class"); } JarEntry entry = new JarEntry(formattedName); entry.setTime(System.currentTimeMillis()); jarOutputStream.putNextEntry(entry); jarOutputStream.write(bytes); jarOutputStream.closeEntry(); jarOutputStream.close(); }
/** * Create a JAR using the given file contents and with the given file name. * * @param fileName Name of the file to create * @param content Content of the created file * @return The JAR file content * @throws IOException If there is a problem creating the output stream for the JAR file. */ public byte[] createJarFromFileContent(final String fileName, final String content) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); JarOutputStream jarOutputStream = new JarOutputStream(byteArrayOutputStream); JarEntry entry = new JarEntry(fileName); entry.setTime(System.currentTimeMillis()); jarOutputStream.putNextEntry(entry); jarOutputStream.write(content.getBytes()); jarOutputStream.closeEntry(); jarOutputStream.close(); return byteArrayOutputStream.toByteArray(); }
private void buildJar(File outputJarFile, List<CompiledSourceCode> compiledSourceCodes) throws IOException { assertThat(outputJarFile).doesNotExist(); try (FileOutputStream outputStream = new FileOutputStream(outputJarFile)) { JarOutputStream jarOutputStream = new JarOutputStream(outputStream); for (CompiledSourceCode compiledSource : compiledSourceCodes) { String formattedName = compiledSource.className.replace(".", "/"); if (!formattedName.endsWith(".class")) { formattedName = formattedName.concat(".class"); } JarEntry entry = new JarEntry(formattedName); entry.setTime(System.currentTimeMillis()); jarOutputStream.putNextEntry(entry); jarOutputStream.write(compiledSource.compiledBytecode); jarOutputStream.closeEntry(); } jarOutputStream.close(); } } }
outEntry.setTime(timestamp); out.putNextEntry(outEntry);
if (path != null) { JarEntry je = new JarEntry(subPath); je.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(je); jos.flush(); try { JarEntry entry = new JarEntry(path + dirOrFile2jar.getName()); entry.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(entry); while ((mByteCount = fis.read(mBuffer)) != -1) {
je.setTime(timestamp); outputJar.putNextEntry(je); manifest.write(outputJar); signature.initSign(privateKey); je = new JarEntry("META-INF/CERT.SF"); je.setTime(timestamp); outputJar.putNextEntry(je); writeSignatureFile(manifest, new SignatureOutputStream(outputJar, signature)); je.setTime(timestamp); outputJar.putNextEntry(je);
jarAdd.setTime(jarFile.lastModified()); out.putNextEntry(jarAdd);
jarAdd.setTime(tobeJared[i].lastModified()); out.putNextEntry(jarAdd);
private void addFile(String path, File file, JarOutputStream jar) throws IOException { try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) { JarEntry entry = new JarEntry(path); entry.setTime(file.lastModified()); jar.putNextEntry(entry); IOUtils.copy(in, jar); jar.closeEntry(); } }
if (path != null) { JarEntry je = new JarEntry(subPath); je.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(je); jos.flush(); try { JarEntry entry = new JarEntry(path+dirOrFile2jar.getName()); entry.setTime(dirOrFile2jar.lastModified()); jos.putNextEntry(entry); while ((mByteCount = fis.read(mBuffer)) != -1) {
private static void process(File file) throws IOException{ String name = file.getName().replaceAll("[\\/\\.]", "_"); JarEntry entry = new JarEntry(name); entry.setTime(time); jarOut.putNextEntry(entry); }
private static void write(String name, byte[] value, JarOutputStream target) throws IOException { name = name.replace(".", "/") + ".class"; JarEntry entry = new JarEntry(name); entry.setTime(System.currentTimeMillis()); target.putNextEntry(entry); target.write(value, 0, value.length); target.closeEntry(); }
private static void write(String name, byte[] value, JarOutputStream target) throws IOException { name = name.replace(".", "/") + ".class"; JarEntry entry = new JarEntry(name); entry.setTime(System.currentTimeMillis()); target.putNextEntry(entry); target.write(value, 0, value.length); target.closeEntry(); }
private static void copyFileToJar(JarOutputStream jarOS, Path rootDir, String targetDirPrefix, Path file) throws IOException { JarEntry fileEntry = new JarEntry(targetDirPrefix + rootDir.relativize(file).toString()); try { fileEntry.setTime(Files.getLastModifiedTime(file).toMillis()); } catch (IOException e) {} jarOS.putNextEntry(fileEntry); Files.copy(file, jarOS); jarOS.closeEntry(); }
private void addEntry(File file, String name) throws IOException { final JarEntry ze = new JarEntry(name); ze.setTime(file.lastModified()); jos.putNextEntry(ze); if (file.isFile()) { try (final FileInputStream input = new FileInputStream(file)) { IOUtils.copy(input, jos); } } jos.closeEntry(); } }
private void addResource( Set<String> resources, JarOutputStream jos, String name, long lastModified, InputStream is ) throws IOException { final JarEntry jarEntry = new JarEntry( name ); jarEntry.setTime( lastModified ); jos.putNextEntry( jarEntry ); IOUtil.copy( is, jos ); resources.add( name ); }
private JarEntry createJarEntry(Path source) throws IOException { String entryName = FilenameUtils.separatorsToUnix(mtaAssemblyDir.relativize(source) .toString()); if (source.toFile() .isDirectory() && !entryName.endsWith(Constants.UNIX_PATH_SEPARATOR)) { entryName += Constants.UNIX_PATH_SEPARATOR; } JarEntry entry = new JarEntry(entryName); entry.setTime(Files.getLastModifiedTime(source) .toMillis()); return entry; }
protected JarEntry createEntry(JarEntry rootEntry, JarEntry template) { if(rootEntry == null) return new JarEntry(template); String name = template.getName().substring(rootEntry.getName().length()); JarEntry entry = new JarEntry(name); entry.setComment(template.getComment()); entry.setSize(template.getSize()); entry.setTime(template.getTime()); return entry; }