mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-23 00:19:18 +01:00
Optimize the NUSDataProviderWUDGI implementation
This commit is contained in:
parent
a0ce93dc38
commit
57611173b4
@ -45,11 +45,15 @@ public class NUSDataProviderWUDGI extends NUSDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStreamFromContent(Content content, long fileOffsetBlock) throws IOException {
|
public InputStream getInputStreamFromContent(Content content, long fileOffsetBlock) throws IOException {
|
||||||
InputStream in = getGiPartitionTitle().getFileAsStream(content.getFilename(), getDiscReader(), titleKey);
|
InputStream in = getGiPartitionTitle().getFileAsStream(content.getFilename(), getDiscReader(), fileOffsetBlock, titleKey);
|
||||||
in.skip(fileOffsetBlock);
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getChunkFromContent(Content content, long offset, int size) throws IOException {
|
||||||
|
return getGiPartitionTitle().getFileAsByte(content.getFilename(), getDiscReader(), offset, size, titleKey);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getContentH3Hash(Content content) throws IOException {
|
public byte[] getContentH3Hash(Content content) throws IOException {
|
||||||
return getGiPartitionTitle().getFileAsByte(String.format("%08X.h3", content.getID()), getDiscReader(), titleKey);
|
return getGiPartitionTitle().getFileAsByte(String.format("%08X.h3", content.getID()), getDiscReader(), titleKey);
|
||||||
|
@ -25,15 +25,29 @@ public class WUDGIPartitionTitle {
|
|||||||
|
|
||||||
public byte[] getFileAsByte(String filename, WUDDiscReader discReader, byte[] titleKey) throws IOException {
|
public byte[] getFileAsByte(String filename, WUDDiscReader discReader, byte[] titleKey) throws IOException {
|
||||||
FSTEntry entry = getEntryByFilename(rootEntry, filename);
|
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);
|
FSTEntry entry = getEntryByFilename(rootEntry, filename);
|
||||||
ContentFSTInfo info = fst.getContentFSTInfos().get((int) entry.getContentFSTID());
|
ContentFSTInfo info = fst.getContentFSTInfos().get((int) entry.getContentFSTID());
|
||||||
|
|
||||||
return discReader.readDecryptedToInputStream(getAbsoluteReadOffset() + (long) info.getOffset(), entry.getFileOffset(), (int) entry.getFileSize(),
|
return getFileAsStream(info.getOffset(), entry.getFileOffset() + offsetInFile, (int) entry.getFileSize(), discReader, titleKey);
|
||||||
titleKey, null, false);
|
}
|
||||||
|
|
||||||
|
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() {
|
private long getAbsoluteReadOffset() {
|
||||||
|
Loading…
Reference in New Issue
Block a user