2424import java .util .Iterator ;
2525
2626public class GenericContainer implements Container {
27+ protected static final long TIMESTAMP = System .currentTimeMillis ();
28+
29+ protected static long tmpFileCounter = 0 ;
30+
2731 protected API api ;
2832 protected int rootNameCount ;
2933 protected Container .Entry root ;
3034
3135 public GenericContainer (API api , Container .Entry parentEntry , Path rootPath ) {
32- this .api = api ;
33- this .rootNameCount = rootPath .getNameCount ();
34- this .root = new Entry (parentEntry , rootPath , parentEntry .getUri ()) {
35- public Entry newChildEntry (Path fsPath ) {
36- return new Entry (parent , fsPath , null );
37- }
38- };
36+ try {
37+ URI uri = parentEntry .getUri ();
38+
39+ this .api = api ;
40+ this .rootNameCount = rootPath .getNameCount ();
41+ this .root = new Entry (parentEntry , rootPath , new URI (uri .getScheme (), uri .getHost (), uri .getPath () + "!/" , null )) {
42+ public Entry newChildEntry (Path fsPath ) {
43+ return new Entry (parent , fsPath , null );
44+ }
45+ };
46+ } catch (URISyntaxException e ) {
47+ assert ExceptionUtil .printStackTrace (e );
48+ }
3949 }
4050
4151 public String getType () { return "generic" ; }
@@ -66,7 +76,8 @@ public Entry(Container.Entry parent, Path fsPath, URI uri) {
6676 public URI getUri () {
6777 if (uri == null ) {
6878 try {
69- uri = new URI (root .getUri ().getScheme (), root .getUri ().getHost (), root .getUri ().getPath () + "!/" + getPath (), null );
79+ URI rootUri = root .getUri ();
80+ uri = new URI (rootUri .getScheme (), rootUri .getHost (), rootUri .getPath () + getPath (), null );
7081 } catch (URISyntaxException e ) {
7182 assert ExceptionUtil .printStackTrace (e );
7283 }
@@ -146,7 +157,8 @@ protected Collection<Container.Entry> loadChildrenFromDirectoryEntry() throws IO
146157 }
147158
148159 protected Collection <Container .Entry > loadChildrenFromFileEntry () throws IOException {
149- File tmpFile = File .createTempFile ("jd-gui." , "." + fsPath .getFileName ().toString ());
160+ StringBuilder suffix = new StringBuilder ("." ).append (TIMESTAMP ).append ('.' ).append (tmpFileCounter ++).append ('.' ).append (fsPath .getFileName ().toString ());
161+ File tmpFile = File .createTempFile ("jd-gui.tmp." , suffix .toString ());
150162 Path tmpPath = Paths .get (tmpFile .toURI ());
151163
152164 tmpFile .delete ();
@@ -166,7 +178,6 @@ protected Collection<Container.Entry> loadChildrenFromFileEntry() throws IOExcep
166178 Container container = containerFactory .make (api , this , rootPath );
167179
168180 if (container != null ) {
169- tmpFile .delete ();
170181 return container .getRoot ().getChildren ();
171182 }
172183 }
0 commit comments