private static boolean isPosix() { Method getDefaultMethod = ZTZipReflectionUtil.getDeclaredMethod( ZTZipReflectionUtil.getClassForName("java.nio.file.FileSystems", Object.class), "getDefault"); Method supportedFileAttributeViewsMethod = ZTZipReflectionUtil.getDeclaredMethod( ZTZipReflectionUtil.getClassForName("java.nio.file.FileSystem", Object.class), "supportedFileAttributeViews"); Object fileSystem = ZTZipReflectionUtil.invoke(getDefaultMethod, null); @SuppressWarnings("unchecked") Set<String> views = (Set<String>) ZTZipReflectionUtil.invoke(supportedFileAttributeViewsMethod, fileSystem); return views.contains("posix"); } }
(Class<? extends Enum<?>>) ZTZipReflectionUtil.getClassForName("java.nio.file.attribute.PosixFilePermission", Enum.class); Enum<?>[] constants = posixFilePermissionClass.getEnumConstants(); OWNER_READ = constants[0]; (Class<? extends Enum<?>>) ZTZipReflectionUtil.getClassForName("java.nio.file.LinkOption", Enum.class); linkOptionsArray = (Enum<?>[]) Array.newInstance(linkOptionClass, 1); linkOptionsArray[0] = (Enum<?>) linkOptionClass.getEnumConstants()[0]; // LinkOption.NOFOLLOW_LINKS; filesClass = ZTZipReflectionUtil.getClassForName("java.nio.file.Files", Object.class); pathClass = ZTZipReflectionUtil.getClassForName("java.nio.file.Path", Object.class); toPathMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "toPath"); setPosixFilePermissionsMethod = ZTZipReflectionUtil.getDeclaredMethod(filesClass, "setPosixFilePermissions", pathClass, Set.class); getPosixFilePermissionsMethod = ZTZipReflectionUtil.getDeclaredMethod(filesClass, "getPosixFilePermissions", pathClass, linkOptionsArray.getClass());
/** * Construct java.nio.file.Path object from abstract path. * Invokes JDK7 <code>file.toPath()</code> method through reflection. * * @param file * @return instance of java.nio.file.Path object */ private Object toPath(File file) { return ZTZipReflectionUtil.invoke(toPathMethod, file); }
public Java6FileApiPermissionsStrategy() throws ZipException { canExecuteMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "canExecute"); setExecutableMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "setExecutable", boolean.class, boolean.class); setReadableMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "setReadable", boolean.class, boolean.class); setWritableMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "setWritable", boolean.class, boolean.class); }
private boolean setWritable(File file, boolean executable, boolean ownerOnly) { return (Boolean) ZTZipReflectionUtil.invoke(setWritableMethod, file, executable, ownerOnly); }
(Class<? extends Enum<?>>) ZTZipReflectionUtil.getClassForName("java.nio.file.attribute.PosixFilePermission", Enum.class); Enum<?>[] constants = posixFilePermissionClass.getEnumConstants(); OWNER_READ = constants[0]; (Class<? extends Enum<?>>) ZTZipReflectionUtil.getClassForName("java.nio.file.LinkOption", Enum.class); linkOptionsArray = (Enum<?>[]) Array.newInstance(linkOptionClass, 1); linkOptionsArray[0] = (Enum<?>) linkOptionClass.getEnumConstants()[0]; // LinkOption.NOFOLLOW_LINKS; filesClass = ZTZipReflectionUtil.getClassForName("java.nio.file.Files", Object.class); pathClass = ZTZipReflectionUtil.getClassForName("java.nio.file.Path", Object.class); toPathMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "toPath"); setPosixFilePermissionsMethod = ZTZipReflectionUtil.getDeclaredMethod(filesClass, "setPosixFilePermissions", pathClass, Set.class); getPosixFilePermissionsMethod = ZTZipReflectionUtil.getDeclaredMethod(filesClass, "getPosixFilePermissions", pathClass, linkOptionsArray.getClass());
public Java6FileApiPermissionsStrategy() throws ZipException { canExecuteMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "canExecute"); setExecutableMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "setExecutable", boolean.class, boolean.class); setReadableMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "setReadable", boolean.class, boolean.class); setWritableMethod = ZTZipReflectionUtil.getDeclaredMethod(File.class, "setWritable", boolean.class, boolean.class); }
private static boolean isPosix() { Method getDefaultMethod = ZTZipReflectionUtil.getDeclaredMethod( ZTZipReflectionUtil.getClassForName("java.nio.file.FileSystems", Object.class), "getDefault"); Method supportedFileAttributeViewsMethod = ZTZipReflectionUtil.getDeclaredMethod( ZTZipReflectionUtil.getClassForName("java.nio.file.FileSystem", Object.class), "supportedFileAttributeViews"); Object fileSystem = ZTZipReflectionUtil.invoke(getDefaultMethod, null); @SuppressWarnings("unchecked") Set<String> views = (Set<String>) ZTZipReflectionUtil.invoke(supportedFileAttributeViewsMethod, fileSystem); return views.contains("posix"); } }
private boolean setExecutable(File file, boolean executable, boolean ownerOnly) { return (Boolean) ZTZipReflectionUtil.invoke(setExecutableMethod, file, executable, ownerOnly); }
private boolean canExecute(File file) { return (Boolean) ZTZipReflectionUtil.invoke(canExecuteMethod, file); } }
private boolean setReadable(File file, boolean executable, boolean ownerOnly) { return (Boolean) ZTZipReflectionUtil.invoke(setReadableMethod, file, executable, ownerOnly); }
private Set<?> getPosixFilePermissions(File file) { return (Set<?>) ZTZipReflectionUtil.invoke(getPosixFilePermissionsMethod, null, toPath(file), linkOptionsArray); }
private void setPosixFilePermissions(File file, Set<?> set) { ZTZipReflectionUtil.invoke(setPosixFilePermissionsMethod, null, toPath(file), set); }
/** * Construct java.nio.file.Path object from abstract path. * Invokes JDK7 <code>file.toPath()</code> method through reflection. * * @param file * @return instance of java.nio.file.Path object */ private Object toPath(File file) { return ZTZipReflectionUtil.invoke(toPathMethod, file); }
private boolean canExecute(File file) { return (Boolean) ZTZipReflectionUtil.invoke(canExecuteMethod, file); } }
private boolean setWritable(File file, boolean executable, boolean ownerOnly) { return (Boolean) ZTZipReflectionUtil.invoke(setWritableMethod, file, executable, ownerOnly); }
private boolean setReadable(File file, boolean executable, boolean ownerOnly) { return (Boolean) ZTZipReflectionUtil.invoke(setReadableMethod, file, executable, ownerOnly); }
private boolean setExecutable(File file, boolean executable, boolean ownerOnly) { return (Boolean) ZTZipReflectionUtil.invoke(setExecutableMethod, file, executable, ownerOnly); }
private Set<?> getPosixFilePermissions(File file) { return (Set<?>) ZTZipReflectionUtil.invoke(getPosixFilePermissionsMethod, null, toPath(file), linkOptionsArray); }
private void setPosixFilePermissions(File file, Set<?> set) { ZTZipReflectionUtil.invoke(setPosixFilePermissionsMethod, null, toPath(file), set); }