From 76147048d088a339183ea6cdf03bc4ad2003ebb8 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Wed, 25 Sep 2024 14:11:23 -0400 Subject: [PATCH] fix reading/writing of arbitrary files to cloud storage --- src/main/java/util/URITools.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/util/URITools.java b/src/main/java/util/URITools.java index 2816cae9..59c1526b 100644 --- a/src/main/java/util/URITools.java +++ b/src/main/java/util/URITools.java @@ -78,7 +78,7 @@ else if ( URITools.isS3( xmlURI ) || URITools.isGC( xmlURI ) ) try { pb = URITools.parseCloudLink( xmlURI.toString() ); - kva = URITools.getKeyValueAccessForBucket( pb ); + kva = URITools.getWriteKeyValueAccessForBucket( pb ); } catch ( Exception e ) { @@ -298,7 +298,7 @@ else if ( URITools.isS3( xmlURI ) || URITools.isGC( xmlURI ) ) //super.load(null, xmlURI); // how do I use this? final ParsedBucket pb = URITools.parseCloudLink( xmlURI.toString() ); - final KeyValueAccess kva = URITools.getKeyValueAccessForBucket( pb ); + final KeyValueAccess kva = URITools.getReadKeyValueAccessForBucket( pb ); final SAXBuilder sax = new SAXBuilder(); Document doc; @@ -330,6 +330,7 @@ else if ( URITools.isS3( xmlURI ) || URITools.isGC( xmlURI ) ) } } + /* public static KeyValueAccess getKeyValueAccessForBucket( String bucketUri ) { final N5Reader n5r = new N5Factory().openReader( StorageFormat.N5, bucketUri ); @@ -337,15 +338,24 @@ public static KeyValueAccess getKeyValueAccessForBucket( String bucketUri ) return kva; } + */ - public static KeyValueAccess getKeyValueAccessForBucket( ParsedBucket pb ) + public static KeyValueAccess getReadKeyValueAccessForBucket( final ParsedBucket pb ) { - final N5Reader n5r = new N5Factory().openReader( StorageFormat.N5, pb.protocol + pb.bucket ); + final N5Reader n5r = instantiateN5Reader(StorageFormat.N5, URI.create( pb.protocol + pb.bucket ) );//new N5Factory().openReader( StorageFormat.N5, pb.protocol + pb.bucket ); final KeyValueAccess kva = ((GsonKeyValueN5Reader)n5r).getKeyValueAccess(); return kva; } + public static KeyValueAccess getWriteKeyValueAccessForBucket( final ParsedBucket pb ) + { + final N5Writer n5w = instantiateN5Writer(StorageFormat.N5, URI.create( pb.protocol + pb.bucket ) );//new N5Factory().openReader( StorageFormat.N5, pb.protocol + pb.bucket ); + final KeyValueAccess kva = ((GsonKeyValueN5Reader)n5w).getKeyValueAccess(); + + return kva; + } + public static ParsedBucket parseCloudLink( final String uri ) { System.out.println( "Parsing link path for '" + uri + "':" );