List of usage examples for org.apache.commons.compress.archivers.tar TarInputStream TarInputStream
public TarInputStream(final InputStream input)
From source file:ch.randelshofer.cubetwister.PreferencesTemplatesPanel.java
private void exportInternalTemplate(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportInternalTemplate if (exportFileChooser == null) { exportFileChooser = new JFileChooser(); exportFileChooser.setFileFilter(new ExtensionFileFilter("zip", "Zip Archive")); exportFileChooser.setSelectedFile( new File(userPrefs.get("cubetwister.exportedHTMLTemplate", "CubeTwister HTML-Template.zip"))); exportFileChooser.setApproveButtonText(labels.getString("filechooser.export")); }//from w w w . ja v a 2s . c om if (JFileChooser.APPROVE_OPTION == exportFileChooser.showSaveDialog(this)) { userPrefs.put("cubetwister.exportedHTMLTemplate", exportFileChooser.getSelectedFile().getPath()); final File target = exportFileChooser.getSelectedFile(); new BackgroundTask() { @Override public void construct() throws IOException { if (!target.getParentFile().exists()) { target.getParentFile().mkdirs(); } InputStream in = null; OutputStream out = null; try { in = getClass().getResourceAsStream("/htmltemplates.tar.bz"); out = new FileOutputStream(target); exportTarBZasZip(in, out); } finally { try { if (in != null) { in.close(); } } finally { if (out != null) { out.close(); } } } } private void exportTarBZasZip(InputStream in, OutputStream out) throws IOException { ZipOutputStream zout = new ZipOutputStream(out); TarInputStream tin = new TarInputStream(new BZip2CompressorInputStream(in)); for (TarArchiveEntry inEntry = tin.getNextEntry(); inEntry != null;) { ZipEntry outEntry = new ZipEntry(inEntry.getName()); zout.putNextEntry(outEntry); if (!inEntry.isDirectory()) { Files.copyStream(tin, zout); } zout.closeEntry(); } zout.finish(); } }.start(); } }
From source file:ch.randelshofer.cubetwister.HTMLExporter.java
private void processHTMLTemplates(ProgressObserver p) throws IOException { TarInputStream tin = null;//from w w w . j av a 2 s. c o m try { InputStream in = getClass().getResourceAsStream("/htmltemplates.tar.bz"); in.read(); // skip header chars; in.read(); tin = new TarInputStream(new BZip2CompressorInputStream(in)); for (TarArchiveEntry entry = tin.getNextEntry(); entry != null && !p.isCanceled();) { if (entry.isDirectory()) { //System.out.println("dir:" + entry.getName()); } else { //System.out.println("file:"+entry.getName()); String name = entry.getName(); if (name.indexOf("${cube}") != -1) { processCubeTemplate(name, toTokens(name, tin)); } else if (name.indexOf("${notation}") != -1) { processNotationTemplate(name, toTokens(name, tin)); } else if (name.indexOf("${script}") != -1) { processScriptTemplate(name, toTokens(name, tin)); } else if (name.indexOf("${note}") != -1) { processNoteTemplate(name, toTokens(name, tin)); } else if (name.endsWith(".html")) { processHTMLTemplate(name, toTokens(name, tin)); } else if (name.endsWith(".jar.pack.gz")) { processPack200Template(name, tin); } else { processBinaryTemplate(name, tin); } } entry = tin.getNextEntry(); } } finally { if (tin != null) { tin.close(); } } }
From source file:ch.randelshofer.cubetwister.HTMLExporter.java
private int countHTMLTemplates(ProgressObserver p) throws IOException { int count = 0; HashSet<CubeKind> cubeKinds = new HashSet<CubeKind>(); EntityModel dmtn = model.getChild(model.getRoot(), DocumentModel.CUBE_INDEX); for (EntityModel node : dmtn.getChildren()) { CubeModel cm = (CubeModel) node; cubeKinds.add(cm.getKind());//w ww .j ava2 s. com } int cubeCount = dmtn.getChildCount(); dmtn = model.getChild(model.getRoot(), DocumentModel.NOTATION_INDEX); int notationCount = dmtn.getChildCount(); dmtn = model.getChild(model.getRoot(), DocumentModel.SCRIPT_INDEX); int scriptCount = dmtn.getChildCount(); dmtn = model.getChild(model.getRoot(), DocumentModel.TEXT_INDEX); int textCount = dmtn.getChildCount(); TarInputStream tin = null; try { InputStream in = getClass().getResourceAsStream("/htmltemplates.tar.bz"); in.read(); // skip header chars; in.read(); tin = new TarInputStream(new BZip2CompressorInputStream(in)); for (TarArchiveEntry entry = tin.getNextEntry(); entry != null && !p.isCanceled();) { if (entry.isDirectory()) { //System.out.println("dir:" + entry.getName()); } else { //System.out.println("file:"+entry.getName()); String name = entry.getName(); if (name.indexOf("${cube}") != -1) { count += cubeCount; } else if (name.indexOf("${notation}") != -1) { count += notationCount; } else if (name.indexOf("${script}") != -1) { count += scriptCount; } else if (name.indexOf("${note}") != -1) { count += textCount; } else if (name.endsWith(".html")) { count++; } else if (name.endsWith(".jar.pack.gz")) { count++; } else { count++; } } entry = tin.getNextEntry(); } } finally { if (tin != null) { tin.close(); } } return count; }