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

Commit 58687715 authored by Jan Nordqvist's avatar Jan Nordqvist
Browse files

Added parameter to avoid having a stream opened,

and with that, file truncated on no-op.

Change-Id: I5813e4fd269c639a437e17f2554efa4db735a8ba
parent 052a0da4
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);