@Test public void closeSourceAfterWrite() throws IOException { when(source.read(any(Buffer.class), anyByte())).thenReturn(Long.valueOf(-1)); fsFile.write(source); verify(source).close(); }
public void write(@Nonnull BufferedSource source) throws IOException { File tmpFile = File.createTempFile("new", "tmp", file.getParentFile()); BufferedSink sink = null; try { sink = Okio.buffer(Okio.sink(tmpFile)); sink.writeAll(source); if (!tmpFile.renameTo(file)) { throw new IOException("unable to move tmp file to " + file.getPath()); } } catch (Exception e) { throw new IOException("unable to write to file", e); } finally { tmpFile.delete(); if (sink != null) { sink.close(); } source.close(); } }
FSFile { public void write(@Nonnull BufferedSource source) throws IOException { File tmpFile = File.createTempFile("new", "tmp", file.getParentFile()); BufferedSink sink = null; try { sink = Okio.buffer(Okio.sink(tmpFile)); sink.writeAll(source); if (!tmpFile.renameTo(file)) { throw new IOException("unable to move tmp file to " + file.getPath()); } } catch (Exception e) { throw new IOException("unable to write to file", e); } finally { tmpFile.delete(); if (sink != null) { sink.close(); } source.close(); } } }
FSFile { public void write(@Nonnull BufferedSource source) throws IOException { File tmpFile = File.createTempFile("new", "tmp", file.getParentFile()); BufferedSink sink = null; try { sink = Okio.buffer(Okio.sink(tmpFile)); sink.writeAll(source); if (!tmpFile.renameTo(file)) { throw new IOException("unable to move tmp file to " + file.getPath()); } } catch (Exception e) { throw new IOException("unable to write to file", e); } finally { tmpFile.delete(); if (sink != null) { sink.close(); } source.close(); } } FSFile(File root, @Nonnull String path); }
FSFile { public void write(@Nonnull BufferedSource source) throws IOException { File tmpFile = File.createTempFile("new", "tmp", file.getParentFile()); BufferedSink sink = null; try { sink = Okio.buffer(Okio.sink(tmpFile)); sink.writeAll(source); if (!tmpFile.renameTo(file)) { throw new IOException("unable to move tmp file to " + file.getPath()); } } catch (Exception e) { throw new IOException("unable to write to file", e); } finally { tmpFile.delete(); if (sink != null) { sink.close(); } source.close(); } } FSFile(File root, @Nonnull String path); boolean exists(); void delete(); @Nonnull String path(); void write(@Nonnull BufferedSource source); @Nonnull BufferedSource source(); long lastModified(); }
FSFile { public void write(@Nonnull BufferedSource source) throws IOException { File tmpFile = File.createTempFile("new", "tmp", file.getParentFile()); BufferedSink sink = null; try { sink = Okio.buffer(Okio.sink(tmpFile)); sink.writeAll(source); if (!tmpFile.renameTo(file)) { throw new IOException("unable to move tmp file to " + file.getPath()); } } catch (Exception e) { throw new IOException("unable to write to file", e); } finally { tmpFile.delete(); if (sink != null) { sink.close(); } source.close(); } } FSFile(File root, @Nonnull String path); boolean exists(); void delete(); @Nonnull String path(); void write(@Nonnull BufferedSource source); @Nonnull BufferedSource source(); long lastModified();  }