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;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int UPDATE_EVERY_BYTES = 16000;
|
private static final int BUFFER_SIZE = 16384;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -161,18 +161,14 @@ public class StitchJob extends Job {
|
||||||
InputStream inputStream = ICleaverInputStream.fromElement(cleaverNode, chpFolder, cryptKey);
|
InputStream inputStream = ICleaverInputStream.fromElement(cleaverNode, chpFolder, cryptKey);
|
||||||
OutputStream outputStream = new FileOutputStream(resultFile);
|
OutputStream outputStream = new FileOutputStream(resultFile);
|
||||||
|
|
||||||
//Pipe everything to the output
|
//Pipe everything to the output, in chunks
|
||||||
int bytesUntilNextUpdate = UPDATE_EVERY_BYTES;
|
|
||||||
this.setProgress(new WorkingProgress());
|
this.setProgress(new WorkingProgress());
|
||||||
|
|
||||||
int i;
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
while((i = inputStream.read()) != -1) {
|
//Loop until the first byte in the buffer is -1
|
||||||
outputStream.write(i);
|
while(inputStream.read(buffer) != -1) {
|
||||||
bytesUntilNextUpdate -= 1;
|
outputStream.write(buffer);
|
||||||
if(bytesUntilNextUpdate <= 0) {
|
this.setProgress(new WorkingProgress((float)(resultFile.length() - inputStream.available()) / (float)resultFile.length()));
|
||||||
this.setProgress(new WorkingProgress((float)(resultFile.length() - inputStream.available()) / (float)resultFile.length()));
|
|
||||||
bytesUntilNextUpdate = UPDATE_EVERY_BYTES;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
|
Loading…
Reference in a new issue