ソースを参照

Fix copying resources from zip files.

FileSystems aren't as automatic as I expected :(

Change-Id: I5fe47086e86e3812dfa463bf1125ae02d1df3633
Reviewed-on: http://gerrit.dmdirc.com/4062
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
changes/62/4062/2
Chris Smith 9年前
コミット
9d279109f1
1個のファイルの変更18行の追加2行の削除
  1. 18
    2
      src/com/dmdirc/util/io/FileUtils.java

+ 18
- 2
src/com/dmdirc/util/io/FileUtils.java ファイルの表示

@@ -23,14 +23,19 @@
23 23
 package com.dmdirc.util.io;
24 24
 
25 25
 import java.io.IOException;
26
+import java.net.URI;
26 27
 import java.net.URISyntaxException;
27 28
 import java.net.URL;
28 29
 import java.nio.file.CopyOption;
29 30
 import java.nio.file.DirectoryStream;
31
+import java.nio.file.FileSystem;
32
+import java.nio.file.FileSystems;
30 33
 import java.nio.file.Files;
31 34
 import java.nio.file.Path;
32 35
 import java.nio.file.Paths;
33 36
 import java.nio.file.StandardCopyOption;
37
+import java.util.HashMap;
38
+import java.util.Map;
34 39
 
35 40
 /**
36 41
  * Utility class to deal with files.
@@ -51,8 +56,19 @@ public final class FileUtils {
51 56
      */
52 57
     public static void copyResources(final URL source, final Path destination) throws IOException {
53 58
         try {
54
-            copyRecursively(Paths.get(source.toURI()), destination,
55
-                    StandardCopyOption.REPLACE_EXISTING);
59
+            final String path = source.toURI().toString();
60
+            final int index = path.indexOf("!/");
61
+            if (index > -1) {
62
+                final String file = path.substring(0, index);
63
+                final Map<String, String> env = new HashMap<>();
64
+                try (final FileSystem fs = FileSystems.newFileSystem(URI.create(file), env)) {
65
+                    copyRecursively(fs.getPath(path.substring(index + 2)), destination,
66
+                            StandardCopyOption.REPLACE_EXISTING);
67
+                }
68
+            } else {
69
+                copyRecursively(Paths.get(source.toURI()), destination,
70
+                        StandardCopyOption.REPLACE_EXISTING);
71
+            }
56 72
         } catch (URISyntaxException ex) {
57 73
             throw new IOException("Unable to get source URI", ex);
58 74
         }

読み込み中…
キャンセル
保存