11package org .janelia .saalfeldlab .n5 ;
22
3- import java .io .*;
3+ import java .io .IOException ;
4+ import java .io .InputStream ;
5+ import java .io .OutputStream ;
6+ import java .io .Reader ;
7+ import java .io .Writer ;
48import java .nio .channels .Channels ;
59import java .nio .channels .FileChannel ;
610import java .nio .charset .StandardCharsets ;
1115// TODO: This only has to be public because of a test in another package. Fix that
1216public class LockedFileChannel implements LockedChannel {
1317
14- private final FileChannel channel ;
18+ private final FileChannel channel ;
1519 private ReleaseLock releaseLock ;
1620
1721 @ FunctionalInterface
@@ -27,50 +31,49 @@ public interface ReleaseLock {
2731 }
2832
2933 @ Override
30- public Reader newReader () throws N5Exception .N5IOException {
34+ public Reader newReader () throws N5Exception .N5IOException {
3135
32- return Channels .newReader (channel , StandardCharsets .UTF_8 .name ());
33- }
36+ return Channels .newReader (channel , StandardCharsets .UTF_8 .name ());
37+ }
3438
35- @ Override
36- public InputStream newInputStream () throws N5Exception .N5IOException {
39+ @ Override
40+ public InputStream newInputStream () throws N5Exception .N5IOException {
3741
38- return Channels .newInputStream (channel );
39- }
42+ return Channels .newInputStream (channel );
43+ }
4044
41- @ Override
42- public Writer newWriter () throws N5Exception .N5IOException {
45+ @ Override
46+ public Writer newWriter () throws N5Exception .N5IOException {
4347
44- truncateChannel ();
45- return Channels .newWriter (channel , StandardCharsets .UTF_8 .name ());
46- }
48+ truncateChannel ();
49+ return Channels .newWriter (channel , StandardCharsets .UTF_8 .name ());
50+ }
4751
48- @ Override
49- public OutputStream newOutputStream () throws N5Exception .N5IOException {
52+ @ Override
53+ public OutputStream newOutputStream () throws N5Exception .N5IOException {
5054
51- truncateChannel ();
52- return Channels .newOutputStream (channel );
53- }
55+ truncateChannel ();
56+ return Channels .newOutputStream (channel );
57+ }
5458
5559 // TODO: This only has to be public because of a test in another package. Fix that
56- public FileChannel getFileChannel () {
60+ public FileChannel getFileChannel () {
5761
58- return channel ;
59- }
62+ return channel ;
63+ }
6064
61- private void truncateChannel () throws N5Exception .N5IOException {
65+ private void truncateChannel () throws N5Exception .N5IOException {
6266
63- try {
64- channel .truncate (0 );
65- } catch (final IOException e ) {
66- throw new N5Exception .N5IOException ("Failed to truncate channel" , e );
67- }
68- }
67+ try {
68+ channel .truncate (0 );
69+ } catch (final IOException e ) {
70+ throw new N5Exception .N5IOException ("Failed to truncate channel" , e );
71+ }
72+ }
6973
70- @ Override
71- public void close () throws IOException {
74+ @ Override
75+ public void close () throws IOException {
7276
73- channel .close ();
7477 if (releaseLock != null ) {
7578 releaseLock .release ();
7679 releaseLock = null ;
0 commit comments