|
@@ -102,18 +102,23 @@ public class SnapStream {
|
|
|
public static CheckedInputStream getInputStream(File file) throws IOException {
|
|
|
FileInputStream fis = new FileInputStream(file);
|
|
|
InputStream is;
|
|
|
- switch (getStreamMode(file.getName())) {
|
|
|
- case GZIP:
|
|
|
- is = new GZIPInputStream(fis);
|
|
|
- break;
|
|
|
- case SNAPPY:
|
|
|
- is = new SnappyInputStream(fis);
|
|
|
- break;
|
|
|
- case CHECKED:
|
|
|
- default:
|
|
|
- is = new BufferedInputStream(fis);
|
|
|
+ try {
|
|
|
+ switch (getStreamMode(file.getName())) {
|
|
|
+ case GZIP:
|
|
|
+ is = new GZIPInputStream(fis);
|
|
|
+ break;
|
|
|
+ case SNAPPY:
|
|
|
+ is = new SnappyInputStream(fis);
|
|
|
+ break;
|
|
|
+ case CHECKED:
|
|
|
+ default:
|
|
|
+ is = new BufferedInputStream(fis);
|
|
|
+ }
|
|
|
+ return new CheckedInputStream(is, new Adler32());
|
|
|
+ } catch (IOException e) {
|
|
|
+ fis.close();
|
|
|
+ throw e;
|
|
|
}
|
|
|
- return new CheckedInputStream(is, new Adler32());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -129,9 +134,16 @@ public class SnapStream {
|
|
|
OutputStream os;
|
|
|
switch (streamMode) {
|
|
|
case GZIP:
|
|
|
- os = new GZIPOutputStream(fos);
|
|
|
+ try {
|
|
|
+ os = new GZIPOutputStream(fos);
|
|
|
+ } catch (IOException e) {
|
|
|
+ fos.close();
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
break;
|
|
|
case SNAPPY:
|
|
|
+ // Unlike SnappyInputStream, the SnappyOutputStream
|
|
|
+ // constructor cannot throw an IOException.
|
|
|
os = new SnappyOutputStream(fos);
|
|
|
break;
|
|
|
case CHECKED:
|