Skip to content

Commit

Permalink
centralize the URITools.toFile() method (see change in URITools @tpie…
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Oct 11, 2024
1 parent 691e863 commit 3d1f5fe
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1318,16 +1318,6 @@ else if (resaveAsN5)

data = Resave_N5Api.resaveN5( data, viewIds, n5params, false );

// Re-assemble a new SpimData object containing the subset of viewsetups and timepoints selected
//final SpimData2 newSpimData = Resave_TIFF.assemblePartialSpimData2( data, viewIds, chosenPathXMLURI , new ArrayList<>() );

// replace imgLoader
//newSpimData.getSequenceDescription().setImgLoader( new N5ImageLoader( n5DatasetURI, newSpimData.getSequenceDescription() ) );
//newSpimData.setBasePathURI( chosenPathXMLURI );

// replace the spimdata object
//data = newSpimData;

IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + "): N5 resave finished." );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ else if ( N5ImageLoader.class.isInstance( imgLoader ) )
final URI n5URI = ((N5ImageLoader)imgLoader).getN5URI();

IOFunctions.println( "Path of N5 (stays in old location): " + n5URI );
data.getSequenceDescription().setImgLoader( new N5ImageLoader( n5URI, data.getSequenceDescription() ) );
data.getSequenceDescription().setImgLoader( new N5ImageLoader( URITools.toFile( n5URI ), data.getSequenceDescription() ) );
}
else if ( Hdf5ImageLoader.class.isInstance( imgLoader ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,9 @@ public static SpimData2 resaveN5(

if ( format == StorageFormat.N5 && URITools.isFile( n5Params.n5URI )) // local file
{
File f;
try
{
// might trigger Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
f = new File( n5Params.n5URI );
}
catch ( Exception e )
{
f = new File( n5Params.n5URI.toString() );
}

// we need to init with File and not with URI, since otherwise the N5ImageLoader will trigger the exception above if this object is re-used
// this seems to not matter when opening directly from disc...
sdReduced.getSequenceDescription().setImgLoader( new N5ImageLoader( f, sdReduced.getSequenceDescription() ) );
sdReduced.getSequenceDescription().setImgLoader( new N5ImageLoader( URITools.toFile( n5Params.n5URI ), sdReduced.getSequenceDescription() ) );
n5Writer.close();
}
else if ( format == StorageFormat.N5 ) // some cloud location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,6 @@ else if (index == 4 || index == 5) // 4 == in-place, 5 == choose path

final SpimData2 newSpimData = Resave_N5Api.resaveN5( data, viewIds, n5params, false );

// replace imgLoader
//newSpimData.getSequenceDescription().setImgLoader( new N5ImageLoader( n5params.n5URI, newSpimData.getSequenceDescription() ) );
//newSpimData.setBasePathURI( basePathURI );

// make sure interestpoints are saved to the new location as well
if ( index == 5 && !n5params.xmlURI.equals( panel.xml() ) )
{
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/util/URITools.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,23 @@ public static boolean isFile( URI uri )
return !hasScheme || FILE_SCHEME.asPredicate().test( scheme );
}

public static File toFile( final URI uri )
{
File f;
try
{
// might trigger Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
// if it is like '/nrs/test.xml' and not 'file:/nrs/test.xml'
f = new File( uri );
}
catch ( Exception e )
{
f = new File( uri.toString() );
}

return f;
}

public static String removeFilePrefix( URI uri )
{
final String scheme = uri.getScheme();
Expand Down

0 comments on commit 3d1f5fe

Please sign in to comment.