Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-19 17:30:08 +01:00
chore: use the actual FileChannel for mark / reset (if present)
Dieser Commit ist enthalten in:
Ursprung
b4b427b38e
Commit
b150c69c2a
@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.extent.clipboard.io;
|
|||||||
|
|
||||||
import com.fastasyncworldedit.core.extent.clipboard.LinearClipboard;
|
import com.fastasyncworldedit.core.extent.clipboard.LinearClipboard;
|
||||||
import com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard;
|
import com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard;
|
||||||
|
import com.fastasyncworldedit.core.internal.io.ResettableFileInputStream;
|
||||||
import com.fastasyncworldedit.core.internal.io.VarIntStreamIterator;
|
import com.fastasyncworldedit.core.internal.io.VarIntStreamIterator;
|
||||||
import com.fastasyncworldedit.core.math.MutableBlockVector3;
|
import com.fastasyncworldedit.core.math.MutableBlockVector3;
|
||||||
import com.sk89q.jnbt.NBTConstants;
|
import com.sk89q.jnbt.NBTConstants;
|
||||||
@ -21,16 +22,20 @@ import com.sk89q.worldedit.world.biome.BiomeTypes;
|
|||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
|
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.io.InputStream;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClipboardReader for the Sponge Schematic Format v3.
|
* ClipboardReader for the Sponge Schematic Format v3.
|
||||||
@ -42,11 +47,13 @@ public class FastSchematicReaderV3 implements ClipboardReader {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
|
|
||||||
private final DataInputStream dataInputStream;
|
private final InputStream resetableInputStream;
|
||||||
private final NBTInputStream nbtInputStream;
|
private final MutableBlockVector3 dimensions = MutableBlockVector3.at(0, 0, 0);
|
||||||
|
|
||||||
|
private DataInputStream dataInputStream;
|
||||||
|
private NBTInputStream nbtInputStream;
|
||||||
|
|
||||||
private VersionedDataFixer dataFixer;
|
private VersionedDataFixer dataFixer;
|
||||||
private MutableBlockVector3 dimensions = MutableBlockVector3.at(0, 0, 0);
|
|
||||||
private BlockVector3 offset;
|
private BlockVector3 offset;
|
||||||
private BlockState[] blockPalette;
|
private BlockState[] blockPalette;
|
||||||
private BiomeType[] biomePalette;
|
private BiomeType[] biomePalette;
|
||||||
@ -58,29 +65,32 @@ public class FastSchematicReaderV3 implements ClipboardReader {
|
|||||||
|
|
||||||
private boolean needAdditionalIterate = true;
|
private boolean needAdditionalIterate = true;
|
||||||
|
|
||||||
public FastSchematicReaderV3(
|
public FastSchematicReaderV3(InputStream stream) throws IOException {
|
||||||
DataInputStream dataInputStream,
|
if (stream instanceof FileInputStream fileInputStream) {
|
||||||
NBTInputStream nbtInputStream
|
stream = new ResettableFileInputStream(fileInputStream);
|
||||||
) throws IOException {
|
} else if (!stream.markSupported()) {
|
||||||
this.dataInputStream = Objects.requireNonNull(dataInputStream, "dataInputStream");
|
LOGGER.warn("InputStream does not support mark - will be wrapped using in memory buffer");
|
||||||
this.nbtInputStream = Objects.requireNonNull(nbtInputStream, "nbtInputStream");
|
stream = new BufferedInputStream(stream);
|
||||||
if (!dataInputStream.markSupported()) {
|
|
||||||
throw new IOException("InputStream does not support mark");
|
|
||||||
}
|
}
|
||||||
|
this.resetableInputStream = stream;
|
||||||
|
this.resetableInputStream.mark(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Clipboard read(final UUID uuid, final Function<BlockVector3, Clipboard> createOutput) throws IOException {
|
public Clipboard read(final UUID uuid, final Function<BlockVector3, Clipboard> createOutput) throws IOException {
|
||||||
dataInputStream.skipNBytes(1 + 2); // 1 Byte = TAG_Compound, 2 Bytes = Short (Length of tag name = "")
|
|
||||||
dataInputStream.skipNBytes(1 + 2 + 9); // as above + 9 bytes = "Schematic"
|
|
||||||
this.dataInputStream.mark(Integer.MAX_VALUE); // allow resets to basically the start of stream (file) - just skip header
|
|
||||||
|
|
||||||
Clipboard clipboard = null;
|
Clipboard clipboard = null;
|
||||||
|
|
||||||
while (needAdditionalIterate) {
|
while (needAdditionalIterate) {
|
||||||
this.needAdditionalIterate = false;
|
this.needAdditionalIterate = false;
|
||||||
this.dataInputStream.reset();
|
this.resetableInputStream.reset();
|
||||||
this.dataInputStream.mark(Integer.MAX_VALUE);
|
this.resetableInputStream.mark(Integer.MAX_VALUE);
|
||||||
|
final FastBufferedInputStream buffer = new FastBufferedInputStream(new GZIPInputStream(this.resetableInputStream));
|
||||||
|
this.dataInputStream = new DataInputStream(buffer);
|
||||||
|
this.nbtInputStream = new NBTInputStream(buffer);
|
||||||
|
|
||||||
|
// Skip header
|
||||||
|
dataInputStream.skipNBytes(1 + 2); // 1 Byte = TAG_Compound, 2 Bytes = Short (Length of tag name = "")
|
||||||
|
dataInputStream.skipNBytes(1 + 2 + 9); // as above + 9 bytes = "Schematic"
|
||||||
|
|
||||||
while (dataInputStream.readByte() != NBTConstants.TYPE_END) {
|
while (dataInputStream.readByte() != NBTConstants.TYPE_END) {
|
||||||
String tag = readTagName();
|
String tag = readTagName();
|
||||||
@ -320,7 +330,7 @@ public class FastSchematicReaderV3 implements ClipboardReader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
nbtInputStream.close(); // closes the DataInputStream implicitly
|
resetableInputStream.close(); // closes all underlying resources implicitly
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClipboardReader getReader(InputStream inputStream) throws IOException {
|
public ClipboardReader getReader(InputStream inputStream) throws IOException {
|
||||||
if (inputStream instanceof FileInputStream fileInputStream) {
|
return new FastSchematicReaderV3(inputStream);
|
||||||
inputStream = new ResettableFileInputStream(fileInputStream);
|
|
||||||
}
|
|
||||||
BufferedInputStream buffered = new BufferedInputStream(new GZIPInputStream(new BufferedInputStream(inputStream)));
|
|
||||||
DataInputStream dataInputStream = new DataInputStream(buffered);
|
|
||||||
NBTInputStream nbtStream = new NBTInputStream(buffered);
|
|
||||||
return new FastSchematicReaderV3(dataInputStream, nbtStream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren