mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-05 07:45:11 +01:00
Reextract content file until it's has the expected length. Maximum tries: 3
This commit is contained in:
parent
7425e6e904
commit
78b51226aa
@ -109,26 +109,48 @@ public abstract class NUSDataProvider {
|
||||
* Content that should be saved
|
||||
* @param outputFolder
|
||||
* Target directory where the files will be stored in.
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public void saveEncryptedContent(@NonNull Content content, @NonNull String outputFolder) throws IOException {
|
||||
Utils.createDir(outputFolder);
|
||||
InputStream inputStream = getInputStreamFromContent(content, 0);
|
||||
if (inputStream == null) {
|
||||
log.info("Couldn't save encrypted content. Input stream was null");
|
||||
return;
|
||||
}
|
||||
int maxTries = 3;
|
||||
int i = 0;
|
||||
while (i < maxTries) {
|
||||
File output = new File(outputFolder + File.separator + content.getFilename());
|
||||
if (output.exists()) {
|
||||
if (output.length() == content.getEncryptedFileSizeAligned()) {
|
||||
log.info(content.getFilename() + "Encrypted content alreadys exists, skipped");
|
||||
return;
|
||||
} else {
|
||||
log.warning(content.getFilename() + " Encrypted content alreadys exists, but the length is not as expected. Saving it again. "
|
||||
+ output.length() + " " + content.getEncryptedFileSizeAligned() + " Difference: "
|
||||
+ (output.length() - content.getEncryptedFileSizeAligned()));
|
||||
}
|
||||
}
|
||||
|
||||
File output = new File(outputFolder + File.separator + content.getFilename());
|
||||
if (output.exists()) {
|
||||
if (output.length() == content.getEncryptedFileSizeAligned()) {
|
||||
log.info("Encrypted content alreadys exists, skipped");
|
||||
Utils.createDir(outputFolder);
|
||||
InputStream inputStream = getInputStreamFromContent(content, 0);
|
||||
if (inputStream == null) {
|
||||
log.info(content.getFilename() + " Couldn't save encrypted content. Input stream was null");
|
||||
return;
|
||||
} else {
|
||||
log.info("Encrypted content alreadys exists, but the length is not as expected. Saving it again");
|
||||
}
|
||||
log.warning("loading " + content.getFilename());
|
||||
FileUtils.saveInputStreamToFile(output, inputStream, content.getEncryptedFileSizeAligned());
|
||||
|
||||
File outputNow = new File(outputFolder + File.separator + content.getFilename());
|
||||
if (outputNow.exists()) {
|
||||
if (outputNow.length() != content.getEncryptedFileSizeAligned()) {
|
||||
log.warning(content.getFilename() + " Encrypted content length is not as expected. Saving it again. Loaded: " + outputNow.length()
|
||||
+ " Expected: " + content.getEncryptedFileSizeAligned() + " Difference: "
|
||||
+ (outputNow.length() - content.getEncryptedFileSizeAligned()));
|
||||
i++;
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
FileUtils.saveInputStreamToFile(output, inputStream, content.getEncryptedFileSizeAligned());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user