|
37 | 37 | import java.io.FilenameFilter;
|
38 | 38 | import java.io.IOException;
|
39 | 39 | import java.io.InputStream;
|
40 |
| -import java.io.OutputStream; |
41 | 40 | import java.net.URL;
|
| 41 | +import java.nio.file.Files; |
| 42 | +import java.nio.file.StandardCopyOption; |
42 | 43 | import java.util.Arrays;
|
43 | 44 | import java.util.LinkedList;
|
44 | 45 | import java.util.List;
|
@@ -198,9 +199,7 @@ private static boolean extractAndLoadLibraryFile(
|
198 | 199 | if (!extractedLckFile.exists()) {
|
199 | 200 | new FileOutputStream(extractedLckFile).close();
|
200 | 201 | }
|
201 |
| - try (OutputStream out = new FileOutputStream(extractedLibFile)) { |
202 |
| - copy(in, out); |
203 |
| - } |
| 202 | + Files.copy(in, extractedLibFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
204 | 203 | } finally {
|
205 | 204 | // Delete the extracted lib file on JVM exit.
|
206 | 205 | extractedLibFile.deleteOnExit();
|
@@ -239,14 +238,6 @@ private static String randomUUID() {
|
239 | 238 | return Long.toHexString(new Random().nextLong());
|
240 | 239 | }
|
241 | 240 |
|
242 |
| - private static void copy(InputStream in, OutputStream out) throws IOException { |
243 |
| - byte[] buf = new byte[8192]; |
244 |
| - int n; |
245 |
| - while ((n = in.read(buf)) > 0) { |
246 |
| - out.write(buf, 0, n); |
247 |
| - } |
248 |
| - } |
249 |
| - |
250 | 241 | /**
|
251 | 242 | * Loads native library using the given path and name of the library.
|
252 | 243 | *
|
@@ -358,7 +349,7 @@ private static void loadJansiNativeLibrary() throws Exception {
|
358 | 349 |
|
359 | 350 | throw new Exception(String.format(
|
360 | 351 | "No native library found for os.name=%s, os.arch=%s, paths=[%s]",
|
361 |
| - OSInfo.getOSName(), OSInfo.getArchName(), join(triedPaths, File.pathSeparator))); |
| 352 | + OSInfo.getOSName(), OSInfo.getArchName(), String.join(File.pathSeparator, triedPaths))); |
362 | 353 | }
|
363 | 354 |
|
364 | 355 | private static boolean hasResource(String path) {
|
@@ -401,16 +392,4 @@ public static String getVersion() {
|
401 | 392 | }
|
402 | 393 | return version;
|
403 | 394 | }
|
404 |
| - |
405 |
| - private static String join(List<String> list, String separator) { |
406 |
| - StringBuilder sb = new StringBuilder(); |
407 |
| - boolean first = true; |
408 |
| - for (String item : list) { |
409 |
| - if (first) first = false; |
410 |
| - else sb.append(separator); |
411 |
| - |
412 |
| - sb.append(item); |
413 |
| - } |
414 |
| - return sb.toString(); |
415 |
| - } |
416 | 395 | }
|
0 commit comments