added copy methods

This commit is contained in:
2022-03-26 00:42:28 +08:00
parent 705ad088aa
commit 419f08364c
3 changed files with 22 additions and 3 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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<Path> paths = StreamSupport.stream(fs.getRootDirectories().spliterator(), false).flatMap(new Function<Path, Stream<Path>>() {
@Override
@SneakyThrows
@@ -36,7 +36,7 @@ public class PathClassLoaderTest {
@SneakyThrows
public Stream<Path> 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);