List of usage examples for org.apache.commons.compress.archivers.cpio CpioArchiveOutputStream CpioArchiveOutputStream
public CpioArchiveOutputStream(final OutputStream out)
From source file:com.espringtran.compressor4j.processor.CpioProcessor.java
/** * Compress data//from ww w . j a va 2 s. c o m * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CpioArchiveOutputStream aos = new CpioArchiveOutputStream(baos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { CpioArchiveEntry entry = new CpioArchiveEntry(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:ch.ledcom.jpreseed.InitrdRepacker.java
public final void repack(OutputStream out) throws IOException { // start new archive try (CpioArchiveInputStream cpioIn = new CpioArchiveInputStream(new GZIPInputStream(initrdGz)); CpioArchiveOutputStream cpioOut = new CpioArchiveOutputStream(new GZIPOutputStream(out))) { CpioArchiveEntry cpioEntry;/*w ww. j av a 2 s . c o m*/ // add files from base archive while ((cpioEntry = cpioIn.getNextCPIOEntry()) != null) { if (!additionalFiles.keySet().contains(cpioEntry.getName())) { logger.info("Repacking [{}]", cpioEntry.getName()); cpioOut.putArchiveEntry(cpioEntry); long bytesCopied = copy(cpioIn, cpioOut); cpioOut.closeArchiveEntry(); logger.debug("Copied [{}] bytes", bytesCopied); } } // additional files for (Map.Entry<String, File> entry : additionalFiles.entrySet()) { logger.info("Packing new file [{}]", entry.getKey()); ArchiveEntry additionalEntry = cpioOut.createArchiveEntry(entry.getValue(), entry.getKey()); cpioOut.putArchiveEntry(additionalEntry); try (InputStream in = new FileInputStream(entry.getValue())) { copy(in, cpioOut); } cpioOut.closeArchiveEntry(); } } }