/** * Rethrow the given exception as a runtime exception. */ static ZipException rethrow(IOException e) { throw new ZipException(e); }
static Object invoke(Method method, Object obj, Object... args) throws ZipException { try { return method.invoke(obj, args); } catch (IllegalAccessException e) { throw new ZipException(e); } catch (InvocationTargetException e) { throw new ZipException(e); } catch (IllegalArgumentException e) { throw new ZipException(e); } }
static <T> Class<? extends T> getClassForName(String name, Class<T> clazz) { try { return Class.forName(name).asSubclass(clazz); } catch (ClassNotFoundException e) { throw new ZipException(e); } catch (ClassCastException e) { throw new ZipException(e); } }
static Method getDeclaredMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) { try { return clazz.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { throw new ZipException(e); } }
private String getRootName(final String name) { String newName = name.substring(FilenameUtils.getPrefixLength(name)); int idx = newName.indexOf(PATH_SEPARATOR); if (idx < 0) { throw new ZipException("Entry " + newName + " from the root of the zip is not supported"); } return newName.substring(0, newName.indexOf(PATH_SEPARATOR)); } }
if (filenames == null) { if (!dir.exists()) { throw new ZipException("Given file '" + dir + "' doesn't exist!"); throw new ZipException("Given directory '" + dir + "' doesn't contain any files!");
public void process(InputStream in, ZipEntry zipEntry) throws IOException { String root = getRootName(zipEntry.getName()); if (rootDir == null) { rootDir = root; } else if (!rootDir.equals(root)) { throw new ZipException("Unwrapping with multiple roots is not supported, roots: " + rootDir + ", " + root); } String name = mapper.map(getUnrootedName(root, zipEntry.getName())); if (name != null) { File file = makeDestinationFile(outputDir, name); if (zipEntry.isDirectory()) { FileUtils.forceMkdir(file); } else { FileUtils.forceMkdir(file.getParentFile()); if (log.isDebugEnabled() && file.exists()) { log.debug("Overwriting file '{}'.", zipEntry.getName()); } FileUtils.copy(in, file); } } }
log.debug("Compressing '{}' into '{}'.", sourceDir, targetZip); if (!sourceDir.exists()) { throw new ZipException("Given file '" + sourceDir + "' doesn't exist!");
throw new ZipException("Failed to process zip entry '" + entry.getName() + " with action " + action, ze);
throw new ZipException("Failed to process zip entry '" + e.getName() + " with action " + action, ze);
throw new ZipException("Failed to process zip entry '" + entry.getName() + " with action " + action, ze);
throw new ZipException("Failed to process zip entry '" + e.getName() + "' with action " + action, ze);
throw new ZipException("Failed to process zip entry '" + e.getName() + " with action " + action, ze);
log.debug("Compressing '{}' into a stream.", sourceDir); if (!sourceDir.exists()) { throw new ZipException("Given file '" + sourceDir + "' doesn't exist!");
throw new ZipException("Failed to process zip entry '" + e.getName() + " with action " + action, ze);
@SuppressWarnings("unchecked") public Java7Nio2ApiPermissionsStrategy() { if (!isPosix()) { throw new ZipException("File system does not support POSIX file attributes");
/** * Get assigned to ZIP entry file permissions info. Current implementation tries to read "ASi Unix" (tag 0x756e) extra tag. * "ASi Unix" * * @param zipEntry * @return file permissions info or <code>null</code> if ZIP entry does not have "ASi Unix" extra field. */ static ZTFilePermissions getZTFilePermissions(ZipEntry zipEntry) { try { ZTFilePermissions permissions = null; List<ZipExtraField> fields = ExtraFieldUtils.parse(zipEntry.getExtra()); AsiExtraField asiExtraField = getFirstAsiExtraField(fields); if (asiExtraField != null) { int mode = asiExtraField.getMode() & 0777; permissions = ZTFilePermissionsUtil.fromPosixFileMode(mode); } return permissions; } catch (java.util.zip.ZipException ze) { throw new ZipException(ze); } }
/** * Rethrow the given exception as a runtime exception. */ static ZipException rethrow(IOException e) { throw new ZipException(e); }
static <T> Class<? extends T> getClassForName(String name, Class<T> clazz) { try { return Class.forName(name).asSubclass(clazz); } catch (ClassNotFoundException e) { throw new ZipException(e); } catch (ClassCastException e) { throw new ZipException(e); } }
static Method getDeclaredMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) { try { return clazz.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { throw new ZipException(e); } }