Skip to content

Commit

Permalink
improve the toFile() code - without exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Oct 12, 2024
1 parent 0ef7a1f commit 7f4e991
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/util/URITools.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@ public static boolean isFile( URI uri )

public static File toFile( final URI uri )
{
if ( !isFile( uri ) )
throw new RuntimeException( "Cannot make a java.io.File from '" + uri + "'" );

// otherwise triggers Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
if ( !uri.toString().toLowerCase().startsWith( "file:") )
return new File( uri.toString() );
else
return new File( uri );

/*
File f;
try
{
Expand All @@ -481,7 +491,7 @@ public static File toFile( final URI uri )
f = new File( uri.toString() );
}
return f;
return f;*/
}

public static String removeFilePrefix( URI uri )
Expand Down

0 comments on commit 7f4e991

Please sign in to comment.