Revision: 2817
http://sourceforge.net/p/swingme/code/2817
Author: yuranet
Date: 2025-01-22 16:33:18 +0000 (Wed, 22 Jan 2025)
Log Message:
-----------
fallback handles spaces
Modified Paths:
--------------
me4se/src/org/me4se/psi/java1/gcf/file/FileConnectionImpl.java
Modified: me4se/src/org/me4se/psi/java1/gcf/file/FileConnectionImpl.java
===================================================================
--- me4se/src/org/me4se/psi/java1/gcf/file/FileConnectionImpl.java 2025-01-11 20:10:45 UTC (rev 2816)
+++ me4se/src/org/me4se/psi/java1/gcf/file/FileConnectionImpl.java 2025-01-22 16:33:18 UTC (rev 2817)
@@ -21,7 +21,7 @@
import java.io.DataOutputStream;
import java.io.DataInputStream;
import java.io.RandomAccessFile;
-
+import java.net.URI;
import java.util.Arrays;
import java.util.Properties;
import java.util.Enumeration;
@@ -88,17 +88,34 @@
return;
}
}
-
- int cut = 5; // file://
- while(cut < url.length() && url.charAt(cut)=='/')
- cut++;
-
- if(cut+1 >= url.length() || url.charAt(cut+1) != ':') // "/C:/" -> "C:/"
- cut--;
-
- String path = url.substring(cut);
- //System.out.println("opening file: "+path+" URL="+url);
- file = new File(path);
+
+ // modern browsers will handle urls with both encoded and non-encoded chars
+ // but there is no single way in java that will handle this mix
+ // so we will try to use java URI, but also fallback to doing it manually
+ try {
+ // supports url encoded spaces and other url encoded things
+ // a real space will cause a 'java.net.URISyntaxException: Illegal character in path'
+ URI fileUrl = new URI(url.replaceAll(" ", "%20"));
+ file = new File(fileUrl);
+ }
+ catch(Exception ex) {
+ // on windows some network urls WILL fail, so we HAVE to have a fallback
+ System.out.println("unable to convert using standard java: " + url + " " + ex);
+
+ // fall back to old method of converting url to file
+ int cut = 5; // file://
+ while(cut < url.length() && url.charAt(cut)=='/')
+ cut++;
+
+ if(cut+1 >= url.length() || url.charAt(cut+1) != ':') // "/C:/" -> "C:/"
+ cut--;
+
+ String path = url.substring(cut);
+ //System.out.println("opening file: "+path+" URL="+url);
+
+ // can not have %20 in the name or it will not find it, needs to be " ".
+ file = new File(path.replaceAll("\\%20"," "));
+ }
}
/*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|