Well, it works now ig
-Better file lengthening -Made temp files -Exchanged temp files for ByteArrayIn/OutputBuffers -Fixed loadRegion to actually read sector sizes
This commit is contained in:
parent
6891d3a095
commit
9c26418354
@ -21,6 +21,8 @@ package ru.windcorp.progressia.test;
|
|||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -52,7 +54,7 @@ import ru.windcorp.progressia.server.Server;
|
|||||||
public class TestWorldDiskIO {
|
public class TestWorldDiskIO {
|
||||||
|
|
||||||
private static Path SAVE_DIR = Paths.get("tmp_world");
|
private static Path SAVE_DIR = Paths.get("tmp_world");
|
||||||
private static String formatFile = "world.format";
|
private static final String formatFile = "world.format";
|
||||||
private static final Logger LOG = LogManager.getLogger("TestWorldDiskIO");
|
private static final Logger LOG = LogManager.getLogger("TestWorldDiskIO");
|
||||||
|
|
||||||
private static final boolean ENABLE = true;
|
private static final boolean ENABLE = true;
|
||||||
@ -218,6 +220,12 @@ public class TestWorldDiskIO {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*if (!dosave)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dosave = false;*/
|
||||||
|
|
||||||
try (
|
try (
|
||||||
RandomAccessFile output = new RandomAccessFile(path.toFile(), "rw")
|
RandomAccessFile output = new RandomAccessFile(path.toFile(), "rw")
|
||||||
) {
|
) {
|
||||||
@ -242,27 +250,30 @@ public class TestWorldDiskIO {
|
|||||||
output.seek(shortOffset);
|
output.seek(shortOffset);
|
||||||
output.writeInt(offset<<8);
|
output.writeInt(offset<<8);
|
||||||
output.seek(outputLen);
|
output.seek(outputLen);
|
||||||
while (output.length()<fullOffset+sectorSize*offset)
|
/*while (output.length()<fullOffset+sectorSize*offset)
|
||||||
{
|
{
|
||||||
output.write(0);
|
output.write((int) (output.length()%256));
|
||||||
}
|
}*/
|
||||||
|
output.setLength(fullOffset+offset*sectorSize);
|
||||||
//output.write(200);
|
//output.write(200);
|
||||||
}
|
}
|
||||||
output.seek((long) fullOffset+sectorSize*offset);
|
|
||||||
|
|
||||||
//int bytestoWrite = output.readInt();
|
//int bytestoWrite = output.readInt();
|
||||||
//output.mark(sectorSize*sectorLength);
|
//output.mark(sectorSize*sectorLength);
|
||||||
|
|
||||||
CountingOutputStream counter = new CountingOutputStream(new BufferedOutputStream(Channels.newOutputStream(output.getChannel())));
|
//BufferedOutputStream counter = new BufferedOutputStream(Files.newOutputStream( SAVE_DIR.resolve(tempFile)));
|
||||||
|
ByteArrayOutputStream tempDataStream = new ByteArrayOutputStream();
|
||||||
DataOutputStream trueOutput = new DataOutputStream(
|
DataOutputStream trueOutput = new DataOutputStream(
|
||||||
new DeflaterOutputStream(
|
new DeflaterOutputStream(
|
||||||
counter
|
new BufferedOutputStream(tempDataStream)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// CountingOutputStream countOutput = new
|
// CountingOutputStream countOutput = new
|
||||||
// CountingOutputStream(trueOutput);
|
// CountingOutputStream(trueOutput);
|
||||||
|
|
||||||
//LOG.info("Before: {}",output.);
|
//LOG.info("Before: {}",output.);
|
||||||
|
//trueOutput.writeBytes("uh try this");
|
||||||
|
//counter.
|
||||||
ChunkIO.save(chunk, trueOutput, IOContext.SAVE);
|
ChunkIO.save(chunk, trueOutput, IOContext.SAVE);
|
||||||
writeGenerationHint(chunk, trueOutput, server);
|
writeGenerationHint(chunk, trueOutput, server);
|
||||||
|
|
||||||
@ -270,11 +281,23 @@ public class TestWorldDiskIO {
|
|||||||
counter.write(0);
|
counter.write(0);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
output.seek(shortOffset+offsetBytes);
|
|
||||||
LOG.info("Wrote {} bytes to {},{},{}",counter.getCount(),chunk.getPosition().x,chunk.getPosition().y,chunk.getPosition().z);
|
LOG.info("Wrote {} bytes to {},{},{}",trueOutput.size(),chunk.getPosition().x,chunk.getPosition().y,chunk.getPosition().z);
|
||||||
output.write((int) counter.getCount()/sectorSize);
|
|
||||||
|
|
||||||
trueOutput.close();
|
trueOutput.close();
|
||||||
|
|
||||||
|
byte tempData[] = tempDataStream.toByteArray();
|
||||||
|
|
||||||
|
output.seek((long) fullOffset+sectorSize*offset);
|
||||||
|
output.write(tempData);
|
||||||
|
|
||||||
|
output.seek(shortOffset+offsetBytes);
|
||||||
|
output.write((int) tempData.length/sectorSize + 1);
|
||||||
|
LOG.info("Used {} sectors",(int) tempData.length/sectorSize + 1);
|
||||||
|
|
||||||
|
output.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if (currentFormat)
|
// else if (currentFormat)
|
||||||
@ -514,15 +537,19 @@ public class TestWorldDiskIO {
|
|||||||
offset*=256;
|
offset*=256;
|
||||||
offset += input.read();
|
offset += input.read();
|
||||||
}
|
}
|
||||||
int sectorLength = offset & 255;
|
int sectorLength = input.read();
|
||||||
offset = offset >> 8;
|
|
||||||
input.skipNBytes(fullOffset-shortOffset-offsetBytes-1);
|
input.skipNBytes(fullOffset-shortOffset-offsetBytes-1);
|
||||||
input.skipNBytes(sectorSize*offset);
|
input.skipNBytes(sectorSize*offset);
|
||||||
input.mark(sectorSize*sectorLength);
|
|
||||||
|
LOG.info("Read {} sectors", sectorLength);
|
||||||
|
|
||||||
|
byte tempData[] = input.readNBytes(sectorSize*sectorLength);
|
||||||
|
|
||||||
DataInputStream trueInput = new DataInputStream(
|
DataInputStream trueInput = new DataInputStream(
|
||||||
new InflaterInputStream(input));
|
new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(tempData))));
|
||||||
ChunkData chunk = ChunkIO.load(world, chunkPos, trueInput, IOContext.SAVE);
|
ChunkData chunk = ChunkIO.load(world, chunkPos, trueInput, IOContext.SAVE);
|
||||||
readGenerationHint(chunk, trueInput, server);
|
readGenerationHint(chunk, trueInput, server);
|
||||||
|
trueInput.close();
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user