1
Fork 0
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:
Steffo 2020-01-09 17:04:49 +01:00
commit a2ee697d2a

View file

@ -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) {
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()));
bytesUntilNextUpdate = UPDATE_EVERY_BYTES;
}
}
inputStream.close();