@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Test public void appendFile() throws Exception { File file = temporaryFolder.newFile(); BufferedSink sink = Okio.buffer(Okio.appendingSink(file)); sink.writeUtf8("Hello, "); sink.close(); assertTrue(file.exists()); assertEquals(7, file.length()); sink = Okio.buffer(Okio.appendingSink(file)); sink.writeUtf8("java.io file!"); sink.close(); assertEquals(20, file.length()); BufferedSource source = Okio.buffer(Okio.source(file)); assertEquals("Hello, java.io file!", source.readUtf8()); source.close(); }
@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Override public Sink appendingSink(File file) throws FileNotFoundException { try { return Okio.appendingSink(file); } catch (FileNotFoundException e) { // Maybe the parent directory doesn't exist? Try creating it first. file.getParentFile().mkdirs(); return Okio.appendingSink(file); } }
@Override public void run() { try { BufferedSource bufferedSource = Okio.buffer(Okio.source(sourceFile)); bufferedSource.skip(mDownloadInfo.getDownloadedLength()); BufferedSink bufferedSink = Okio.buffer(Okio.appendingSink(file)); writeData(bufferedSource, bufferedSink); } catch (Exception e) { FirebaseCrash.report(e); e.printStackTrace(); } } }).start();
@Override public void onResponse(Call call, Response response) { try { if (response.isSuccessful()) { BufferedSource bufferedSource = response.body().source(); if (!started()) { mDownloadInfo.setContentLength(response.body().contentLength()); } BufferedSink bufferedSink = Okio.buffer(Okio.appendingSink(file));; writeData(bufferedSource, bufferedSink); } else { stopDownload(); String message = "Download Failed! Response Code : " + response.code(); Log.v(TAG, message); Global.showToastFromNonUiThread(mContext, message, Toast.LENGTH_SHORT); } } catch (IOException e) { Log.e("DownloadService", "Exception : ", e); stopDownload(); } } });