always call sink.close() from finally block (#63)

This commit is contained in:
Brian Plummer 2017-01-15 19:23:24 -05:00 committed by Mike Nakhimovich
parent 47aa5da3bf
commit a31deb7f0c

View file

@ -53,11 +53,11 @@ class FSFile {
public void write(BufferedSource source) throws IOException {
File tmpFile = File.createTempFile("new", "tmp", file.getParentFile());
BufferedSink sink = null;
try {
BufferedSink sink = Okio.buffer(Okio.sink(tmpFile));
sink = Okio.buffer(Okio.sink(tmpFile));
sink.writeAll(source);
sink.close();
if (!tmpFile.renameTo(file)) {
throw new IOException("unable to move tmp file to " + file.getPath());
@ -67,6 +67,9 @@ class FSFile {
} finally {
tmpFile.delete();
if (sink != null) {
sink.close();
}
}
}