Skip to content

Commit

Permalink
refactor: N5URI.from
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Apr 25, 2024
1 parent 816b1be commit 83822b1
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/main/java/org/janelia/saalfeldlab/n5/N5URI.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,35 +600,27 @@ public static N5URI from(
*/
public static N5URI from(final String uriOrPath) {

URI uri = null;
try {
uri = new URI(uriOrPath);
// System.out.println("direct uri: " + uri.toString());
return new N5URI(uri);
return new N5URI(new URI(uriOrPath));
} catch (Throwable ignore) {}

try {
final String[] split = uriOrPath.split("\\?");
final URI tmp = Paths.get(split[0]).toUri();
System.out.println("tmp: " + tmp.toString());
if (split.length == 1)
uri = tmp;
return new N5URI(tmp);
else {
StringBuffer buildUri = new StringBuffer();
buildUri.append(tmp.toString());
buildUri.append("?");
for (int i = 1; i < split.length; i++)
buildUri.append(split[i]);

uri = new URI(buildUri.toString());
// System.out.println("path uri: " + uri.toString());
return new N5URI(uri);
return new N5URI(new URI(buildUri.toString()));
}
} catch (Throwable ignore) {}

try {
uri = N5URI.encodeAsUri(uriOrPath);
// System.out.println("encoded uri: " + uri.toString());
return new N5URI(N5URI.encodeAsUri(uriOrPath));
} catch (URISyntaxException e) {
throw new N5Exception(e);
Expand Down

0 comments on commit 83822b1

Please sign in to comment.