Return false instead of throwing an exception while trying to extract missing files

This commit is contained in:
Maschell 2019-04-16 12:59:34 +02:00
parent a521b045ab
commit 73440af121

View File

@ -117,23 +117,30 @@ public final class ExtractionService {
} }
} }
public void extractTMDTo(String output) throws IOException { public boolean extractTMDTo(String output) throws IOException {
Utils.createDir(output); Utils.createDir(output);
byte[] rawTMD = getDataProvider().getRawTMD().orElseThrow(() -> new FileNotFoundException("TMD not found")); Optional<byte[]> rawTMD = getDataProvider().getRawTMD();
if (!rawTMD.isPresent()) {
return false;
}
String tmd_path = output + File.separator + Settings.TMD_FILENAME; String tmd_path = output + File.separator + Settings.TMD_FILENAME;
log.info("Extracting TMD to: " + tmd_path); log.info("Extracting TMD to: " + tmd_path);
FileUtils.saveByteArrayToFile(tmd_path, rawTMD); return FileUtils.saveByteArrayToFile(tmd_path, rawTMD.get());
} }
public boolean extractTicketTo(String output) throws IOException { public boolean extractTicketTo(String output) throws IOException {
Utils.createDir(output); Utils.createDir(output);
byte[] rawTicket = getDataProvider().getRawTicket().orElseThrow(() -> new FileNotFoundException("Ticket not found")); Optional<byte[]> rawTicket = getDataProvider().getRawTicket();
if (!rawTicket.isPresent()) {
return false;
}
String ticket_path = output + File.separator + Settings.TICKET_FILENAME; String ticket_path = output + File.separator + Settings.TICKET_FILENAME;
log.info("Extracting Ticket to: " + ticket_path); log.info("Extracting Ticket to: " + ticket_path);
return FileUtils.saveByteArrayToFile(ticket_path, rawTicket); return FileUtils.saveByteArrayToFile(ticket_path, rawTicket.get());
} }
public boolean extractCertTo(String output) throws IOException { public boolean extractCertTo(String output) throws IOException {
@ -160,5 +167,4 @@ public final class ExtractionService {
} }
} }