List of usage examples for org.apache.commons.compress.compressors.xz XZCompressorOutputStream write
@Override public void write(final byte[] buf, final int off, final int len) throws IOException
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 * /*from w w w.j a v a 2 s. c om*/ * @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); } }