@Override public void writePackage(File file, IRI documentIRI, Authorizations authorizations) throws Exception { if (!file.exists()) { throw new VisalloException("OWL file does not exist: " + file.getAbsolutePath()); } if (!file.isFile()) { throw new VisalloException("OWL file is not a file: " + file.getAbsolutePath()); } ZipFile zipped = new ZipFile(file); if (zipped.isValidZipFile()) { File tempDir = Files.createTempDir(); try { LOGGER.info("Extracting: %s to %s", file.getAbsoluteFile(), tempDir.getAbsolutePath()); zipped.extractAll(tempDir.getAbsolutePath()); File owlFile = findOwlFile(tempDir); importFile(owlFile, documentIRI, authorizations); } finally { FileUtils.deleteDirectory(tempDir); } } else { importFile(file, documentIRI, authorizations); } }
private File savePartToTemp(Part part) { File tempDir = Files.createTempDir(); try { File uploadFile = new File(tempDir, part.getSubmittedFileName()); try (OutputStream uploadFileOut = new FileOutputStream(uploadFile)) { IOUtils.copy(part.getInputStream(), uploadFileOut); } try { ZipFile zipped = new ZipFile(uploadFile); if (zipped.isValidZipFile()) { zipped.extractAll(tempDir.getAbsolutePath()); } } catch (Exception ex) { throw new VisalloException("Could not expand zip file: " + uploadFile.getAbsolutePath(), ex); } return tempDir; } catch (Exception ex) { try { FileUtils.forceDelete(tempDir); } catch (IOException e) { LOGGER.error("Could not delete temp directory (%s) after failed save", tempDir.getAbsolutePath(), e); } throw new VisalloException("Could not save uploaded file", ex); } }
if(!zipFile.isValidZipFile()) { throw new MopedException("unzip: not a valid zip file " + source); } else {
@Override public String guessDocumentIRIFromPackage(File file) throws IOException, ZipException { ZipFile zipped = new ZipFile(file); if (zipped.isValidZipFile()) { File tempDir = Files.createTempDir(); try { LOGGER.info("Extracting: %s to %s", file.getAbsoluteFile(), tempDir.getAbsolutePath()); zipped.extractAll(tempDir.getAbsolutePath()); File owlFile = findOwlFile(tempDir); return guessDocumentIRIFromFile(owlFile); } finally { FileUtils.deleteDirectory(tempDir); } } else { if (file.isDirectory()) { file = findOwlFile(file); } return guessDocumentIRIFromFile(file); } }
/** * Unzip the contents of the zip file in the passed destination directory. If the directory * does not exist, create it. * * @param zipFile * @param destDir * @throws KlabException */ public static void unzip(File zipFile, File destDir) throws KlabException { ZipFile zFile; try { zFile = new ZipFile(zipFile); if (!zFile.isValidZipFile()) { throw new KlabIOException("file " + zipFile + " is not a valid archive"); } if (!destDir.exists()) { destDir.mkdirs(); } // if (zFile.isEncrypted()) { // zFile.setPassword(passwd.toCharArray()); // } zFile.extractAll(destDir.toString()); } catch (ZipException e) { throw new KlabIOException(e); } }
ZipFile zFile = new ZipFile(zipFile); zFile.setFileNameCharset(SkeletonConstant.ENCODING_UTF_8); if (!zFile.isValidZipFile()) { throw new ZipException("Invalid zip files, it may be damaged");
ZipFile zFile = new ZipFile(zipFile); zFile.setFileNameCharset(SkeletonConstant.ENCODING_UTF_8); if (!zFile.isValidZipFile()) { throw new ZipException("Invalid zip files, it may be damaged");
if (!zipFile.isValidZipFile()) { sendHandle(3, "文件不合法"); return;
private void validateResourceZip(App app) { FileMeta appZipMeta = app.getSourceFiles(); if (appZipMeta != null) { File fileStoreFile = fileStore.getFile(appZipMeta.getId()); if (fileStoreFile == null) { LOG.error("Resource zip '{}' for app '{}' missing in file store", appZipMeta.getId(), app.getName()); throw new RuntimeException("An error occurred trying to create or update app"); } ZipFile zipFile; try { zipFile = new ZipFile(fileStoreFile); } catch (ZipException e) { LOG.error("Error creating zip file object", e); throw new RuntimeException("An error occurred trying to create or update app"); } if (!zipFile.isValidZipFile()) { throw new MolgenisValidationException(new ConstraintViolation( String.format("'%s' is not a valid zip file.", appZipMeta.getFilename()))); } } } }