Add a readFileToStream function to the FSTDataProvider interface while allows your to read a file to a outputstream

This commit is contained in:
Maschell 2019-04-11 13:14:50 +02:00
parent 53993dc8c4
commit 89d5927acd
7 changed files with 27 additions and 4 deletions

View File

@ -91,6 +91,15 @@ public class FSTDataProviderNUSTitle implements FSTDataProvider, HasNUSTitle {
return in;
}
@Override
public void readFileToStream(OutputStream outputStream, FSTEntry entry) throws IOException {
try {
readFileToOutputStream(outputStream, entry, 0, entry.getFileSize());
} catch (CheckSumWrongException e) {
throw new IOException(e);
}
}
public boolean readFileToOutputStream(OutputStream out, FSTEntry entry, long offset, long size) throws IOException, CheckSumWrongException {
long fileOffset = entry.getFileOffset() + offset;
long fileOffsetBlock = fileOffset;

View File

@ -18,6 +18,7 @@ package de.mas.wiiu.jnus.implementations;
****************************************************************************/
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import de.mas.wiiu.jnus.entities.content.ContentFSTInfo;
@ -53,6 +54,16 @@ public class FSTDataProviderWUDDataPartition implements FSTDataProvider {
return getChunkOfData(info.getOffset(), entry.getFileOffset() + offset, size, discReader, titleKey);
}
@Override
public void readFileToStream(OutputStream out, FSTEntry entry) throws IOException {
ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID());
if (titleKey == null) {
discReader.readEncryptedToOutputStream(out, partition.getAbsolutePartitionOffset() + info.getOffset() + entry.getFileOffset(), entry.getFileSize());
}
discReader.readDecryptedToOutputStream(out, partition.getAbsolutePartitionOffset() + info.getOffset(), entry.getFileOffset(), entry.getFileSize(),
titleKey, null, false);
}
@Override
public InputStream readFileAsStream(FSTEntry entry, long offset, Optional<Long> size) throws IOException {
ContentFSTInfo info = partition.getFST().getContentFSTInfos().get((int) entry.getContentFSTID());

View File

@ -83,7 +83,7 @@ public abstract class WUDDiscReader {
return out.toByteArray();
}
protected abstract void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException;
public abstract void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException;
/**
*

View File

@ -36,7 +36,7 @@ public class WUDDiscReaderCompressed extends WUDDiscReader {
* Expects the .wux format by Exzap. You can more infos about it here. https://gbatemp.net/threads/wii-u-image-wud-compression-tool.397901/
*/
@Override
protected void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException {
public void readEncryptedToOutputStream(OutputStream out, long offset, long size) throws IOException {
// make sure there is no out-of-bounds read
WUDImageCompressedInfo info = getImage().getCompressedInfo();

View File

@ -37,7 +37,7 @@ public class WUDDiscReaderSplitted extends WUDDiscReader {
}
@Override
protected void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException {
public void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException {
RandomAccessFile input = getFileByOffset(offset);
int bufferSize = 0x8000;

View File

@ -30,7 +30,7 @@ public class WUDDiscReaderUncompressed extends WUDDiscReader {
}
@Override
protected void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException {
public void readEncryptedToOutputStream(OutputStream outputStream, long offset, long size) throws IOException {
FileInputStream input = new FileInputStream(getImage().getFileHandle());

View File

@ -18,6 +18,7 @@ package de.mas.wiiu.jnus.interfaces;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import de.mas.wiiu.jnus.entities.fst.FSTEntry;
@ -35,4 +36,6 @@ public interface FSTDataProvider {
public InputStream readFileAsStream(FSTEntry entry, long offset, Optional<Long> size) throws IOException;
public void readFileToStream(OutputStream out, FSTEntry entry) throws IOException;
}