From 5205e47e8a2e84e793b26305391b1c4f8648597c Mon Sep 17 00:00:00 2001
From: Sven Gothel
- * Impl. operates on the scheme-specific-part, and hence is sub-protocol savvy.
- *
- * In case baseURI is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used.
- *
- * schemeSpecificPart's query, if exist is split to path and query.
- *
- * In case path is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used.
- *
- * Implementation processes the ../
*/
public static String slashify(final String path, final boolean startWithSlash, final boolean endWithSlash) throws URISyntaxException {
- String p = path.replace('\\', '/'); // unify file separator
+ String p = patternSingleBS.matcher(path).replaceAll("/");
if (startWithSlash && !p.startsWith("/")) {
p = "/" + p;
}
@@ -308,24 +316,6 @@ public class IOUtil {
return cleanPathString(p);
}
- /**
- * Using the simple conversion via File -> URI, assuming proper characters.
- * @throws URISyntaxException if path is empty or has no parent directory available while resolving ../
- * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI
- */
- public static URI toURISimple(final File file) throws URISyntaxException {
- return new URI(FILE_SCHEME, null, slashify(file.getAbsolutePath(), true /* startWithSlash */, file.isDirectory() /* endWithSlash */), null);
- }
-
- /**
- * Using the simple conversion via File -> URI, assuming proper characters.
- * @throws URISyntaxException if path is empty or has no parent directory available while resolving ../
- * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI
- */
- public static URI toURISimple(final String protocol, final String path, final boolean isDirectory) throws URISyntaxException {
- return new URI(protocol, null, slashify(new File(path).getAbsolutePath(), true /* startWithSlash */, isDirectory /* endWithSlash */), null);
- }
-
/**
* Returns the lowercase suffix of the given file name (the text
* after the last '.' in the file name). Returns null if the file
@@ -445,6 +435,7 @@ public class IOUtil {
* @return "protocol:/some/path/"
* @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null
* @throws URISyntaxException
+ * @deprecated Use {@link Uri#getDirectory()}
*/
public static URI getURIDirname(final URI uri) throws IllegalArgumentException, URISyntaxException {
if(null == uri) {
@@ -468,6 +459,7 @@ public class IOUtil {
* @return "protocol:/some/path/"
* @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null
* @throws URISyntaxException
+ * @deprecated Use {@link Uri#getDirectory()}
*/
public static String getURIDirname(String uriS) throws IllegalArgumentException, URISyntaxException {
if(null == uriS) {
@@ -488,25 +480,11 @@ public class IOUtil {
uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':'
if( DEBUG ) {
- System.err.println("getJarURIDirname res: "+uriS);
+ System.err.println("getURIDirname res: "+uriS);
}
return uriS;
}
- /**
- * Simply returns {@link URI#toURL()}.
- * @param uri
- * @return
- * @throws IOException
- * @throws IllegalArgumentException
- * @throws URISyntaxException
- *
- * @deprecated Useless
- */
- public static URL toURL(final URI uri) throws IOException, IllegalArgumentException, URISyntaxException {
- return uri.toURL();
- }
-
/***
*
* RESOURCE LOCATION STUFF
@@ -705,177 +683,7 @@ public class IOUtil {
return path;
}
- /**
- * Generates a URI for the relativePath relative to the baseURI,
- * hence the result is a absolute location.
- * ../
- */
- public static URI getRelativeOf(final URI baseURI, final String relativePath) throws URISyntaxException {
- return compose(baseURI.getScheme(), baseURI.getRawSchemeSpecificPart(), relativePath, baseURI.getRawFragment());
- }
-
- /**
- * Wraps {@link #getRelativeOf(URI, String)} for convenience.
- * @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded)
- * @throws IOException
- */
- public static URL getRelativeOf(final URL baseURL, final String relativePath) throws IOException {
- try {
- return getRelativeOf(baseURL.toURI(), relativePath).toURL();
- } catch (final URISyntaxException e) {
- throw new IOException(e);
- }
- }
-
- /**
- * Generates a URI for the relativePath relative to the schemeSpecificPart,
- * hence the result is a absolute location.
- * ../
- * @see #encodeToURI(String)
- */
- public static URI compose(final String scheme, String schemeSpecificPart, final String relativePath, final String fragment) throws URISyntaxException {
- // cut off optional query in scheme-specific-part
- final String query;
- final int queryI = schemeSpecificPart.lastIndexOf('?');
- if( queryI >= 0 ) {
- query = schemeSpecificPart.substring(queryI+1);
- schemeSpecificPart = schemeSpecificPart.substring(0, queryI);
- } else {
- query = null;
- }
- if( null != relativePath ) {
- if( !schemeSpecificPart.endsWith("/") ) {
- schemeSpecificPart = getParentOf(schemeSpecificPart);
- }
- schemeSpecificPart = schemeSpecificPart + relativePath;
- }
- schemeSpecificPart = cleanPathString( schemeSpecificPart );
- final StringBuilder uri = new StringBuilder();
- uri.append(scheme);
- uri.append(':');
- uri.append(schemeSpecificPart);
- if ( null != query ) {
- uri.append('?');
- uri.append(query);
- }
- if ( null != fragment ) {
- uri.append('#');
- uri.append(fragment);
- }
- return new URI(uri.toString());
- }
-
- private static final Pattern patternSpaceRaw = Pattern.compile(" ");
- private static final Pattern patternSpaceEnc = Pattern.compile("%20");
-
- /**
- * Escapes characters not complying w/ RFC 2396 and the {@link URI#URI(String)} ctor.
- *
- *
- * @deprecated Useless
- */
- public static String encodeToURI(final String vanilla) {
- return patternSpaceRaw.matcher(vanilla).replaceAll("%20"); // Uri TODO: Uri.encode(vanilla, Uri.PATH_MIN_LEGAL);
- }
-
- /**
- * Reverses escaping of characters as performed via {@link #encodeToURI(String)}.
- *
- *
- * @deprecated Use {@link #decodeURIIfFilePath(URI)}
- */
- public static String decodeFromURI(final String encodedUri) {
- return patternSpaceEnc.matcher(encodedUri).replaceAll(" "); // Uri TODO: Uri.decode(encoded);
- }
-
- private static final Pattern patternSingleBS = Pattern.compile("\\\\{1}");
- private static final Pattern patternSingleFS = Pattern.compile("/{1}");
-
- /**
- * Encodes file path characters not complying w/ RFC 2396 and the {@link URI#URI(String)} ctor.
- * filePath
if {@link File#separatorChar} == '\\'
- * as follows:
- *
- *
- *
- * Note that this method does not perform space encoding, - * which can be utilized via {@link #encodeToURI(String)}. - *
- *
- * Even though Oracle's JarURLStreamHandler can handle backslashes and
- * erroneous URIs w/ e.g. Windows file 'syntax', other may not (Netbeans).
- * See Bug 857 - http://jogamp.org/bugzilla/show_bug.cgi?id=857
- *
- * Implementation decodes the space-encoding path={@link #decodeFromURI(String) decodeFromURI}(uriPath)
.
- *
- * Then it processes the path
if {@link File#separatorChar} == '\\'
- * as follows:
- *
uri
is a file scheme,
@@ -890,9 +698,7 @@ public class IOUtil {
* * Otherwise it returns the {@link URI#toASCIIString()} encoded URI. *
- * - * @see #decodeFromURI(String) - * @see #decodeURIToFilePath(String) + * @deprecated Use {@link Uri#getNativeFilePath()}. */ public static String decodeURIIfFilePath(final URI uri) { if( IOUtil.FILE_SCHEME.equals( uri.getScheme() ) ) { -- cgit v1.2.3