mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-26 18:04:17 +01:00
Add a synchronized block to the WUD disc reading.
This commit is contained in:
parent
78b51226aa
commit
a16c1943c0
@ -58,31 +58,33 @@ public class WUDDiscReaderCompressed extends WUDDiscReader {
|
|||||||
byte[] buffer = new byte[bufferSize];
|
byte[] buffer = new byte[bufferSize];
|
||||||
|
|
||||||
RandomAccessFile input = getRandomAccessFileStream();
|
RandomAccessFile input = getRandomAccessFileStream();
|
||||||
while (usedSize > 0) {
|
synchronized (input) {
|
||||||
long sectorOffset = (usedOffset % info.getSectorSize());
|
while (usedSize > 0) {
|
||||||
long remainingSectorBytes = info.getSectorSize() - sectorOffset;
|
long sectorOffset = (usedOffset % info.getSectorSize());
|
||||||
long sectorIndex = (usedOffset / info.getSectorSize());
|
long remainingSectorBytes = info.getSectorSize() - sectorOffset;
|
||||||
int bytesToRead = (int) ((remainingSectorBytes < usedSize) ? remainingSectorBytes : usedSize); // read only up to the end of the current sector
|
long sectorIndex = (usedOffset / info.getSectorSize());
|
||||||
// look up real sector index
|
int bytesToRead = (int) ((remainingSectorBytes < usedSize) ? remainingSectorBytes : usedSize); // read only up to the end of the current sector
|
||||||
long realSectorIndex = info.getSectorIndex((int) sectorIndex);
|
// look up real sector index
|
||||||
long offset2 = info.getOffsetSectorArray() + realSectorIndex * info.getSectorSize() + sectorOffset;
|
long realSectorIndex = info.getSectorIndex((int) sectorIndex);
|
||||||
|
long offset2 = info.getOffsetSectorArray() + realSectorIndex * info.getSectorSize() + sectorOffset;
|
||||||
|
|
||||||
input.seek(offset2);
|
input.seek(offset2);
|
||||||
int read = input.read(buffer);
|
int read = input.read(buffer);
|
||||||
if (read < 0) return;
|
if (read < 0) return;
|
||||||
try {
|
try {
|
||||||
out.write(Arrays.copyOfRange(buffer, 0, bytesToRead));
|
out.write(Arrays.copyOfRange(buffer, 0, bytesToRead));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().equals("Pipe closed")) {
|
if (e.getMessage().equals("Pipe closed")) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
usedSize -= bytesToRead;
|
usedSize -= bytesToRead;
|
||||||
usedOffset += bytesToRead;
|
usedOffset += bytesToRead;
|
||||||
|
}
|
||||||
|
input.close();
|
||||||
}
|
}
|
||||||
input.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user