List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveOutputStream ArArchiveOutputStream
public ArArchiveOutputStream(final OutputStream pOut)
From source file:com.espringtran.compressor4j.processor.ArProcessor.java
/** * Compress data//from w ww . j a va2 s. com * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ArArchiveOutputStream aos = new ArArchiveOutputStream(baos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { ArArchiveEntry entry = new ArArchiveEntry(binaryFile.getDesPath(), binaryFile.getActualSize()); aos.putArchiveEntry(entry); aos.write(binaryFile.getData()); aos.closeArchiveEntry(); } aos.flush(); aos.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { aos.close(); baos.close(); } return baos.toByteArray(); }
From source file:com.moss.simpledeb.core.DebWriter.java
public void write(OutputStream out) throws Exception { if (out == null) { throw new NullPointerException(); }//w w w . j av a2 s . c om DebState state = new DebState(); for (DebAction action : pkg.actions()) { action.run(state); } ArArchiveOutputStream ar = new ArArchiveOutputStream(out); /* * Version */ byte[] versionData = "2.0\n".getBytes(); ArArchiveEntry versionEntry = new ArArchiveEntry("debian-binary", versionData.length, 0, 0, 0664, System.currentTimeMillis()); ar.putArchiveEntry(versionEntry); ar.write(versionData); ar.closeArchiveEntry(); /* * Control */ byte[] controlFileData = buildGzipTar(state.controlPaths); ArArchiveEntry controlEntry = new ArArchiveEntry("control.tar.gz", controlFileData.length, 0, 0, 0664, System.currentTimeMillis()); ar.putArchiveEntry(controlEntry); ar.write(controlFileData); ar.closeArchiveEntry(); /* * Data */ byte[] contentData = buildGzipTar(state.contentPaths); ArArchiveEntry contentEntry = new ArArchiveEntry("data.tar.gz", contentData.length, 0, 0, 0664, System.currentTimeMillis()); ar.putArchiveEntry(contentEntry); ar.write(contentData); ar.closeArchiveEntry(); ar.close(); }
From source file:com.kloudtek.buildmagic.tools.createinstaller.deb.CreateDebTask.java
@Override public void execute() throws BuildException { try {// w w w . j a v a 2 s.com prepare(); final ArArchiveOutputStream debFile = new ArArchiveOutputStream(new FileOutputStream(destfile)); // create debian-binary debFile.putArchiveEntry(new ArArchiveEntry("debian-binary", DEBVERSION.length)); debFile.write(DEBVERSION); debFile.closeArchiveEntry(); // create control.tar.gz DataBuffer controlFile = createControlArchive(); ArchiveHelper.write(debFile, controlFile, "control.tar.gz"); controlFile.clear(); // create data.tar.gz DataBuffer dataArchive = createDataArchive(); ArchiveHelper.write(debFile, dataArchive, "data.tar.gz"); dataArchive.clear(); debFile.close(); log("Created " + destfile.getPath()); } catch (RuntimeException e) { throw new BuildException(e); } catch (IOException e) { throw new BuildException(e); } finally { dataBufferManager.clear(); } }
From source file:com.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java
/** * Create debian package// w ww . java 2 s. c o m * * @param p Path to write to */ public String build(File p) throws Exception, IOException, FileNotFoundException { File ftemp; String fileName = m_packName + ".deb"; File filePack = new File(p, fileName); long sysTime = System.currentTimeMillis(); FileOutputStream fos = new FileOutputStream(filePack); BufferedOutputStream bos = new BufferedOutputStream(fos); ArArchiveOutputStream aros = new ArArchiveOutputStream(bos); byte[] debBin = { (byte) '2', (byte) '.', (byte) '0', (byte) 0x0a }; // Write the file 'debian-binary' aros.putArchiveEntry(new ArArchiveEntry("debian-binary", 4, 0, 0, 0x81a4, sysTime)); aros.write(debBin); aros.closeArchiveEntry(); // Create control.tar.gz ftemp = File.createTempFile(sysTime + "", "control.tar.gz"); doCreateControlTarGZip(ftemp); aros.putArchiveEntry(new ArArchiveEntry("control.tar.gz", ftemp.length(), 0, 0, 0x81a4, sysTime)); BuilderUtil.getInstance().copyFileToOutputStream(aros, ftemp); aros.closeArchiveEntry(); ftemp.delete(); // Create data.tar.gz ftemp = File.createTempFile(sysTime + "", "data.tar.gz"); doAddFilesToTarGZip(ftemp); aros.putArchiveEntry(new ArArchiveEntry("data.tar.gz", ftemp.length(), 0, 0, 0x81a4, sysTime)); BuilderUtil.getInstance().copyFileToOutputStream(aros, ftemp); aros.closeArchiveEntry(); ftemp.delete(); // Done aros.close(); bos.close(); fos.close(); // Return absolute path return filePack.getName(); }
From source file:org.apache.ant.compress.util.ArStreamFactory.java
/** * @param stream the stream to write to, should be buffered * @param encoding the encoding of the entry names, ignored *//*w w w .j a va 2 s . c o m*/ public ArchiveOutputStream getArchiveStream(OutputStream stream, String encoding) throws IOException { return new ArArchiveOutputStream(stream); }
From source file:org.apache.tika.parser.pkg.TikaArchiveStreamFactory.java
@Override public ArchiveOutputStream createArchiveOutputStream(final String archiverName, final OutputStream out, final String actualEncoding) throws ArchiveException { if (archiverName == null) { throw new IllegalArgumentException("Archivername must not be null."); }//from w ww . j a va 2 s .c om if (out == null) { throw new IllegalArgumentException("OutputStream must not be null."); } if (AR.equalsIgnoreCase(archiverName)) { return new ArArchiveOutputStream(out); } if (ZIP.equalsIgnoreCase(archiverName)) { final ZipArchiveOutputStream zip = new ZipArchiveOutputStream(out); if (actualEncoding != null) { zip.setEncoding(actualEncoding); } return zip; } if (TAR.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new TarArchiveOutputStream(out, actualEncoding); } return new TarArchiveOutputStream(out); } if (JAR.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new JarArchiveOutputStream(out, actualEncoding); } return new JarArchiveOutputStream(out); } if (CPIO.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new CpioArchiveOutputStream(out, actualEncoding); } return new CpioArchiveOutputStream(out); } if (SEVEN_Z.equalsIgnoreCase(archiverName)) { throw new StreamingNotSupportedException(SEVEN_Z); } final ArchiveStreamProvider archiveStreamProvider = getArchiveOutputStreamProviders() .get(toKey(archiverName)); if (archiveStreamProvider != null) { return archiveStreamProvider.createArchiveOutputStream(archiverName, out, actualEncoding); } throw new ArchiveException("Archiver: " + archiverName + " not found."); }
From source file:org.eclipse.packagedrone.utils.deb.build.DebianPackageWriter.java
public DebianPackageWriter(final OutputStream stream, final BinaryPackageControlFile packageControlFile) throws IOException { this.packageControlFile = packageControlFile; BinaryPackageControlFile.validate(packageControlFile); this.ar = new ArArchiveOutputStream(stream); this.ar.putArchiveEntry(new ArArchiveEntry("debian-binary", this.binaryHeader.length)); this.ar.write(this.binaryHeader); this.ar.closeArchiveEntry(); this.dataTemp = File.createTempFile("data", null); this.dataStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(this.dataTemp))); this.dataStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); }
From source file:org.eclipse.scada.utils.pkg.deb.DebianPackageWriter.java
public DebianPackageWriter(final OutputStream stream, final GenericControlFile packageControlFile, final TimestampProvider timestampProvider) throws IOException { this.packageControlFile = packageControlFile; this.timestampProvider = timestampProvider; if (getTimestampProvider() == null) { throw new IllegalArgumentException("'timestampProvider' must not be null"); }//from w w w .j a v a 2s . c om BinaryPackageControlFile.validate(packageControlFile); this.ar = new ArArchiveOutputStream(stream); this.ar.putArchiveEntry(new ArArchiveEntry("debian-binary", this.binaryHeader.length, 0, 0, AR_ARCHIVE_DEFAULT_MODE, getTimestampProvider().getModTime() / 1000)); this.ar.write(this.binaryHeader); this.ar.closeArchiveEntry(); this.dataTemp = File.createTempFile("data", null); this.dataStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(this.dataTemp))); this.dataStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); }
From source file:org.vafer.jdeb.ar.ArOutputStreamTestCase.java
public void testWrite() throws Exception { final File out1 = File.createTempFile("jdeb", ".ar"); final ArArchiveOutputStream os = new ArArchiveOutputStream(new FileOutputStream(out1)); os.putArchiveEntry(new ArArchiveEntry("data", 4)); os.write("data".getBytes()); os.closeArchiveEntry();//from w w w . ja va 2 s . c o m os.close(); assertTrue(out1.delete()); }
From source file:org.vafer.jdeb.DebMaker.java
/** * Create the debian archive with from the provided control files and data producers. * * @param pControlFiles/*from ww w.j a v a 2 s. co m*/ * @param pData * @param deb * @param compression the compression method used for the data file * @return BinaryPackageControlFile * @throws PackagingException */ public BinaryPackageControlFile createDeb(Compression compression) throws PackagingException { File tempData = null; File tempControl = null; try { tempData = File.createTempFile("deb", "data"); tempControl = File.createTempFile("deb", "control"); console.info("Building data"); DataBuilder dataBuilder = new DataBuilder(console); StringBuilder md5s = new StringBuilder(); BigInteger size = dataBuilder.buildData(dataProducers, tempData, md5s, compression); console.info("Building control"); ControlBuilder controlBuilder = new ControlBuilder(console, variableResolver); BinaryPackageControlFile packageControlFile = controlBuilder .createPackageControlFile(new File(control, "control"), size); if (packageControlFile.get("Package") == null) { packageControlFile.set("Package", packageName); } if (packageControlFile.get("Depends") == null) { packageControlFile.set("Depends", depends); } if (packageControlFile.get("Section") == null) { packageControlFile.set("Section", section); } if (packageControlFile.get("Description") == null) { packageControlFile.set("Description", description); } if (packageControlFile.get("Homepage") == null) { packageControlFile.set("Homepage", homepage); } controlBuilder.buildControl(packageControlFile, control.listFiles(), md5s, tempControl); if (!packageControlFile.isValid()) { throw new PackagingException("Control file fields are invalid " + packageControlFile.invalidFields() + ". The following fields are mandatory: " + packageControlFile.getMandatoryFields() + ". Please check your pom.xml/build.xml and your control file."); } deb.getParentFile().mkdirs(); ArArchiveOutputStream ar = new ArArchiveOutputStream(new FileOutputStream(deb)); addTo(ar, "debian-binary", "2.0\n"); addTo(ar, "control.tar.gz", tempControl); addTo(ar, "data.tar" + compression.getExtension(), tempData); ar.close(); return packageControlFile; } catch (Exception e) { throw new PackagingException("Could not create deb package", e); } finally { if (tempData != null) { if (!tempData.delete()) { console.warn("Could not delete the temporary file " + tempData); } } if (tempControl != null) { if (!tempControl.delete()) { console.warn("Could not delete the temporary file " + tempControl); } } } }