Skip to content

Commit

Permalink
Add UriParser for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Oct 26, 2024
1 parent 5031f5b commit 8b30b85
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/test/java/develop/UriParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package develop;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;

public class UriParser
{
public static void main( String[] args ) throws URISyntaxException, MalformedURLException
{
parseUri( new URI( "file:/Volumes/test" ) );
parseUri( new URI( "/Volumes/test" ) );
parseUri( new URI( "https://fiji.sc" ) );
parseUri( new URI("C:/test") );
}

public static void parseUri( URI uri ) throws MalformedURLException, URISyntaxException
{
if ( uri.getScheme() == null )
{
System.out.println("--");
System.out.println("Missing schema, treating as file." );
treatAsFile( new URI( "file:" + uri ) );
}
else if ( uri.getScheme().contains( "file" ) )
{
System.out.println("--");
treatAsFile( uri );
}
else if ( uri.getScheme().contains( "http" ) )
{
System.out.println("--");
String address = uri.toURL().toString();
System.out.println("http address: " + address);
}
else
{
System.out.println("--");
System.out.println("Unknown schema: " + uri.getScheme() + ", treating as File." );
treatAsFile( new URI( "file:" + uri ) );
}
}

private static void treatAsFile( URI uri ) throws MalformedURLException
{
String path = uri.toURL().getPath();
File file = new File( path );
System.out.println("File path: " + file.getAbsolutePath() );
}
}

0 comments on commit 8b30b85

Please sign in to comment.