Fix error from flushing on different thread

This commit is contained in:
Jesse Boyd 2016-09-24 14:41:33 +10:00
parent d4fd374caa
commit d61c21f60e
2 changed files with 78 additions and 70 deletions

View File

@ -134,6 +134,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
@Override
public boolean flush() {
synchronized (this) {
super.flush();
boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null;
try {
@ -162,6 +163,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
}
return flushed;
}
}
@Override
public int getCompressedSize() {
@ -199,12 +201,14 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
if (osBD != null) {
return osBD;
}
synchronized (this) {
bdFile.getParentFile().mkdirs();
bdFile.createNewFile();
osBD = getCompressedOS(new FileOutputStream(bdFile));
writeHeader(osBD, x, y, z);
return osBD;
}
}
@Override
public NBTOutputStream getEntityCreateOS() throws IOException {

View File

@ -48,6 +48,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
@Override
public boolean flush() {
synchronized (this) {
super.flush();
try {
if (idsStream != null) {
@ -85,6 +86,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
} catch (IOException e) {
MainUtil.handleError(e);
}
}
return false;
}
@ -110,12 +112,14 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
if (idsStreamZip != null) {
return idsStreamZip;
}
synchronized (this) {
setOrigin(x, z);
idsStream = new FastByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE);
idsStreamZip = getCompressedOS(idsStream);
writeHeader(idsStreamZip, x, y, z);
return idsStreamZip;
}
}
@Override
public InputStream getBlockIS() throws IOException {