From 606b1b3b2f468914326e502bc976b92bedc991bf Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 9 Jan 2020 00:35:50 +0100 Subject: [PATCH] Incomplete: use buffered reads and writes --- .../eu/steffo/cleaver/errors/ChpFileError.html | 4 ++-- .../cleaver/errors/ProgrammingError.html | 10 +++++----- .../steffo/cleaver/errors/package-summary.html | 4 ++-- .../eu/steffo/cleaver/errors/package-tree.html | 4 ++-- src/eu/steffo/cleaver/logic/job/StitchJob.java | 18 +++++++----------- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ChpFileError.html b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ChpFileError.html index a0a50bd..94fbc41 100644 --- a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ChpFileError.html +++ b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ChpFileError.html @@ -2,10 +2,10 @@ - + ChpFileError - + diff --git a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ProgrammingError.html b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ProgrammingError.html index 587eb5a..020ef03 100644 --- a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ProgrammingError.html +++ b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ProgrammingError.html @@ -2,10 +2,10 @@ - + ProgrammingError - + @@ -129,7 +129,7 @@ extends -ProgrammingError() +ProgrammingError​(String s)   @@ -168,8 +168,8 @@ extends
  • -

    ProgrammingError

    -
    public ProgrammingError()
    +

    ProgrammingError

    +
    public ProgrammingError​(String s)
  • diff --git a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-summary.html b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-summary.html index c0251f9..67d4d8b 100644 --- a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-summary.html +++ b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-summary.html @@ -2,10 +2,10 @@ - + eu.steffo.cleaver.errors - + diff --git a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-tree.html b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-tree.html index 8f503f1..29840d9 100644 --- a/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-tree.html +++ b/docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-tree.html @@ -2,10 +2,10 @@ - + eu.steffo.cleaver.errors Class Hierarchy - + diff --git a/src/eu/steffo/cleaver/logic/job/StitchJob.java b/src/eu/steffo/cleaver/logic/job/StitchJob.java index f38c6d6..a9dfc15 100644 --- a/src/eu/steffo/cleaver/logic/job/StitchJob.java +++ b/src/eu/steffo/cleaver/logic/job/StitchJob.java @@ -149,7 +149,7 @@ public class StitchJob extends Job { return doc; } - private static final int UPDATE_EVERY_BYTES = 16000; + private static final int BUFFER_SIZE = 16384; @Override public void run() { @@ -161,18 +161,14 @@ public class StitchJob extends Job { InputStream inputStream = ICleaverInputStream.fromElement(cleaverNode, chpFolder, cryptKey); OutputStream outputStream = new FileOutputStream(resultFile); - //Pipe everything to the output - int bytesUntilNextUpdate = UPDATE_EVERY_BYTES; + //Pipe everything to the output, in chunks this.setProgress(new WorkingProgress()); - int i; - while((i = inputStream.read()) != -1) { - outputStream.write(i); - bytesUntilNextUpdate -= 1; - if(bytesUntilNextUpdate <= 0) { - this.setProgress(new WorkingProgress((float)(resultFile.length() - inputStream.available()) / (float)resultFile.length())); - bytesUntilNextUpdate = UPDATE_EVERY_BYTES; - } + byte[] buffer = new byte[BUFFER_SIZE]; + //Loop until the first byte in the buffer is -1 + while(inputStream.read(buffer) != -1) { + outputStream.write(buffer); + this.setProgress(new WorkingProgress((float)(resultFile.length() - inputStream.available()) / (float)resultFile.length())); } inputStream.close();