mirror of
https://github.com/Steffo99/unimore-oop-2020-cleaver.git
synced 2024-11-25 09:34:20 +00:00
Merge branch 'buffered'
# Conflicts: # docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ChpFileError.html # docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/ProgrammingError.html # docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-summary.html # docs/eu.steffo.cleaver/eu/steffo/cleaver/errors/package-tree.html
This commit is contained in:
commit
a2ee697d2a
1 changed files with 7 additions and 11 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue