Skip to content

Commit c61aa5e

Browse files
committed
refactor: migrate IOExceptions to N5IOExceptions for ReadData and related logic
1 parent 8bfbc5f commit c61aa5e

15 files changed

Lines changed: 249 additions & 191 deletions

src/main/java/org/janelia/saalfeldlab/n5/Bzip2Compression.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -58,6 +58,7 @@
5858
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
5959
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
6060
import org.janelia.saalfeldlab.n5.Compression.CompressionType;
61+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
6162
import org.janelia.saalfeldlab.n5.readdata.ReadData;
6263

6364
@CompressionType("bzip2")
@@ -88,9 +89,12 @@ public boolean equals(final Object other) {
8889
}
8990

9091
@Override
91-
public ReadData decode(final ReadData readData) throws IOException {
92-
93-
return ReadData.from(new BZip2CompressorInputStream(readData.inputStream()));
92+
public ReadData decode(final ReadData readData) throws N5IOException {
93+
try {
94+
return ReadData.from(new BZip2CompressorInputStream(readData.inputStream()));
95+
} catch (IOException e) {
96+
throw new N5IOException(e);
97+
}
9498
}
9599

96100
@Override

src/main/java/org/janelia/saalfeldlab/n5/Compression.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -60,6 +60,8 @@
6060
import java.lang.annotation.Retention;
6161
import java.lang.annotation.RetentionPolicy;
6262
import java.lang.annotation.Target;
63+
64+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
6365
import org.janelia.saalfeldlab.n5.readdata.ReadData;
6466
import org.scijava.annotations.Indexable;
6567

@@ -116,10 +118,10 @@ default String getType() {
116118
*
117119
* @return decoded ReadData
118120
*
119-
* @throws IOException
121+
* @throws N5IOException
120122
* if any I/O error occurs
121123
*/
122-
ReadData decode(ReadData readData) throws IOException;
124+
ReadData decode(ReadData readData) throws N5IOException;
123125

124126
/**
125127
* Encode the given {@code readData}.
@@ -132,9 +134,9 @@ default String getType() {
132134
*
133135
* @return encoded ReadData
134136
*
135-
* @throws IOException
137+
* @throws N5IOException
136138
* if any I/O error occurs
137139
*/
138-
ReadData encode(ReadData readData) throws IOException;
140+
ReadData encode(ReadData readData) throws N5IOException;
139141

140142
}

src/main/java/org/janelia/saalfeldlab/n5/FileSystemKeyValueAccess.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
*/
5454
package org.janelia.saalfeldlab.n5;
5555

56+
import org.janelia.saalfeldlab.n5.N5Exception.N5NoSuchKeyException;
57+
5658
import java.io.File;
5759
import java.io.IOException;
5860
import java.io.InputStream;
@@ -191,8 +193,8 @@ public LockedFileChannel lockForReading(final String normalPath) throws IOExcept
191193

192194
try {
193195
return new LockedFileChannel(normalPath, true);
194-
} catch (NoSuchFileException e) {
195-
throw new N5Exception.N5NoSuchKeyException("No such file", e);
196+
} catch (final NoSuchFileException e) {
197+
throw new N5NoSuchKeyException("No such file", e);
196198
}
197199
}
198200

@@ -206,8 +208,8 @@ public LockedFileChannel lockForReading(final Path path) throws IOException {
206208

207209
try {
208210
return new LockedFileChannel(path, true);
209-
} catch (NoSuchFileException e) {
210-
throw new N5Exception.N5NoSuchKeyException("No such file", e);
211+
} catch (final NoSuchFileException e) {
212+
throw new N5NoSuchKeyException("No such file", e);
211213
}
212214
}
213215

src/main/java/org/janelia/saalfeldlab/n5/GzipCompression.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
6363
import org.apache.commons.compress.compressors.gzip.GzipParameters;
6464
import org.janelia.saalfeldlab.n5.Compression.CompressionType;
65+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
6566
import org.janelia.saalfeldlab.n5.readdata.ReadData;
6667

6768
@CompressionType("gzip")
@@ -113,13 +114,17 @@ private InputStream decode(final InputStream in) throws IOException {
113114
}
114115

115116
@Override
116-
public ReadData decode(final ReadData readData) throws IOException {
117+
public ReadData decode(final ReadData readData) throws N5IOException {
117118

118-
return ReadData.from(decode(readData.inputStream()));
119+
try {
120+
return ReadData.from(decode(readData.inputStream()));
121+
} catch (IOException e) {
122+
throw new N5IOException(e);
123+
}
119124
}
120125

121126
@Override
122-
public ReadData encode(final ReadData readData) {
127+
public ReadData encode(final ReadData readData) {
123128
if (useZlib) {
124129
return readData.encode(out -> new DeflaterOutputStream(out, new Deflater(level)));
125130
} else {

src/main/java/org/janelia/saalfeldlab/n5/HttpKeyValueAccess.java

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,30 +26,11 @@
2626
* POSSIBILITY OF SUCH DAMAGE.
2727
* #L%
2828
*/
29-
/**
30-
* Copyright (c) 2017, Stephan Saalfeld All rights reserved.
31-
* <p>
32-
* Redistribution and use in source and binary forms, with or without modification, are permitted
33-
* provided that the following conditions are met:
34-
* <p>
35-
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
36-
* and the following disclaimer. 2. Redistributions in binary form must reproduce the above
37-
* copyright notice, this list of conditions and the following disclaimer in the documentation
38-
* and/or other materials provided with the distribution.
39-
* <p>
40-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
41-
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
42-
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
43-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45-
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
46-
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
47-
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48-
*/
4929
package org.janelia.saalfeldlab.n5;
5030

5131
import org.apache.commons.io.IOUtils;
5232
import org.apache.commons.lang3.function.TriFunction;
33+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
5334
import org.janelia.saalfeldlab.n5.http.ListResponseParser;
5435

5536
import java.io.Closeable;
@@ -85,7 +66,7 @@ public class HttpKeyValueAccess implements KeyValueAccess {
8566
/**
8667
* Opens an {@link HttpKeyValueAccess}
8768
*
88-
* @throws N5Exception.N5IOException if the access could not be created
69+
* @throws N5IOException if the access could not be created
8970
*/
9071
public HttpKeyValueAccess() {
9172

@@ -296,7 +277,7 @@ private String[] queryListEntries(String normalPath, ListResponseParser parser,
296277
final String listResponse = responseToString(http.getInputStream());
297278
return parser.parseListResponse(listResponse);
298279
} catch (IOException e) {
299-
throw new N5Exception.N5IOException("Error listing directory at " + normalPath, e);
280+
throw new N5IOException("Error listing directory at " + normalPath, e);
300281
}
301282
}
302283

@@ -324,7 +305,7 @@ private HttpURLConnection requireValidHttpResponse(String uri, String method, Tr
324305
code = http.getResponseCode();
325306
responseMsg = http.getResponseMessage();
326307
} catch (IOException e) {
327-
throw new N5Exception.N5IOException("Could not validate HTTP Response", e);
308+
throw new N5IOException("Could not validate HTTP Response", e);
328309
}
329310

330311
final N5Exception cause = filterCode.apply(code, responseMsg, http);

src/main/java/org/janelia/saalfeldlab/n5/Lz4Compression.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -53,10 +53,10 @@
5353
*/
5454
package org.janelia.saalfeldlab.n5;
5555

56-
import java.io.IOException;
5756
import net.jpountz.lz4.LZ4BlockInputStream;
5857
import net.jpountz.lz4.LZ4BlockOutputStream;
5958
import org.janelia.saalfeldlab.n5.Compression.CompressionType;
59+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
6060
import org.janelia.saalfeldlab.n5.readdata.ReadData;
6161

6262
@CompressionType("lz4")
@@ -87,7 +87,7 @@ public boolean equals(final Object other) {
8787
}
8888

8989
@Override
90-
public ReadData decode(final ReadData readData) throws IOException {
90+
public ReadData decode(final ReadData readData) throws N5IOException {
9191

9292
return ReadData.from(new LZ4BlockInputStream(readData.inputStream()));
9393
}

src/main/java/org/janelia/saalfeldlab/n5/XzCompression.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -54,10 +54,10 @@
5454
package org.janelia.saalfeldlab.n5;
5555

5656
import java.io.IOException;
57-
import java.io.InputStream;
5857
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
5958
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
6059
import org.janelia.saalfeldlab.n5.Compression.CompressionType;
60+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
6161
import org.janelia.saalfeldlab.n5.readdata.ReadData;
6262

6363
@CompressionType("xz")
@@ -88,9 +88,13 @@ public boolean equals(final Object other) {
8888
}
8989

9090
@Override
91-
public ReadData decode(final ReadData readData) throws IOException {
91+
public ReadData decode(final ReadData readData) throws N5IOException {
9292

93-
return ReadData.from(new XZCompressorInputStream(readData.inputStream()));
93+
try {
94+
return ReadData.from(new XZCompressorInputStream(readData.inputStream()));
95+
} catch (IOException e) {
96+
throw new N5IOException(e);
97+
}
9498
}
9599

96100
@Override

src/main/java/org/janelia/saalfeldlab/n5/codec/DataBlockCodec.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
*/
2929
package org.janelia.saalfeldlab.n5.codec;
3030

31-
import java.io.IOException;
3231
import org.janelia.saalfeldlab.n5.DataBlock;
32+
import org.janelia.saalfeldlab.n5.N5Exception;
33+
import org.janelia.saalfeldlab.n5.N5Exception.N5IOException;
3334
import org.janelia.saalfeldlab.n5.readdata.ReadData;
3435

3536
/**
@@ -40,7 +41,7 @@
4041
*/
4142
public interface DataBlockCodec<T> {
4243

43-
ReadData encode(DataBlock<T> dataBlock) throws IOException;
44+
ReadData encode(DataBlock<T> dataBlock) throws N5IOException;
4445

45-
DataBlock<T> decode(ReadData readData, long[] gridPosition) throws IOException;
46+
DataBlock<T> decode(ReadData readData, long[] gridPosition) throws N5IOException;
4647
}

0 commit comments

Comments
 (0)