1818import software .amazon .awssdk .services .s3 .S3Client ;
1919
2020import java .io .IOException ;
21+ import java .io .InputStream ;
22+ import java .nio .ByteBuffer ;
2123import java .nio .file .Files ;
2224import java .util .ArrayList ;
2325import java .util .Arrays ;
@@ -103,6 +105,55 @@ public void testS3StoreGet() throws IOException, ZarrException {
103105
104106 }
105107
108+ static Stream <StoreHandle > inputStreamStores () throws IOException {
109+ String [] s3StoreKeys = new String []{"zarr_v3" , "l4_sample" , "color" , "1" , "zarr.json" };
110+ StoreHandle s3StoreHandle = new S3Store (S3Client .builder ()
111+ .region (Region .of ("eu-west-1" ))
112+ .credentialsProvider (AnonymousCredentialsProvider .create ())
113+ .build (), "static.webknossos.org" , "data" )
114+ .resolve (s3StoreKeys );
115+
116+ byte [] testData = new byte [100 ];
117+ for (int i = 0 ; i < testData .length ; i ++) {
118+ testData [i ] = (byte ) i ;
119+ }
120+
121+ StoreHandle memoryStoreHandle = new MemoryStore ().resolve ();
122+ memoryStoreHandle .set (ByteBuffer .wrap (testData ));
123+
124+ StoreHandle fsStoreHandle = new FilesystemStore (TESTOUTPUT .resolve ("testInputStreamFS" )).resolve ("testfile" );
125+ fsStoreHandle .set (ByteBuffer .wrap (testData ));
126+
127+ zipFile (TESTOUTPUT .resolve ("testInputStreamFS" ), TESTOUTPUT .resolve ("testInputStreamZIP.zip" ));
128+ StoreHandle bufferedZipStoreHandle = new BufferedZipStore (TESTOUTPUT .resolve ("testInputStreamZIP.zip" ), true )
129+ .resolve ("testfile" );
130+
131+ StoreHandle readOnlyZipStoreHandle = new ReadOnlyZipStore (TESTOUTPUT .resolve ("testInputStreamZIP.zip" ))
132+ .resolve ("testfile" );
133+
134+ StoreHandle httpStoreHandle = new HttpStore ("https://static.webknossos.org/data/zarr_v3/l4_sample" )
135+ .resolve ("color" , "1" , "zarr.json" );
136+ return Stream .of (
137+ memoryStoreHandle ,
138+ s3StoreHandle ,
139+ fsStoreHandle ,
140+ bufferedZipStoreHandle ,
141+ readOnlyZipStoreHandle ,
142+ httpStoreHandle
143+ );
144+ }
145+
146+ @ ParameterizedTest
147+ @ MethodSource ("inputStreamStores" )
148+ public void testStoreInputStream (StoreHandle storeHandle ) throws IOException , ZarrException {
149+ InputStream is = storeHandle .getInputStream (10 , 20 );
150+ byte [] buffer = new byte [10 ];
151+ int bytesRead = is .read (buffer );
152+ Assertions .assertEquals (10 , bytesRead );
153+ byte [] expectedBuffer = new byte [10 ];
154+ storeHandle .read (10 , 20 ).get (expectedBuffer );
155+ Assertions .assertArrayEquals (expectedBuffer , buffer );
156+ }
106157
107158 @ Test
108159 public void testHttpStore () throws IOException , ZarrException {
@@ -115,8 +166,7 @@ public void testHttpStore() throws IOException, ZarrException {
115166 @ ParameterizedTest
116167 @ CsvSource ({"false" , "true" ,})
117168 public void testMemoryStoreV3 (boolean useParallel ) throws ZarrException , IOException {
118- int [] testData = new int [1024 * 1024 ];
119- Arrays .setAll (testData , p -> p );
169+ int [] testData = testData ();
120170
121171 dev .zarr .zarrjava .v3 .Group group = dev .zarr .zarrjava .v3 .Group .create (new MemoryStore ().resolve ());
122172 Array array = group .createArray ("array" , b -> b
@@ -140,8 +190,7 @@ public void testMemoryStoreV3(boolean useParallel) throws ZarrException, IOExcep
140190 @ ParameterizedTest
141191 @ CsvSource ({"false" , "true" ,})
142192 public void testMemoryStoreV2 (boolean useParallel ) throws ZarrException , IOException {
143- int [] testData = new int [1024 * 1024 ];
144- Arrays .setAll (testData , p -> p );
193+ int [] testData = testData ();
145194
146195 dev .zarr .zarrjava .v2 .Group group = dev .zarr .zarrjava .v2 .Group .create (new MemoryStore ().resolve ());
147196 dev .zarr .zarrjava .v2 .Array array = group .createArray ("array" , b -> b
0 commit comments