mirror of
https://github.com/Steffo99/unimore-oop-2020-cleaver.git
synced 2024-11-22 08:04:19 +00:00
Fix a few bugs with the progress %
This commit is contained in:
parent
d79f83f376
commit
1d99b6513a
1 changed files with 7 additions and 7 deletions
|
@ -53,12 +53,12 @@ public class ChopJob extends Job {
|
||||||
partSize = ((SplitBySizeConfig)splitConfig).getSize();
|
partSize = ((SplitBySizeConfig)splitConfig).getSize();
|
||||||
}
|
}
|
||||||
else if(splitConfig instanceof SplitByPartsConfig) {
|
else if(splitConfig instanceof SplitByPartsConfig) {
|
||||||
partSize = ((SplitByPartsConfig)splitConfig).getParts();
|
partSize = file.length() / ((SplitByPartsConfig)splitConfig).getParts();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
partSize = file.length();
|
partSize = file.length();
|
||||||
}
|
}
|
||||||
OutputStream outputStream = new SplitFileOutputStream(file.getName(), partSize);
|
OutputStream outputStream = new SplitFileOutputStream(file.getAbsolutePath(), partSize);
|
||||||
|
|
||||||
if(compressConfig != null) {
|
if(compressConfig != null) {
|
||||||
outputStream = new DeflaterOutputStream(outputStream);
|
outputStream = new DeflaterOutputStream(outputStream);
|
||||||
|
@ -70,7 +70,7 @@ public class ChopJob extends Job {
|
||||||
|
|
||||||
//Create the .chp file
|
//Create the .chp file
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder;
|
||||||
try {
|
try {
|
||||||
builder = factory.newDocumentBuilder();
|
builder = factory.newDocumentBuilder();
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
|
@ -93,11 +93,11 @@ public class ChopJob extends Job {
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
DOMSource source = new DOMSource(doc);
|
DOMSource source = new DOMSource(doc);
|
||||||
StreamResult result = new StreamResult(String.format("%s.chp", file.getName()));
|
StreamResult result = new StreamResult(String.format("%s.chp", file.getAbsolutePath()));
|
||||||
transformer.transform(source, result);
|
transformer.transform(source, result);
|
||||||
|
|
||||||
//Actually run the job
|
//Actually run the job
|
||||||
int bytesUntilNextUpdate = 1024;
|
int bytesUntilNextUpdate = 2048;
|
||||||
this.setProgress(new WorkingProgress());
|
this.setProgress(new WorkingProgress());
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
@ -105,8 +105,8 @@ public class ChopJob extends Job {
|
||||||
outputStream.write(i);
|
outputStream.write(i);
|
||||||
bytesUntilNextUpdate -= 1;
|
bytesUntilNextUpdate -= 1;
|
||||||
if(bytesUntilNextUpdate <= 0) {
|
if(bytesUntilNextUpdate <= 0) {
|
||||||
this.setProgress(new WorkingProgress((float)file.length() / (float)partSize));
|
this.setProgress(new WorkingProgress((float)(file.length() - inputStream.available()) / (float)file.length()));
|
||||||
bytesUntilNextUpdate = 1024;
|
bytesUntilNextUpdate = 2048;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue