I am trying to generate an ISO file with JIIC library:
https://github.com/stephenc/java-iso-tools
The thing is that I need to know the exact amount of the generated (to be) iso file after adding a file. (I need to have a restriction on the generated iso file size and if exceeds, to generate a new iso file).
I am trying:
long currentIsoSize;
var numOfCreatedIsos = 1;
var root = new ISO9660RootDirectory();
for (var i = 0; i<listFilesInPdfDir.length; i++) {
if (listFilesInPdfDir[i].isDirectory()) {
currentIsoSize = generateIso(event, numOfCreatedIsos, root, listFilesInPdfDir[i]);
if (maxIsoFileSizeExceeds(currentIsoSize)) {
root.getDirectories().remove(root.getDirectories().get(root.getDirectories().size()-1));
generateIso(event, numOfCreatedIsos, root, null);
root = new ISO9660RootDirectory();
numOfCreatedIsos++;
i--;
}
} else {
log.warn("File: {} skipped", listFilesInPdfDir[i]);
}
}
private long generateIso(ArchiveEventTrigger event, int numOfCreatedIsos, ISO9660RootDirectory root, File file) throws HandlerException, FileNotFoundException {
if (file != null) {
var directory = root.addDirectory(file);
for (var pdf : Objects.requireNonNull(file.listFiles())) {
directory.addFile(pdf);
}
}
var isoName = ArchiveUtils.buildIsoName(event, numOfCreatedIsos);
var isoFile = new File("DIR_TO_ISO"+isoName);
var handler = new ISOImageFileHandler(isoFile);
var iso = new CreateISO(handler, root);
iso.process(Utils.isoConfig("daily-isos-"+numOfCreatedIsos), null, null, null);
return new File("DIR_TO_ISO"+isoName).length();
}
The thing is that it creates the appropriate ISO but:
- The file size is not the expected one (files: 70MB - iso: 60MB(about the size of the first directory inserted to iso)
- Only the first directory has valid files, the other directories have the files but are corrupted.
I noticed that it is happening because of the iso.process call for the same iso file.
Any suggestions?