mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 08:08:34 +00:00
Allow NBT stored in DiskOptimizedClipboards to be written to disk as a compressed byte array at the end of the file (#1745)
* Allow NBT stored in DiskOptimizedClipboards to be written to disk as a compressed byte array at the end of the file * Add some deprecations/javadocs and provide the expected clipboard version on error * Javadoc since tags and add location of clipboard folder to error * Refactor load-from-file method into DOC class * Refactor nbt loading code into separate method in DOC
This commit is contained in:
@ -1,11 +1,62 @@
|
||||
package com.fastasyncworldedit.core.internal.exception;
|
||||
|
||||
import com.fastasyncworldedit.core.Fawe;
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.configuration.Settings;
|
||||
import com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FaweClipboardVersionMismatchException extends FaweException {
|
||||
|
||||
private final int expected;
|
||||
private final int version;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link FaweClipboardVersionMismatchException#FaweClipboardVersionMismatchException(int, int)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "TODO")
|
||||
public FaweClipboardVersionMismatchException() {
|
||||
super(Caption.of("fawe.error.clipboard.on.disk.version.mismatch"), Type.CLIPBOARD);
|
||||
this(DiskOptimizedClipboard.VERSION, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* New exception specifying a version mismatch between that supported and that loaded.
|
||||
*
|
||||
* @param version version of clipboard attempting to be loaded
|
||||
* @param expected expected version of clipboard
|
||||
* @since TODO
|
||||
*/
|
||||
public FaweClipboardVersionMismatchException(int expected, int version) {
|
||||
super(
|
||||
Caption.of(
|
||||
"fawe.error.clipboard.on.disk.version.mismatch",
|
||||
expected,
|
||||
version,
|
||||
Fawe.platform().getDirectory().getName() + File.separator + Settings.settings().PATHS.CLIPBOARD
|
||||
),
|
||||
Type.CLIPBOARD
|
||||
);
|
||||
this.expected = expected;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version specified in the clipboard attempting to be loaded.
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public int getClipboardVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version that was expected of the clipboard
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public int getExpectedVersion() {
|
||||
return expected;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.fastasyncworldedit.core.internal.io;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* <a href="https://stackoverflow.com/questions/4332264/wrapping-a-bytebuffer-with-an-inputstream">https://stackoverflow.com/questions/4332264/wrapping-a-bytebuffer-with-an-inputstream</a>
|
||||
*/
|
||||
public class ByteBufferInputStream extends InputStream {
|
||||
|
||||
ByteBuffer buf;
|
||||
|
||||
public ByteBufferInputStream(ByteBuffer buf) {
|
||||
this.buf = buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (!buf.hasRemaining()) {
|
||||
return -1;
|
||||
}
|
||||
return buf.get() & 0xFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@Nonnull byte[] bytes, int off, int len) throws IOException {
|
||||
if (!buf.hasRemaining()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = Math.min(len, buf.remaining());
|
||||
buf.get(bytes, off, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user