always call sink.close() from finally block (#63)
This commit is contained in:
parent
47aa5da3bf
commit
a31deb7f0c
1 changed files with 5 additions and 2 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue