List of usage examples for java.util.jar JarEntry JarEntry
public JarEntry(JarEntry je)
JarEntry
with fields taken from the specified JarEntry
object. From source file:com.streamsets.datacollector.cluster.TestTarFileCreator.java
private File createJar(File parentDir) throws IOException { if (parentDir.isFile()) { parentDir.delete();/*from ww w . j av a 2 s . c o m*/ } parentDir.mkdirs(); Assert.assertTrue(parentDir.isDirectory()); String uuid = UUID.randomUUID().toString(); File jar = new File(parentDir, uuid + ".jar"); JarOutputStream out = new JarOutputStream(new FileOutputStream(jar)); JarEntry entry = new JarEntry("sample.txt"); out.putNextEntry(entry); out.write(uuid.getBytes(StandardCharsets.UTF_8)); out.closeEntry(); out.close(); return jar; }
From source file:JarBuilder.java
/** Makes a directory in the jar file * * @param parent The name of the parent that the directory is to be created in * @param dirName The name of the directory to be created * @return Returns true on success, false on failure *///from w w w . j a v a2s .c om public boolean makeDirectory(String parent, String dirName) { JarEntry entry = new JarEntry(makeName(parent, dirName)); try { _output.putNextEntry(entry); } catch (IOException e) { return false; } return true; }
From source file:averroes.JarFile.java
/** * Add the file read from the source input stream with the given entry name * to this JAR file./* w ww .ja v a 2s .c o m*/ * * @param source * @param entryName * @throws IOException */ public void add(InputStream source, String entryName) throws IOException { JarEntry entry = new JarEntry(entryName); entry.setTime(System.currentTimeMillis()); getJarOutputStream().putNextEntry(entry); byte[] buffer = new byte[1024]; int len; while ((len = source.read(buffer)) != -1) { getJarOutputStream().write(buffer, 0, len); } getJarOutputStream().closeEntry(); source.close(); }
From source file:de.tobiasroeser.maven.featurebuilder.FeatureBuilder.java
private boolean createFeatureJar(final String featureId, final String featureVersion, final String featureXml, final String jarDir) { final File file = new File(jarDir, featureId + "_" + featureVersion + ".jar"); file.getParentFile().mkdirs();//from w w w. ja v a 2s . com try { final JarOutputStream jarOutputStream = new JarOutputStream( new BufferedOutputStream(new FileOutputStream(file))); final JarEntry entry = new JarEntry("feature.xml"); jarOutputStream.putNextEntry(entry); final BufferedInputStream featureXmlStream = new BufferedInputStream(new FileInputStream(featureXml)); copy(featureXmlStream, jarOutputStream); jarOutputStream.close(); } catch (final FileNotFoundException e) { throw new RuntimeException("Could not create Feature Jar: " + file.getAbsolutePath(), e); } catch (final IOException e) { throw new RuntimeException("Could not create Feature Jar: " + file.getAbsolutePath(), e); } return true; }
From source file:gov.nih.nci.restgen.util.GeneratorUtil.java
private static void add(File source, JarOutputStream target) throws IOException { BufferedInputStream in = null; try {// w ww. j a v a2s . c o m if (source.isDirectory()) { String name = source.getPath().replace("\\", "/"); if (!name.isEmpty()) { if (!name.endsWith("/")) name += "/"; JarEntry entry = new JarEntry(name); entry.setTime(source.lastModified()); target.putNextEntry(entry); target.closeEntry(); } for (File nestedFile : source.listFiles()) add(nestedFile, target); return; } JarEntry entry = new JarEntry(source.getPath().replace("\\", "/")); entry.setTime(source.lastModified()); target.putNextEntry(entry); in = new BufferedInputStream(new FileInputStream(source)); byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) break; target.write(buffer, 0, count); } target.closeEntry(); } finally { if (in != null) in.close(); } }
From source file:com.alu.e3.prov.service.ApiJarBuilder.java
protected void addJarEntry(List<JarEntryData> entries, byte[] bytes, String entryName) throws IOException { JarEntry anEntry = new JarEntry(entryName); JarEntryData data = new JarEntryData(); data.bytes = bytes;/*from ww w. j ava2 s . com*/ data.jarEntry = anEntry; entries.add(data); }
From source file:com.glaf.core.util.ZipUtils.java
public static byte[] getZipBytes(Map<String, InputStream> dataMap) { byte[] bytes = null; try {//from w w w. j a v a 2s . c om ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); JarOutputStream jos = new JarOutputStream(bos); if (dataMap != null) { Set<Entry<String, InputStream>> entrySet = dataMap.entrySet(); for (Entry<String, InputStream> entry : entrySet) { String name = entry.getKey(); InputStream inputStream = entry.getValue(); if (name != null && inputStream != null) { BufferedInputStream bis = new BufferedInputStream(inputStream); JarEntry jarEntry = new JarEntry(name); jos.putNextEntry(jarEntry); while ((len = bis.read(buf)) >= 0) { jos.write(buf, 0, len); } bis.close(); jos.closeEntry(); } } } jos.flush(); jos.close(); bos.flush(); bos.close(); bytes = baos.toByteArray(); baos.close(); return bytes; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.germinus.easyconf.FileUtil.java
public static void writeAsJAR(File dest, String propsFileName, Properties props) throws FileNotFoundException, IOException { JarOutputStream out = new JarOutputStream(new FileOutputStream(dest)); JarEntry propertiesFile = new JarEntry(propsFileName); propertiesFile.setExtra(propertiesToString(props).getBytes()); out.putNextEntry(propertiesFile);//from w ww . java 2 s .c o m out.close(); }
From source file:interactivespaces.workbench.project.java.BndOsgiContainerBundleCreator.java
/** * Write out the contents of the folder to the distribution file. * * @param directory/*from w ww .jav a2 s . co m*/ * folder being written to the build * @param buf * a buffer for caching info * @param jarOutputStream * the stream where the jar is being written * @param parentPath * path up to this point * * @throws IOException * for IO access errors */ private void writeJarFile(File directory, byte[] buf, ZipOutputStream jarOutputStream, String parentPath) throws IOException { File[] files = directory.listFiles(); if (files == null || files.length == 0) { log.warn("No source files found in " + directory.getAbsolutePath()); return; } for (File file : files) { if (file.isDirectory()) { writeJarFile(file, buf, jarOutputStream, parentPath + file.getName() + "/"); } else { FileInputStream in = null; try { in = new FileInputStream(file); // Add ZIP entry to output stream. jarOutputStream.putNextEntry(new JarEntry(parentPath + file.getName())); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { jarOutputStream.write(buf, 0, len); } // Complete the entry jarOutputStream.closeEntry(); } finally { fileSupport.close(in, false); } } } }
From source file:gov.nih.nci.restgen.util.GeneratorUtil.java
public static void createJarArchive(File jarFile, File[] listFiles) throws IOException { byte b[] = new byte[10240]; FileOutputStream fout = new FileOutputStream(jarFile); JarOutputStream out = new JarOutputStream(fout, new Manifest()); for (int i = 0; i < listFiles.length; i++) { if (listFiles[i] == null || !listFiles[i].exists() || listFiles[i].isDirectory()) { System.out.println(); }/*from ww w .j a v a 2s .c o m*/ JarEntry addFiles = new JarEntry(listFiles[i].getName()); addFiles.setTime(listFiles[i].lastModified()); out.putNextEntry(addFiles); FileInputStream fin = new FileInputStream(listFiles[i]); while (true) { int len = fin.read(b, 0, b.length); if (len <= 0) break; out.write(b, 0, len); } fin.close(); } out.close(); fout.close(); }