Browse Source

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 years ago
parent
commit
9d279109f1
1 changed files with 18 additions and 2 deletions
  1. 18
    2
      src/com/dmdirc/util/io/FileUtils.java

+ 18
- 2
src/com/dmdirc/util/io/FileUtils.java View File

23
 package com.dmdirc.util.io;
23
 package com.dmdirc.util.io;
24
 
24
 
25
 import java.io.IOException;
25
 import java.io.IOException;
26
+import java.net.URI;
26
 import java.net.URISyntaxException;
27
 import java.net.URISyntaxException;
27
 import java.net.URL;
28
 import java.net.URL;
28
 import java.nio.file.CopyOption;
29
 import java.nio.file.CopyOption;
29
 import java.nio.file.DirectoryStream;
30
 import java.nio.file.DirectoryStream;
31
+import java.nio.file.FileSystem;
32
+import java.nio.file.FileSystems;
30
 import java.nio.file.Files;
33
 import java.nio.file.Files;
31
 import java.nio.file.Path;
34
 import java.nio.file.Path;
32
 import java.nio.file.Paths;
35
 import java.nio.file.Paths;
33
 import java.nio.file.StandardCopyOption;
36
 import java.nio.file.StandardCopyOption;
37
+import java.util.HashMap;
38
+import java.util.Map;
34
 
39
 
35
 /**
40
 /**
36
  * Utility class to deal with files.
41
  * Utility class to deal with files.
51
      */
56
      */
52
     public static void copyResources(final URL source, final Path destination) throws IOException {
57
     public static void copyResources(final URL source, final Path destination) throws IOException {
53
         try {
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
         } catch (URISyntaxException ex) {
72
         } catch (URISyntaxException ex) {
57
             throw new IOException("Unable to get source URI", ex);
73
             throw new IOException("Unable to get source URI", ex);
58
         }
74
         }

Loading…
Cancel
Save