List of usage examples for java.util.jar JarOutputStream flush
public void flush() throws IOException
From source file:org.jahia.modules.serversettings.portlets.BasePortletHelper.java
void copyEntries(JarInputStream source, JarOutputStream dest) throws IOException { JarEntry originalJarEntry = source.getNextJarEntry(); while (originalJarEntry != null) { final JarEntry newJarEntry = cloneEntry(originalJarEntry); dest.putNextEntry(newJarEntry);//from ww w . ja v a 2 s . c om if (!handled(originalJarEntry, source, dest)) { IOUtils.copy(source, dest); } dest.closeEntry(); dest.flush(); originalJarEntry = source.getNextJarEntry(); } }
From source file:org.kepler.kar.KARBuilder.java
/** * */// w w w . j a v a 2 s . c om private void writeKARFile() throws IOException { JarOutputStream jos = new JarOutputStream(new FileOutputStream(_karFile), _manifest); Iterator<KAREntry> li = _karItems.keySet().iterator(); while (li.hasNext()) { KAREntry entry = (KAREntry) li.next(); if (isDebugging) log.debug("Writing " + entry.getName()); try { jos.putNextEntry(entry); if (_karItems.get(entry) instanceof InputStream) { // inputstream from a bin file byte[] b = new byte[1024]; InputStream is = (InputStream) _karItems.get(entry); int numread = is.read(b, 0, 1024); while (numread != -1) { jos.write(b, 0, numread); numread = is.read(b, 0, 1024); } is.close(); // jos.flush(); jos.closeEntry(); } } catch (IOException ioe) { log.error(" Tried to write Duplicate Entry to kar " + entry.getName() + " " + entry.getLSID()); ioe.printStackTrace(); } } jos.flush(); jos.close(); log.info("done writing KAR file to " + _karFile.getAbsolutePath()); }
From source file:org.mule.util.JarUtils.java
public static void createJarFileEntries(File jarFile, LinkedHashMap entries) throws Exception { JarOutputStream jarStream = null; FileOutputStream fileStream = null; if (jarFile != null) { logger.debug("Creating jar file " + jarFile.getAbsolutePath()); try {/* w ww . j a va 2 s . co m*/ fileStream = new FileOutputStream(jarFile); jarStream = new JarOutputStream(fileStream); if (entries != null && !entries.isEmpty()) { Iterator iter = entries.keySet().iterator(); while (iter.hasNext()) { String jarFilePath = (String) iter.next(); Object content = entries.get(jarFilePath); JarEntry entry = new JarEntry(jarFilePath); jarStream.putNextEntry(entry); logger.debug("Adding jar entry " + jarFilePath + " to " + jarFile.getAbsolutePath()); if (content instanceof String) { writeJarEntry(jarStream, ((String) content).getBytes()); } else if (content instanceof byte[]) { writeJarEntry(jarStream, (byte[]) content); } else if (content instanceof File) { writeJarEntry(jarStream, (File) content); } } } jarStream.flush(); fileStream.getFD().sync(); } finally { if (jarStream != null) { try { jarStream.close(); } catch (Exception jarNotClosed) { logger.debug(jarNotClosed); } } if (fileStream != null) { try { fileStream.close(); } catch (Exception fileNotClosed) { logger.debug(fileNotClosed); } } } } }
From source file:org.sonatype.maven.plugin.emma4it.InstrumentProjectArtifactMojo.java
private void append(JarOutputStream output, File jar, boolean excludeMetainf) throws IOException { JarFile ejar = new JarFile(jar); Enumeration<JarEntry> entries = ejar.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); if (jarEntry.isDirectory() || (excludeMetainf && jarEntry.getName().startsWith("META-INF"))) { continue; }/*from w w w. ja v a 2 s . c o m*/ output.putNextEntry(jarEntry); InputStream input = ejar.getInputStream(jarEntry); try { IOUtil.copy(input, output); } finally { IOUtil.close(input); } output.flush(); } }
From source file:org.talend.designer.maven.utils.ClasspathsJarGenerator.java
public static String createJar(Property property, String classpath, String separator) throws Exception { String newClasspath = generateClasspathForManifest(classpath, separator); Manifest manifest = new Manifest(); Attributes a = manifest.getMainAttributes(); a.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //$NON-NLS-1$ a.put(Attributes.Name.IMPLEMENTATION_VENDOR, "Talend Open Studio"); //$NON-NLS-1$ a.put(Attributes.Name.CLASS_PATH, newClasspath); String jarLocation = getJarLocation(property); File jarFile = new File(jarLocation); if (!jarFile.exists()) { jarFile.createNewFile();/* w ww .j a v a 2s . c om*/ } JarOutputStream stream = null; try { stream = new JarOutputStream(new FileOutputStream(jarLocation), manifest); stream.flush(); } finally { stream.close(); } return getFinalClasspath(classpath, separator, jarLocation); }
From source file:org.wso2.carbon.automation.test.utils.common.FileManager.java
public void copyJarFile(String sourceFileLocationWithFileName, String destinationDirectory) throws IOException, URISyntaxException { File sourceFile = new File(getClass().getResource(sourceFileLocationWithFileName).toURI()); File destinationFileDirectory = new File(destinationDirectory); JarFile jarFile = new JarFile(sourceFile); String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); File destinationFile = new File(destinationFileDirectory, fileNameLastPart); JarOutputStream jarOutputStream = null; try {//from www.jav a2 s .c o m jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile)); Enumeration<JarEntry> entries = jarFile.entries(); InputStream inputStream = null; while (entries.hasMoreElements()) { try { JarEntry jarEntry = entries.nextElement(); inputStream = jarFile.getInputStream(jarEntry); //jarOutputStream.putNextEntry(jarEntry); //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { jarOutputStream.write(buffer, 0, bytesRead); } } finally { if (inputStream != null) { inputStream.close(); jarOutputStream.flush(); jarOutputStream.closeEntry(); } } } } finally { if (jarOutputStream != null) { jarOutputStream.close(); } } }
From source file:org.wso2.carbon.automation.test.utils.common.FileManager.java
public static void copyJarFile(File sourceFile, String destinationDirectory) throws IOException { File destinationFileDirectory = new File(destinationDirectory); JarFile jarFile = new JarFile(sourceFile); String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); File destinationFile = new File(destinationFileDirectory, fileNameLastPart); JarOutputStream jarOutputStream = null; try {/* w w w .j a va 2 s . c om*/ jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile)); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream inputStream = jarFile.getInputStream(jarEntry); //jarOutputStream.putNextEntry(jarEntry); //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { jarOutputStream.write(buffer, 0, bytesRead); } inputStream.close(); jarOutputStream.flush(); jarOutputStream.closeEntry(); } } finally { if (jarOutputStream != null) { try { jarOutputStream.close(); } catch (IOException e) { } } } }
From source file:org.wso2.carbon.integration.common.utils.FileManager.java
public void copyJarFile(String sourceFileLocationWithFileName, String destinationDirectory) throws URISyntaxException, IOException { File sourceFile = new File(getClass().getResource(sourceFileLocationWithFileName).toURI()); File destinationFileDirectory = new File(destinationDirectory); JarOutputStream jarOutputStream = null; InputStream inputStream = null; try {/*from w w w . j a v a 2s .c o m*/ JarFile jarFile = new JarFile(sourceFile); String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); File destinationFile = new File(destinationFileDirectory, fileNameLastPart); jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile)); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { try { JarEntry jarEntry = entries.nextElement(); inputStream = jarFile.getInputStream(jarEntry); //jarOutputStream.putNextEntry(jarEntry); //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { jarOutputStream.write(buffer, 0, bytesRead); } } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { log.warn("Fail to close jarOutStream"); } } if (jarOutputStream != null) { try { jarOutputStream.flush(); jarOutputStream.closeEntry(); } catch (IOException e) { log.warn("Error while closing jar out stream"); } } if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { log.warn("Error while closing jar file"); } } } } } finally { if (jarOutputStream != null) { try { jarOutputStream.close(); } catch (IOException e) { log.warn("Fail to close jarOutStream"); } } if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { log.warn("Error while closing input stream"); } } } }
From source file:org.wso2.carbon.integration.common.utils.FileManager.java
public static void copyJarFile(File sourceFile, String destinationDirectory) throws IOException { File destinationFileDirectory = new File(destinationDirectory); JarFile jarFile = new JarFile(sourceFile); String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); File destinationFile = new File(destinationFileDirectory, fileNameLastPart); JarOutputStream jarOutputStream = null; try {/*from w w w . ja v a 2s. c o m*/ jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile)); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream inputStream = jarFile.getInputStream(jarEntry); //jarOutputStream.putNextEntry(jarEntry); //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { jarOutputStream.write(buffer, 0, bytesRead); } inputStream.close(); jarOutputStream.flush(); jarOutputStream.closeEntry(); } } finally { if (jarOutputStream != null) { try { jarOutputStream.close(); } catch (IOException e) { //ignore } } } }
From source file:org.wso2.esb.integration.common.utils.common.FileManager.java
public void copyJarFile(String sourceFileLocationWithFileName, String destinationDirectory) throws IOException, URISyntaxException { File sourceFile = new File(getClass().getResource(sourceFileLocationWithFileName).toURI()); File destinationFileDirectory = new File(destinationDirectory); JarFile jarFile = new JarFile(sourceFile); String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); File destinationFile = new File(destinationFileDirectory, fileNameLastPart); JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(destinationFile)); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream inputStream = jarFile.getInputStream(jarEntry); //jarOutputStream.putNextEntry(jarEntry); //create a new jarEntry to avoid ZipException: invalid jarEntry compressed size jarOutputStream.putNextEntry(new JarEntry(jarEntry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { jarOutputStream.write(buffer, 0, bytesRead); }//from w w w.j a v a2 s .com inputStream.close(); jarOutputStream.flush(); jarOutputStream.closeEntry(); } jarOutputStream.close(); }