List of usage examples for org.apache.commons.compress.archivers ArchiveException printStackTrace
public void printStackTrace()
From source file:io.github.retz.executor.FileManager.java
static void fetchPersistentFiles(List<String> files, String destination, boolean trustPVFiles) throws IOException { for (String file : files) { java.nio.file.Path path = Paths.get(file).getFileName(); if (path == null) { throw new FileSystemException(destination); }/*from w w w. java 2 s. c o m*/ File f = new File(FilenameUtils.concat(destination, path.toString())); LOG.info("Downloading: {} as {}", file, f); if (f.exists()) { LOG.debug("File already exists: {}", f); if (!trustPVFiles) { try { boolean needsDecompression = needsDecompression(f, destination); if (needsDecompression) { decompress(f, destination); } else { LOG.info("File {} was correctly decompressed before. Skipping decompression.", file); } } catch (ArchiveException e) { LOG.error("ArchiveException on {}: {}", f, e.getMessage()); e.printStackTrace(); } } } else if (file.startsWith("http")) { fetchHTTPFile(file, destination); decompress(f, destination); } else if (file.startsWith("hdfs://")) { fetchHDFSFile(file, destination); decompress(f, destination); } else if (file.startsWith("maprfs://")) { fetchHDFSFile(file, destination); decompress(f, destination); } else { LOG.error("Invalid URL scheme: {}", file); } } }
From source file:org.onebusaway.webapp.actions.admin.bundles.SyncBundleAction.java
private void unzipBundle(String tmpDir, String bundleFileName) throws IOException { byte[] buffer = new byte[1024]; GZIPInputStream zipIn = new GZIPInputStream(new FileInputStream(tmpDir + File.separator + bundleFileName)); FileOutputStream out = new FileOutputStream(tmpDir + File.separator + "unzippedBundle"); int len;//from w w w.j a v a2 s. c o m while ((len = zipIn.read(buffer)) > 0) { out.write(buffer, 0, len); } zipIn.close(); out.close(); // Now to untar the unzipped file File tarFile = new File(tmpDir + File.separator + "unzippedBundle"); File untarredFile = new File(tmpDir + File.separator + "untarredBundle"); //File untarredFile = new File(tmpDir); try { List<File> fileList = (new FileUtility()).unTar(tarFile, untarredFile); } catch (ArchiveException e) { // TODO Auto-generated catch block e.printStackTrace(); } return; }
From source file:org.openbaton.nfvo.core.api.VNFPackageManagement.java
@Override public VirtualNetworkFunctionDescriptor onboard(byte[] pack, String projectId) throws IOException, VimException, NotFoundException, PluginException, IncompatibleVNFPackage, AlreadyExistingException, NetworkServiceIntegrityException { log.info("Onboarding VNF Package..."); VNFPackage vnfPackage = new VNFPackage(); vnfPackage.setScripts(new HashSet<Script>()); Map<String, Object> metadata = null; VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor = null; byte[] imageFile = null; NFVImage image = new NFVImage(); InputStream tarStream;//from w w w . ja v a2 s.c om ArchiveInputStream myTarFile; try { tarStream = new ByteArrayInputStream(pack); myTarFile = new ArchiveStreamFactory().createArchiveInputStream("tar", tarStream); } catch (ArchiveException e) { e.printStackTrace(); throw new IOException(); } TarArchiveEntry entry; Map<String, Object> imageDetails = new HashMap<>(); while ((entry = (TarArchiveEntry) myTarFile.getNextEntry()) != null) { /* Get the name of the file */ if (entry.isFile() && !entry.getName().startsWith("./._")) { log.debug("file inside tar: " + entry.getName()); byte[] content = new byte[(int) entry.getSize()]; myTarFile.read(content, 0, content.length); if (entry.getName().equals("Metadata.yaml")) { YamlJsonParser yaml = new YamlJsonParser(); metadata = yaml.parseMap(new String(content)); imageDetails = handleMetadata(metadata, vnfPackage, imageDetails, image); } else if (!entry.getName().startsWith("scripts/") && entry.getName().endsWith(".json")) { //this must be the vnfd //and has to be onboarded in the catalogue String json = new String(content); log.trace("Content of json is: " + json); try { virtualNetworkFunctionDescriptor = mapper.fromJson(json, VirtualNetworkFunctionDescriptor.class); } catch (Exception e) { e.printStackTrace(); } int i = 1; for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) { if (vdu.getName() == null) { vdu.setName(virtualNetworkFunctionDescriptor.getName() + "-" + i); i++; } } for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) { log.debug("vdu name: " + vdu.getName()); } log.debug("Created VNFD: " + virtualNetworkFunctionDescriptor.getName()); log.trace("Created VNFD: " + virtualNetworkFunctionDescriptor); nsdUtils.fetchVimInstances(virtualNetworkFunctionDescriptor, projectId); } else if (entry.getName().endsWith(".img")) { //this must be the image //and has to be upladed to the RIGHT vim imageFile = content; log.debug("imageFile is: " + entry.getName()); throw new VimException( "Uploading an image file from the VNFPackage is not supported at this moment. Please use the image link" + "."); } else if (entry.getName().startsWith("scripts/")) { Script script = new Script(); script.setName(entry.getName().substring(8)); script.setPayload(content); vnfPackage.getScripts().add(script); } } } handleImage(vnfPackage, imageFile, virtualNetworkFunctionDescriptor, metadata, image, imageDetails, projectId); vnfPackage.setImage(image); myTarFile.close(); virtualNetworkFunctionDescriptor.setProjectId(projectId); vnfPackage.setProjectId(projectId); for (VirtualNetworkFunctionDescriptor vnfd : vnfdRepository.findByProjectId(projectId)) { if (vnfd.getVendor().equals(virtualNetworkFunctionDescriptor.getVendor()) && vnfd.getName().equals(virtualNetworkFunctionDescriptor.getName()) && vnfd.getVersion().equals(virtualNetworkFunctionDescriptor.getVersion())) { throw new AlreadyExistingException("A VNF with this vendor, name and version is already existing"); } } nsdUtils.checkIntegrity(virtualNetworkFunctionDescriptor); vnfPackageRepository.save(vnfPackage); virtualNetworkFunctionDescriptor.setVnfPackageLocation(vnfPackage.getId()); virtualNetworkFunctionDescriptor = vnfdRepository.save(virtualNetworkFunctionDescriptor); log.trace("Persisted " + virtualNetworkFunctionDescriptor); log.trace("Onboarded VNFPackage (" + virtualNetworkFunctionDescriptor.getVnfPackageLocation() + ") successfully"); return virtualNetworkFunctionDescriptor; }
From source file:tikatest.Investigation.java
/** * Takes a file which has already been detected as a supported archive and * displays the contents./*w ww .ja v a 2 s. c om*/ * <p>This method makes use of code which has been publicly available through * the Apache website. * @param The file to be inspected * @see java.io.BufferedInputStream */ private void handleGeneric(BufferedInputStream bis) { try { // File type is a known archive type and we can work with it (fingers crossed) ArchiveInputStream aisInput = new ArchiveStreamFactory().createArchiveInputStream(bis); ArchiveEntry aeFile = aisInput.getNextEntry(); System.out.println("ArchiveInputStream: " + aisInput.getClass().getName()); System.out.println("Archive Entry - Type: " + aeFile.getClass().getName()); while (aeFile != null) { if (!aeFile.isDirectory()) { String[] segments = aeFile.getName().split("\\/"); String filename = ""; for (String segment : segments) { filename = segment; } System.out.println("Archive Entry - Name: " + filename); } aeFile = aisInput.getNextEntry(); } } catch (ArchiveException aX) { aX.printStackTrace(); } catch (IOException ioX) { ioX.printStackTrace(); } }
From source file:uk.ac.ebi.metabolights.utils.ZipperTest.java
@Test public void testZip() throws IOException { final String EXPECTED_ZIP_MAP = "TMP/test\n" + "TMP/test/a.txt\n" + "TMP/test/folder\n" + "TMP/test/folder/b.txt"; String[] expectedMap = map2FileSystem(EXPECTED_ZIP_MAP); String folderToZip = expectedMap[0]; String tmpDir = System.getProperty("java.io.tmpdir"); File zipFile = new File(tmpDir + "zipTest.zip"); File unzipFolder = new File(zipFile.getAbsolutePath().replace(".zip", "")); FileUtil.deleteDir(zipFile);/*from w w w . ja v a 2s . c o m*/ FileUtil.deleteDir(unzipFolder); try { //Test the zip command Zipper.zip(folderToZip, zipFile.getAbsolutePath()); //Test the unzip command Zipper.unzip(zipFile.getAbsolutePath()); } catch (IOException ioe) { fail(ioe.getMessage()); } catch (ArchiveException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } //Check the output files and folders are correct String[] outMap = getFolderMap(unzipFolder.getAbsolutePath()); // Check lengths: root folder in expected is not expected in the outMap: therefore -1 assertEquals("Check that lenght is the same", expectedMap.length - 1, outMap.length); }
From source file:uk.ac.ebi.metabolights.utils.ZipperTest.java
@Test public void testInvalidZipFile() { try {// w w w . j av a 2 s . c o m Zipper.unzip("wrongpath"); //If it does not throws an exception, It is wrong fail("Zipper.unzip must throw an exception with a wrong file"); } catch (IOException ioe) { assertTrue("IOException expected", true); } catch (ArchiveException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:uk.ac.ebi.metabolights.utils.ZipperTest.java
@Test public void testISAUnzipCreatorArchive() { final String ISAArchiveName = "ISACREATOR1.4_archive_FAST.zip"; String ISAArchive = "./src/test/resources/zipper/unziptest/" + ISAArchiveName; try {/*from w w w .ja v a2 s. co m*/ Zipper.unzip(ISAArchive); } catch (IOException ioe) { fail(ioe.getMessage()); } catch (ArchiveException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }