@Test public void testFileUtils() throws Exception { File testDirectory = new File("build/testDirectory"); testDirectory.mkdirs(); byte[] buffer = new byte[2048]; File zip = new File(testDirectory, "test.zip"); zip.createNewFile(); try (OutputStream outputStream = new FileOutputStream(zip)) { outputStream.write(FileUtils.emptyZipByteArray()); } Assert.assertEquals(FileUtils.emptyZipByteArray().length, zip.length()); try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Hello, world! Hello Peter!".getBytes(StandardCharsets.UTF_8))) { Assert.assertEquals("Hello, world! Hello Peter!", new String(FileUtils.toByteArray(byteArrayInputStream), StandardCharsets.UTF_8)); } FileUtils.openZipFileSystem(zip, fileSystem -> { Path zipEntryInfoFile = fileSystem.getPath("info.txt"); try (OutputStream outputStream = Files.newOutputStream(zipEntryInfoFile); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Info message :3".getBytes())) { FileUtils.copy(byteArrayInputStream, outputStream, buffer); } return null; }); try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipFile zipFile = new ZipFile(zip)) { ZipEntry zipEntry = zipFile.getEntry("info.txt"); Assert.assertNotNull(zipEntry); try (InputStream inputStream = zipFile.getInputStream(zipEntry)) { FileUtils.copy(inputStream, byteArrayOutputStream); } Assert.assertEquals("Info message :3", new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8)); } FileUtils.delete(testDirectory); Assert.assertFalse(testDirectory.exists()); zip = new File("build/test.zip"); zip.createNewFile(); try (OutputStream outputStream = Files.newOutputStream(zip.toPath()); InputStream inputStream = FileUtilsTest.class.getClassLoader().getResourceAsStream("file_utils_resources.zip")) { FileUtils.copy(inputStream, outputStream, buffer); } Path path = Paths.get("build/testDirectory"); FileUtils.extract(zip.toPath(), path); Assert.assertTrue(Files.exists(path)); Assert.assertTrue(new File(path.toFile(), "bungee/config.yml").exists()); Assert.assertTrue(new File(path.toFile(), "nms/bukkit.yml").exists()); Assert.assertTrue(new File(path.toFile(), "nms/server.properties").exists()); FileUtils.delete(path.toFile()); Assert.assertFalse(Files.exists(path)); }
private FileUtils() { throw new UnsupportedOperationException(); }
FileUtils { private FileUtils() { throw new UnsupportedOperationException(); } }
FileUtils { private FileUtils() { throw new UnsupportedOperationException(); } private  FileUtils(); }
FileUtils { private FileUtils() { throw new UnsupportedOperationException(); } private  FileUtils(); static byte[] toByteArray(InputStream inputStream); static byte[] toByteArray(InputStream inputStream, byte[] buffer); static void openZipFileSystem(File file,
                                         IVoidThrowableCallback<FileSystem> consumer); static void openZipFileSystem(Path path,
                                         IVoidThrowableCallback<FileSystem> consumer); static void copy(InputStream inputStream, OutputStream outputStream); static void copy(InputStream inputStream, OutputStream outputStream,
                            byte[] buffer); static void copy(InputStream inputStream, OutputStream outputStream,
                            byte[] buffer, Consumer<Integer> lengthInputListener); static void copy(File from, File to); static void copy(File from, File to, byte[] buffer); static void copy(Path from, Path to); static void copy(Path from, Path to, byte[] buffer); static void copyFilesToDirectory(File from, File to); static void copyFilesToDirectory(File from, File to, Predicate<File> fileFilter); static void copyFilesToDirectory(File from, File to, byte[] buffer); static void copyFilesToDirectory(File from, File to, byte[] buffer, Predicate<File> fileFilter); static void delete(File file); static Path convert(Path zipPath, Path... directories); @Deprecated static byte[] convert(Path... directories); @Nullable static Path zipToFile(Path directory, Path target); static Path extract(Path zipPath, Path targetDirectory); static Path extract(byte[] zipData, Path targetDirectory); static void extract0(ZipInputStream zipInputStream, Path targetDirectory); static byte[] emptyZipByteArray(); static void workFileTree(Path path, Consumer<File> consumer); static void workFileTree(File file, Consumer<File> consumer); }
FileUtils { private FileUtils() { throw new UnsupportedOperationException(); } private  FileUtils(); static byte[] toByteArray(InputStream inputStream); static byte[] toByteArray(InputStream inputStream, byte[] buffer); static void openZipFileSystem(File file,
                                         IVoidThrowableCallback<FileSystem> consumer); static void openZipFileSystem(Path path,
                                         IVoidThrowableCallback<FileSystem> consumer); static void copy(InputStream inputStream, OutputStream outputStream); static void copy(InputStream inputStream, OutputStream outputStream,
                            byte[] buffer); static void copy(InputStream inputStream, OutputStream outputStream,
                            byte[] buffer, Consumer<Integer> lengthInputListener); static void copy(File from, File to); static void copy(File from, File to, byte[] buffer); static void copy(Path from, Path to); static void copy(Path from, Path to, byte[] buffer); static void copyFilesToDirectory(File from, File to); static void copyFilesToDirectory(File from, File to, Predicate<File> fileFilter); static void copyFilesToDirectory(File from, File to, byte[] buffer); static void copyFilesToDirectory(File from, File to, byte[] buffer, Predicate<File> fileFilter); static void delete(File file); static Path convert(Path zipPath, Path... directories); @Deprecated static byte[] convert(Path... directories); @Nullable static Path zipToFile(Path directory, Path target); static Path extract(Path zipPath, Path targetDirectory); static Path extract(byte[] zipData, Path targetDirectory); static void extract0(ZipInputStream zipInputStream, Path targetDirectory); static byte[] emptyZipByteArray(); static void workFileTree(Path path, Consumer<File> consumer); static void workFileTree(File file, Consumer<File> consumer);  }