Optimize the NUSDataProviderWUDGI implementation

This commit is contained in:
Maschell 2019-04-06 16:57:12 +02:00
parent a0ce93dc38
commit 57611173b4
2 changed files with 24 additions and 6 deletions

View File

@ -45,11 +45,15 @@ public class NUSDataProviderWUDGI extends NUSDataProvider {
@Override
public InputStream getInputStreamFromContent(Content content, long fileOffsetBlock) throws IOException {
InputStream in = getGiPartitionTitle().getFileAsStream(content.getFilename(), getDiscReader(), titleKey);
in.skip(fileOffsetBlock);
InputStream in = getGiPartitionTitle().getFileAsStream(content.getFilename(), getDiscReader(), fileOffsetBlock, titleKey);
return in;
}
@Override
public byte[] getChunkFromContent(Content content, long offset, int size) throws IOException {
return getGiPartitionTitle().getFileAsByte(content.getFilename(), getDiscReader(), offset, size, titleKey);
}
@Override
public byte[] getContentH3Hash(Content content) throws IOException {
return getGiPartitionTitle().getFileAsByte(String.format("%08X.h3", content.getID()), getDiscReader(), titleKey);

View File

@ -25,15 +25,29 @@ public class WUDGIPartitionTitle {
public byte[] getFileAsByte(String filename, WUDDiscReader discReader, byte[] titleKey) throws IOException {
FSTEntry entry = getEntryByFilename(rootEntry, filename);
return StreamUtils.getBytesFromStream(getFileAsStream(filename, discReader, titleKey), (int) entry.getFileSize());
return StreamUtils.getBytesFromStream(getFileAsStream(filename, discReader, 0, titleKey), (int) entry.getFileSize());
}
public InputStream getFileAsStream(String filename, WUDDiscReader discReader, byte[] titleKey) throws IOException {
public InputStream getFileAsStream(String filename, WUDDiscReader discReader, long offsetInFile, byte[] titleKey) throws IOException {
FSTEntry entry = getEntryByFilename(rootEntry, filename);
ContentFSTInfo info = fst.getContentFSTInfos().get((int) entry.getContentFSTID());
return discReader.readDecryptedToInputStream(getAbsoluteReadOffset() + (long) info.getOffset(), entry.getFileOffset(), (int) entry.getFileSize(),
titleKey, null, false);
return getFileAsStream(info.getOffset(), entry.getFileOffset() + offsetInFile, (int) entry.getFileSize(), discReader, titleKey);
}
public InputStream getFileAsStream(long contentOffset, long fileoffset, long size, WUDDiscReader discReader, byte[] titleKey) throws IOException {
return discReader.readDecryptedToInputStream(getAbsoluteReadOffset() + contentOffset, fileoffset, (int) size, titleKey, null, false);
}
public byte[] getFileAsData(long contentOffset, long fileoffset, long size, WUDDiscReader discReader, byte[] titleKey) throws IOException {
return discReader.readDecryptedToByteArray(getAbsoluteReadOffset() + contentOffset, fileoffset, (int) size, titleKey, null, false);
}
public byte[] getFileAsByte(String filename, WUDDiscReader discReader, long offsetInFile, int size, byte[] titleKey) throws IOException {
FSTEntry entry = getEntryByFilename(rootEntry, filename);
ContentFSTInfo info = fst.getContentFSTInfos().get((int) entry.getContentFSTID());
return getFileAsData(info.getOffset(), entry.getFileOffset() + offsetInFile, size, discReader, titleKey);
}
private long getAbsoluteReadOffset() {