@@ -229,22 +229,21 @@ public void writeData(STDataAssembly data) throws IOException {
229229 if (readOnly )
230230 throw new IllegalStateException ("Trying to write to read-only file." );
231231
232- N5Writer writer = (N5Writer ) ioSupplier .get ();
233- STData stData = data .data ();
232+ try ( N5Writer writer = (N5Writer ) ioSupplier .get ()) {
233+ STData stData = data .data ();
234234
235- logger .debug ( "Saving spatial data ... " );
236- long time = System .currentTimeMillis ();
237-
238- initializeDataset (writer , stData );
235+ logger .debug ("Saving spatial data ... " );
236+ long time = System .currentTimeMillis ();
239237
240- writeExpressionValues (writer , stData .getAllExprValues ());
241- writeLocations (writer , stData .getLocations ());
242- updateTransformation (writer , data .transform (), transformFieldName );
243- //writeTransformation(writer, data.intensityTransform(), "intensity_transform");
238+ initializeDataset (writer , stData );
244239
245- updateStoredAnnotations (stData .getAnnotations ());
240+ writeExpressionValues (writer , stData .getAllExprValues ());
241+ writeLocations (writer , stData .getLocations ());
242+ updateTransformation (writer , data .transform (), transformFieldName );
246243
247- logger .debug ("Saving took {} ms." , System .currentTimeMillis () - time );
244+ updateStoredAnnotations (stData .getAnnotations ());
245+ logger .debug ("Saving took {} ms." , System .currentTimeMillis () - time );
246+ }
248247 }
249248
250249 /**
@@ -256,14 +255,15 @@ public void updateStoredAnnotations(Map<String, RandomAccessibleInterval<? exten
256255 if (readOnly )
257256 throw new IllegalStateException ("Trying to write to read-only file." );
258257
259- N5Writer writer = (N5Writer ) ioSupplier .get ();
260- List <String > existingAnnotations = detectAnnotations (writer );
258+ try ( N5Writer writer = (N5Writer ) ioSupplier .get ()) {
259+ List <String > existingAnnotations = detectAnnotations (writer );
261260
262- for (Entry <String , RandomAccessibleInterval <? extends NativeType <?>>> newEntry : metadata .entrySet ()) {
263- if (existingAnnotations .contains (newEntry .getKey ()))
264- logger .warn ("Metadata '{}' already exists. Skip writing." , newEntry .getKey ());
265- else
266- writeAnnotations (writer , newEntry .getKey (), newEntry .getValue ());
261+ for (Entry <String , RandomAccessibleInterval <? extends NativeType <?>>> newEntry : metadata .entrySet ()) {
262+ if (existingAnnotations .contains (newEntry .getKey ()))
263+ logger .warn ("Metadata '{}' already exists. Skip writing." , newEntry .getKey ());
264+ else
265+ writeAnnotations (writer , newEntry .getKey (), newEntry .getValue ());
266+ }
267267 }
268268 }
269269
@@ -276,14 +276,15 @@ public void updateStoredGeneAnnotations(Map<String, RandomAccessibleInterval<? e
276276 if (readOnly )
277277 throw new IllegalStateException ("Trying to write to read-only file." );
278278
279- N5Writer writer = (N5Writer ) ioSupplier .get ();
280- List <String > existingGeneAnnotations = detectGeneAnnotations (writer );
279+ try ( N5Writer writer = (N5Writer ) ioSupplier .get ()) {
280+ List <String > existingGeneAnnotations = detectGeneAnnotations (writer );
281281
282- for (Entry <String , RandomAccessibleInterval <? extends NativeType <?>>> newEntry : metadata .entrySet ()) {
283- if (existingGeneAnnotations .contains (newEntry .getKey ()))
284- logger .warn ("Metadata '{}' already exists. Skip writing." , newEntry .getKey ());
285- else
286- writeGeneAnnotations (writer , newEntry .getKey (), newEntry .getValue ());
282+ for (Entry <String , RandomAccessibleInterval <? extends NativeType <?>>> newEntry : metadata .entrySet ()) {
283+ if (existingGeneAnnotations .contains (newEntry .getKey ()))
284+ logger .warn ("Metadata '{}' already exists. Skip writing." , newEntry .getKey ());
285+ else
286+ writeGeneAnnotations (writer , newEntry .getKey (), newEntry .getValue ());
287+ }
287288 }
288289 }
289290
@@ -327,8 +328,9 @@ public void updateTransformation(AffineGet transform, String name) throws IOExce
327328 if (readOnly )
328329 throw new IllegalStateException ("Trying to modify a read-only file." );
329330
330- N5Writer writer = (N5Writer ) ioSupplier .get ();
331- updateTransformation (writer , transform , name );
331+ try (N5Writer writer = (N5Writer ) ioSupplier .get ()) {
332+ updateTransformation (writer , transform , name );
333+ }
332334 }
333335
334336 /**
0 commit comments