本文整理了Java中net.lingala.zip4j.core.ZipFile.isValidZipFile()
方法的一些代码示例,展示了ZipFile.isValidZipFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipFile.isValidZipFile()
方法的具体详情如下:
包路径:net.lingala.zip4j.core.ZipFile
类名称:ZipFile
方法名:isValidZipFile
[英]Checks to see if the input zip file is a valid zip file. This method will try to read zip headers. If headers are read successfully, this method returns true else false
[中]检查输入zip文件是否为有效的zip文件。此方法将尝试读取zip标题。如果成功读取头,此方法将返回true或false
代码示例来源:origin: org.visallo/visallo-core
@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);
}
}
代码示例来源:origin: org.visallo/visallo-web-admin-import-rdf
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);
}
}
代码示例来源:origin: sics-sse/moped
if(!zipFile.isValidZipFile()) {
throw new MopedException("unzip: not a valid zip file " + source);
} else {
代码示例来源:origin: org.visallo/visallo-core
@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);
}
}
代码示例来源:origin: org.integratedmodelling/klab-common
/**
* 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);
}
}
代码示例来源:origin: Nepxion/Skeleton
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset(SkeletonConstant.ENCODING_UTF_8);
if (!zFile.isValidZipFile()) {
throw new ZipException("Invalid zip files, it may be damaged");
代码示例来源:origin: SpringCloud/spring-cloud-codegen
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset(SkeletonConstant.ENCODING_UTF_8);
if (!zFile.isValidZipFile()) {
throw new ZipException("Invalid zip files, it may be damaged");
代码示例来源:origin: StannyBing/ZXUtils
if (!zipFile.isValidZipFile()) {
sendHandle(3, "文件不合法");
return;
代码示例来源:origin: org.molgenis/molgenis-apps
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())));
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!