Moved some utilities to Sedna.
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
package li.cil.oc2.common.serialization.serializers;
|
||||
|
||||
import li.cil.ceres.api.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.BitSet;
|
||||
|
||||
@RegisterSerializer
|
||||
public final class BitSetSerializer implements Serializer<BitSet> {
|
||||
@Override
|
||||
public void serialize(final SerializationVisitor visitor, final Class<BitSet> type, final Object value) throws SerializationException {
|
||||
visitor.putObject("value", long[].class, ((BitSet) value).toLongArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitSet deserialize(final DeserializationVisitor visitor, final Class<BitSet> type, @Nullable final Object value) throws SerializationException {
|
||||
BitSet bitSet = (BitSet) value;
|
||||
if (!visitor.exists("value")) {
|
||||
return bitSet;
|
||||
}
|
||||
|
||||
final long[] longs = (long[]) visitor.getObject("value", long[].class, null);
|
||||
if (longs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (bitSet == null) {
|
||||
bitSet = BitSet.valueOf(longs);
|
||||
} else {
|
||||
bitSet.clear();
|
||||
bitSet.or(BitSet.valueOf(longs));
|
||||
}
|
||||
|
||||
return bitSet;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package li.cil.oc2.common.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class ByteBufferInputStream extends InputStream {
|
||||
private final ByteBuffer buffer;
|
||||
|
||||
public ByteBufferInputStream(final ByteBuffer buffer) {
|
||||
this.buffer = buffer.slice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() {
|
||||
if (!buffer.hasRemaining()) {
|
||||
return -1;
|
||||
}
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] b, final int off, int len) {
|
||||
len = Math.min(len, buffer.remaining());
|
||||
if (len == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
buffer.get(b, off, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package li.cil.oc2.common.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class ByteBufferOutputStream extends OutputStream {
|
||||
private final ByteBuffer buffer;
|
||||
|
||||
public ByteBufferOutputStream(final ByteBuffer buffer) {
|
||||
this.buffer = buffer.slice();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final int b) throws IOException {
|
||||
try {
|
||||
buffer.put((byte) b);
|
||||
} catch (final BufferOverflowException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final byte[] b, final int off, final int len) throws IOException {
|
||||
try {
|
||||
buffer.put(b, off, len);
|
||||
} catch (final BufferOverflowException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user