List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveOutputStream write
private long write(final String data) throws IOException
From source file:com.espringtran.compressor4j.processor.ArProcessor.java
/** * Compress data/*from w w w. j a v a2s . c o m*/ * * @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 a v a 2s. c o m*/ 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.mobilesorcery.sdk.builder.linux.deb.DebBuilder.java
/** * Create debian package//ww w. j a v a 2 s .c om * * @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:com.kloudtek.buildmagic.tools.createinstaller.deb.CreateDebTask.java
@Override public void execute() throws BuildException { try {//from w ww .ja va 2 s .c om 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: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();/*w ww. j av a 2s .c o m*/ os.close(); assertTrue(out1.delete()); }
From source file:org.vafer.jdeb.DebMaker.java
private void addTo(ArArchiveOutputStream pOutput, String pName, String pContent) throws IOException { final byte[] content = pContent.getBytes(); pOutput.putArchiveEntry(new ArArchiveEntry(pName, content.length)); pOutput.write(content); pOutput.closeArchiveEntry();/*from ww w .j ava 2 s . c o m*/ }
From source file:org.vafer.jdeb.Processor.java
private void addTo(final ArArchiveOutputStream pOutput, final String pName, final String pContent) throws IOException { final byte[] content = pContent.getBytes(); pOutput.putArchiveEntry(new ArArchiveEntry(pName, content.length)); pOutput.write(content); pOutput.closeArchiveEntry();// w w w. j a v a2 s . c o m }