FileSystem { public static void delete(File file) throws IOException { if (file != null) { final LinkedList<File> candidates = new LinkedList<>(); candidates.add(file); File fl; File[] children; while (!candidates.isEmpty()) { fl = candidates.getFirst(); if (fl.isDirectory()) { children = fl.listFiles(); if (children != null && children.length > 0) { for (final File c : children) { candidates.push(c); } } else { candidates.removeFirst(); fl.delete(); } } else { candidates.removeFirst(); fl.delete(); } } } } private  FileSystem(); @Pure @Inline(value = "URISchemeType.JAR.isURL($1)", imported = {URISchemeType.class}) static boolean isJarURL(URL url); @Pure static URL getJarURL(URL url); @Pure static File getJarFile(URL url); @Pure static URL toJarURL(File jarFile, File insideFile); @Pure @Inline("toJarURL(($1).toURI().toURL(), ($2))") static URL toJarURL(File jarFile, String insideFile); @Pure static URL toJarURL(URL jarFile, File insideFile); @Pure static URL toJarURL(URL jarFile, String insideFile); @Pure static boolean isCaseSensitiveFilenameSystem(); @Pure @Inline(value = "EXTENSION_SEPARATOR_CHAR", constantExpression = true) static char getFileExtensionCharacter(); @Pure static URL dirname(File filename); @Pure @SuppressWarnings("checkstyle:npathcomplexity") static URL dirname(URL filename); @Pure static String largeBasename(String filename); @Pure @Inline("((($1) == null) ? null : ($1).getName())") static String largeBasename(File filename); @Pure static String largeBasename(URL filename); @Pure static String basename(String filename); @Pure static String basename(File filename); @Pure static String basename(URL filename); @Pure static String shortBasename(String filename); @Pure static String shortBasename(File filename); @Pure static String shortBasename(URL filename); @Pure static String extension(File filename); @Pure static String extension(String filename); @Pure static String extension(URL filename); @Pure static String[] extensions(File filename); @Pure static String[] extensions(String filename); @Pure static String[] extensions(URL filename); @Pure static String[] split(File filename); @Pure static String[] split(URL filename); @Pure static File join(File fileBase, String... elements); @Pure static File join(File fileBase, File... elements); @Pure static URL join(URL urlBase, String... elements); @Pure static URL join(URL urlBase, File... elements); @Pure static boolean hasExtension(File filename, String extension); @Pure static boolean hasExtension(String filename, String extension); @Pure static boolean hasExtension(URL filename, String extension); @Pure static File removeExtension(File filename); @Pure static URL removeExtension(URL filename); @Pure static File replaceExtension(File filename, String extension); @Pure @SuppressWarnings("checkstyle:npathcomplexity") static URL replaceExtension(URL filename, String extension); @Pure static File addExtension(File filename, String extension); @Pure static URL addExtension(URL filename, String extension); static void delete(File file); static void deleteOnExit(File file); static void undeleteOnExit(File file); static void copy(File in, File out); static void copy(URL in, File out); @SuppressWarnings("checkstyle:magicnumber") static void copy(InputStream in, int inSize, FileOutputStream out); @Pure static File getUserHomeDirectory(); @Pure static String getUserHomeDirectoryName(); @Pure static File getUserConfigurationDirectoryFor(String software); @Pure static String getUserConfigurationDirectoryNameFor(String software); @Pure static File getSystemConfigurationDirectoryFor(String software); @Pure static String getSystemConfigurationDirectoryNameFor(String software); @Pure static File getSystemSharedLibraryDirectoryFor(String software); @Pure static String getSystemSharedLibraryDirectoryNameFor(String software); @Pure static File convertStringToFile(String filename); @Pure @SuppressWarnings("checkstyle:npathcomplexity") static File convertURLToFile(URL url); @Pure static URL convertStringToURL(String urlDescription, boolean allowResourceSearch); @Pure static URL convertStringToURL(String urlDescription, boolean allowResourceSearch, boolean repliesFileURL); @Pure static File makeAbsolute(File filename, File current); @Pure static URL makeAbsolute(URL filename, File current); @Pure @SuppressWarnings("checkstyle:cyclomaticcomplexity") static URL makeAbsolute(URL filename, URL current); @Pure static URL makeAbsolute(File filename, URL current); @Pure @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) static URL getParentURL(URL url); @Pure static boolean isWindowsNativeFilename(String filename); @Pure static File normalizeWindowsNativeFilename(String filename); @Pure static URL convertFileToURL(File file); @SuppressWarnings("resource") @Pure static URL toShortestURL(URL url); @Pure static File makeRelative(File filenameToMakeRelative, File rootPath); @Pure static File makeRelative(File filenameToMakeRelative, URL rootPath); @Pure static File makeRelative(URL filenameToMakeRelative, URL rootPath); @Pure static URL makeCanonicalURL(URL url); static void zipFile(File input, File output); @SuppressWarnings("checkstyle:npathcomplexity") static void zipFile(File input, OutputStream output); static void unzipFile(InputStream input, File output); static void unzipFile(File input, File output); static File createTempDirectory(String prefix, String suffix); static File createTempDirectory(String prefix, String suffix, File directory); static final char EXTENSION_SEPARATOR_CHAR; static final String CURRENT_DIRECTORY; static final String PARENT_DIRECTORY; static final char URL_PATH_SEPARATOR_CHAR; static final String URL_PATH_SEPARATOR; static final String EXTENSION_SEPARATOR; static final String JAR_URL_FILE_ROOT; static final char WINDOWS_SEPARATOR_CHAR; static final String WINDOWS_SEPARATOR_STRING; static final String UNIX_SEPARATOR_STRING; }
@Test public void zipFileFile() throws IOException { File testArchive = null; try { testArchive = File.createTempFile("unittest", ".zip"); createZip(testArchive); try (ZipFile zipFile = new ZipFile(testArchive)) { ZipEntry zipEntry = zipFile.getEntry("test.txt"); assertNotNull(zipEntry); assertEquals("TEST1: FOR UNIT TEST ONLY", readInputStream(zipFile.getInputStream(zipEntry))); zipEntry = zipFile.getEntry("test2.txt"); assertNotNull(zipEntry); assertEquals("TEST2: FOR UNIT TEST ONLY", readInputStream(zipFile.getInputStream(zipEntry))); zipEntry = zipFile.getEntry("subdir/test.txt"); assertNotNull(zipEntry); assertEquals("TEST1: FOR UNIT TEST ONLY", readInputStream(zipFile.getInputStream(zipEntry))); } } finally { FileSystem.delete(testArchive); } }