Skip to content

Commit

Permalink
remove Paths.getFileName() to hopefully fix a Windows-path related bu…
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Nov 11, 2024
1 parent e1d9a5e commit 335203e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -58,7 +56,6 @@
import mpicbg.spim.data.sequence.Angle;
import mpicbg.spim.data.sequence.Channel;
import mpicbg.spim.data.sequence.Illumination;
import mpicbg.spim.data.sequence.ImgLoader;
import mpicbg.spim.data.sequence.Tile;
import mpicbg.spim.data.sequence.TimePoint;
import net.preibisch.legacy.io.IOFunctions;
Expand Down Expand Up @@ -715,7 +712,7 @@ protected boolean tryParsing( final URI xmlURI, final boolean parseAllTypes )
{
this.data = parseXML( xmlURI );

this.xmlFileName = Paths.get(xmlURI.getPath()).getFileName().toString();
this.xmlFileName = URITools.getFileName(xmlURI); //Paths.get(xmlURI.getPath()).getFileName().toString();

// which attributes
this.attributes = getAttributes( data, comparator );
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/util/URITools.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.Date;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -671,7 +670,19 @@ public static String fromURI( final URI uri )

public static String getFileName( final URI uri )
{
return Paths.get( uri.getPath() ).getFileName().toString();
int l1 = uri.toString().length();
int l2 = l1;
try
{
l2 = getParentURI( uri ).toString().length();
}
catch (SpimDataIOException e)
{
IOFunctions.println( "Error getting the parent URI for '" + uri + "' in order to extract the filename. Returning entire URI as filename, even though this is most likely wrong: " + e );
e.printStackTrace();
}

return uri.toString().substring( l2, l1 );
}

public static String appendName( final URI uri, final String name )
Expand Down Expand Up @@ -744,10 +755,12 @@ public static void minimalExampleTobiS3GS() throws URISyntaxException, IOExcepti

public static void main( String[] args ) throws SpimDataException, IOException, URISyntaxException
{
URI uri1 = URITools.toURI( "s3://aind-open-data/exaSPIM_708373_2024-04-02_19-49-38/SPIM.ome.zarr" );
URI uri1 = URITools.toURI( "s3://aind-open-data/exaSPIM_708373_2024-04-02_19-49-38/SPIM.ome.zarr/" );

System.out.println( uri1.getHost() );
System.out.println( uri1.getPath() );
System.out.println( getFileName( uri1 ) );

System.exit( 0 );

minimalExampleTobiS3GS();
Expand Down

0 comments on commit 335203e

Please sign in to comment.