List of usage examples for org.apache.commons.compress.compressors.xz XZCompressorOutputStream close
@Override public void close() throws IOException
From source file:kr.debop4j.core.compress.XZCompressor.java
@Override protected byte[] doCompress(byte[] plain) throws IOException { @Cleanup/*from www.ja v a 2 s . c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); @Cleanup XZCompressorOutputStream xz = new XZCompressorOutputStream(bos); xz.write(plain); xz.close(); return bos.toByteArray(); }
From source file:com.espringtran.compressor4j.processor.XzProcessor.java
/** * Compress data//from w ww . j a v a2 s .c o m * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XZCompressorOutputStream cos = new XZCompressorOutputStream(baos); TarArchiveOutputStream aos = new TarArchiveOutputStream(cos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { TarArchiveEntry entry = new TarArchiveEntry(binaryFile.getDesPath()); entry.setSize(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(); cos.close(); baos.close(); } return baos.toByteArray(); }
From source file:org.jboss.tools.tycho.sitegenerator.GenerateRepositoryFacadeMojo.java
/** * Add p2 stats to the repository's artifacts.xml (and .jar and .xml.xz) * See http://wiki.eclipse.org/Equinox_p2_download_stats * /*www . j av a 2 s . c o m*/ * @param theXml * @param theXmlXz * @param transformer * @param source * @throws MojoFailureException * * */ private void alterXzFile(File theXml, File theXmlXz, Transformer transformer, DOMSource source) throws MojoFailureException { try { // JBDS-3929 overwrite the artifacts.xml.xz file too // see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=464614 //getLog().debug("delete " + theXmlXz.toString()); FileUtils.forceDelete(theXmlXz); //getLog().debug("create " + theXml.toString() + " from transformed XML"); FileOutputStream outStreamXml = new FileOutputStream(theXml); StreamResult resultXml = new StreamResult(outStreamXml); transformer.transform(source, resultXml); outStreamXml.close(); //getLog().debug("stream " + theXml.toString() + " to " + theXmlXz.toString()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(theXml)); XZCompressorOutputStream out = new XZCompressorOutputStream(new FileOutputStream(theXmlXz)); final byte[] buffer = new byte[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { out.write(buffer, 0, n); } out.close(); in.close(); //getLog().debug("new " + theXmlXz.toString() + " written; remove " + theXml.toString()); FileUtils.forceDelete(theXml); } catch (IOException | TransformerException ex) { getLog().error(ex); throw new MojoFailureException("Error while compressing " + theXml.toString(), ex); } }