Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a550449 authored by Vinit Deshpande's avatar Vinit Deshpande Committed by Android Partner Code Review
Browse files

Merge "Added parameter to avoid having a stream opened, and with that, file...

Merge "Added parameter to avoid having a stream opened, and with that, file truncated on no-op." into m-wireless-dev
parents e20b8ad4 58687715
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -38,6 +38,10 @@ public class DelayedDiskWrite {
    }

    public void write(final String filePath, final Writer w) {
        write(filePath, w, true);
    }

    public void write(final String filePath, final Writer w, final boolean open) {
        if (TextUtils.isEmpty(filePath)) {
            throw new IllegalArgumentException("empty file path");
        }
@@ -54,16 +58,18 @@ public class DelayedDiskWrite {
        mDiskWriteHandler.post(new Runnable() {
            @Override
            public void run() {
                doWrite(filePath, w);
                doWrite(filePath, w, open);
            }
        });
    }

    private void doWrite(String filePath, Writer w) {
    private void doWrite(String filePath, Writer w, boolean open) {
        DataOutputStream out = null;
        try {
            if (open) {
                out = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(filePath)));
            }
            w.onWriteCalled(out);
        } catch (IOException e) {
            loge("Error writing data file " + filePath);