From 419f08364c7c876557b7d2fd48461bd8709074c1 Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Sat, 26 Mar 2022 00:42:28 +0800 Subject: [PATCH] added copy methods --- gradle.properties | 2 +- src/main/java/net/woggioni/jwo/JWO.java | 19 +++++++++++++++++++ .../net/woggioni/jwo/PathClassLoaderTest.java | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7143a03..bd16aa7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ gradle.version = 7.4.1 jwo.version=1.0-SNAPSHOT -junitJupiter.version=5.7.0 +junitJupiter.version=5.8.2 lombok.version=1.18.22 slf4j.version=1.7.32 guice.version = 5.0.1 diff --git a/src/main/java/net/woggioni/jwo/JWO.java b/src/main/java/net/woggioni/jwo/JWO.java index 74d60a8..229f9ed 100644 --- a/src/main/java/net/woggioni/jwo/JWO.java +++ b/src/main/java/net/woggioni/jwo/JWO.java @@ -585,4 +585,23 @@ public class JWO { } return s; } + + @SneakyThrows + public static void copy(InputStream is, OutputStream os, byte[] buffer) { + while(true) { + int read = is.read(buffer); + if(read < 0) break; + os.write(buffer, 0, read); + } + } + + public static void copy(InputStream is, OutputStream os, int bufferSize) { + byte[] buffer = new byte[bufferSize]; + copy(is, os, buffer); + } + + public static void copy(InputStream is, OutputStream os) { + byte[] buffer = new byte[0x10000]; + copy(is, os, buffer); + } } diff --git a/src/test/java/net/woggioni/jwo/PathClassLoaderTest.java b/src/test/java/net/woggioni/jwo/PathClassLoaderTest.java index d184bdc..a558a33 100644 --- a/src/test/java/net/woggioni/jwo/PathClassLoaderTest.java +++ b/src/test/java/net/woggioni/jwo/PathClassLoaderTest.java @@ -22,7 +22,7 @@ public class PathClassLoaderTest { @Test @SneakyThrows void test() { - FileSystem fs = FileSystems.newFileSystem(testBundle, null); + FileSystem fs = FileSystems.newFileSystem(testBundle, (ClassLoader) null); List paths = StreamSupport.stream(fs.getRootDirectories().spliterator(), false).flatMap(new Function>() { @Override @SneakyThrows @@ -36,7 +36,7 @@ public class PathClassLoaderTest { @SneakyThrows public Stream apply(Path path) { System.out.println(path.getFileName().toString()); - return StreamSupport.stream(FileSystems.newFileSystem(path, null).getRootDirectories().spliterator(), false); + return StreamSupport.stream(FileSystems.newFileSystem(path, (ClassLoader) null).getRootDirectories().spliterator(), false); } }).collect(Collectors.toUnmodifiableList()); PathClassLoader classLoader = new PathClassLoader(paths);