From 157957f3eefb2b7f8d506e930c7fc24ac0c9cbef Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 26 Apr 2019 09:57:05 +0200 Subject: [PATCH] Add default implementiation for the readFile function of the FSTDataProvider interface --- src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java b/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java index 5c10135..6278d2b 100644 --- a/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java +++ b/src/de/mas/wiiu/jnus/interfaces/FSTDataProvider.java @@ -16,6 +16,7 @@ ****************************************************************************/ package de.mas.wiiu.jnus.interfaces; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -30,11 +31,17 @@ public interface FSTDataProvider { public FSTEntry getRoot(); - public default byte[] readFile(FSTEntry entry) throws IOException { + default public byte[] readFile(FSTEntry entry) throws IOException { return readFile(entry, 0, entry.getFileSize()); } - public byte[] readFile(FSTEntry entry, long offset, long size) throws IOException; + default public byte[] readFile(FSTEntry entry, long offset, long size) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + readFileToStream(out, entry, offset, Optional.of(size)); + + return out.toByteArray(); + } default public InputStream readFileAsStream(FSTEntry entry) throws IOException { return readFileAsStream(entry, 0, Optional.empty());