mirror of
https://github.com/Maschell/JNUSLib.git
synced 2025-02-19 17:52:43 +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
|
* Content that should be saved
|
||||||
* @param outputFolder
|
* @param outputFolder
|
||||||
* Target directory where the files will be stored in.
|
* Target directory where the files will be stored in.
|
||||||
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void saveEncryptedContent(@NonNull Content content, @NonNull String outputFolder) throws IOException {
|
public void saveEncryptedContent(@NonNull Content content, @NonNull String outputFolder) throws IOException {
|
||||||
Utils.createDir(outputFolder);
|
int maxTries = 3;
|
||||||
InputStream inputStream = getInputStreamFromContent(content, 0);
|
int i = 0;
|
||||||
if (inputStream == null) {
|
while (i < maxTries) {
|
||||||
log.info("Couldn't save encrypted content. Input stream was null");
|
File output = new File(outputFolder + File.separator + content.getFilename());
|
||||||
return;
|
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());
|
Utils.createDir(outputFolder);
|
||||||
if (output.exists()) {
|
InputStream inputStream = getInputStreamFromContent(content, 0);
|
||||||
if (output.length() == content.getEncryptedFileSizeAligned()) {
|
if (inputStream == null) {
|
||||||
log.info("Encrypted content alreadys exists, skipped");
|
log.info(content.getFilename() + " Couldn't save encrypted content. Input stream was null");
|
||||||
return;
|
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…
x
Reference in New Issue
Block a user