|
28 | 28 | */ |
29 | 29 | package org.janelia.saalfeldlab.n5; |
30 | 30 |
|
31 | | -import java.io.IOException; |
| 31 | +import java.io.OutputStreamWriter; |
32 | 32 | import java.io.UncheckedIOException; |
| 33 | +import java.nio.charset.StandardCharsets; |
33 | 34 | import java.util.Arrays; |
34 | 35 | import java.util.List; |
35 | 36 | import java.util.Map; |
|
38 | 39 | import java.util.concurrent.ExecutionException; |
39 | 40 | import java.util.concurrent.ExecutorService; |
40 | 41 | import org.janelia.saalfeldlab.n5.N5Exception.N5IOException; |
| 42 | +import org.janelia.saalfeldlab.n5.readdata.ReadData; |
41 | 43 | import org.janelia.saalfeldlab.n5.shard.PositionValueAccess; |
42 | 44 |
|
43 | 45 | import com.google.gson.Gson; |
@@ -97,9 +99,14 @@ default void writeAttributes( |
97 | 99 | final String normalGroupPath, |
98 | 100 | final JsonElement attributes) throws N5Exception { |
99 | 101 |
|
100 | | - try (final LockedChannel lock = getKeyValueAccess().lockForWriting(absoluteAttributesPath(normalGroupPath))) { |
101 | | - GsonUtils.writeAttributes(lock.newWriter(), attributes, getGson()); |
102 | | - } catch (final IOException | UncheckedIOException | N5IOException e) { |
| 102 | + final ReadData newAttributesReadData = ReadData.from(os -> { |
| 103 | + final OutputStreamWriter writer = new OutputStreamWriter(os, StandardCharsets.UTF_8); |
| 104 | + GsonUtils.writeAttributes(writer, attributes, getGson()); |
| 105 | + }); |
| 106 | + |
| 107 | + try { |
| 108 | + getKeyValueAccess().write(absoluteAttributesPath(normalGroupPath), newAttributesReadData); |
| 109 | + } catch (UncheckedIOException | N5IOException e) { |
103 | 110 | throw new N5Exception.N5IOException("Failed to write attributes into " + normalGroupPath, e); |
104 | 111 | } |
105 | 112 | } |
|
0 commit comments