HDFS-12881. Output streams closed with IOUtils suppressing write errors. Contributed by Ajay Kumar

This commit is contained in:
Jason Lowe 2017-12-15 14:47:54 -06:00
parent 1fee447bf2
commit 9ae8d1a8de
3 changed files with 13 additions and 5 deletions

View File

@ -1116,8 +1116,10 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
// calculate and write the last crc // calculate and write the last crc
checksum.calculateChunkedSums(data, 0, offset, crcs, 0); checksum.calculateChunkedSums(data, 0, offset, crcs, 0);
metaOut.write(crcs, 0, 4); metaOut.write(crcs, 0, 4);
metaOut.close();
metaOut = null;
} finally { } finally {
IOUtils.cleanupWithLogger(LOG, metaOut); IOUtils.closeStream(metaOut);
} }
} }

View File

@ -108,6 +108,8 @@ public abstract class FSImageTestUtil {
try { try {
raf.seek(IMAGE_TXID_POS); raf.seek(IMAGE_TXID_POS);
raf.writeLong(0); raf.writeLong(0);
raf.close();
raf = null;
} finally { } finally {
IOUtils.closeStream(raf); IOUtils.closeStream(raf);
} }
@ -542,9 +544,11 @@ public abstract class FSImageTestUtil {
out = new FileOutputStream(versionFile); out = new FileOutputStream(versionFile);
props.store(out, null); props.store(out, null);
out.close();
out = null;
} finally { } finally {
IOUtils.cleanup(null, fis, out); IOUtils.closeStream(fis);
IOUtils.closeStream(out);
} }
} }

View File

@ -271,9 +271,11 @@ public class TestOfflineImageViewer {
in = new FileInputStream(src); in = new FileInputStream(src);
out = new FileOutputStream(dest); out = new FileOutputStream(dest);
in.getChannel().transferTo(0, MAX_BYTES, out.getChannel()); in.getChannel().transferTo(0, MAX_BYTES, out.getChannel());
out.close();
out = null;
} finally { } finally {
IOUtils.cleanup(null, in); IOUtils.closeStream(in);
IOUtils.cleanup(null, out); IOUtils.closeStream(out);
} }
} }