diff --git a/pom.xml b/pom.xml index 24f5e97..f08fade 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 9.5.0 7.9.2 5.9.0 - 1.0.252 + 1.0.258 diff --git a/src/main/data-generator/quic-rpc.yaml b/src/main/data-generator/quic-rpc.yaml index 719556a..0d74adb 100644 --- a/src/main/data-generator/quic-rpc.yaml +++ b/src/main/data-generator/quic-rpc.yaml @@ -131,7 +131,7 @@ customTypesData: serializer: it.cavallium.dbengine.database.remote.LLSnapshotSerializer Bytes: - javaClass: it.cavallium.dbengine.buffers.Buf + javaClass: it.cavallium.buffer.Buf serializer: it.cavallium.dbengine.database.remote.BufSerializer StringMap: javaClass: java.util.Map diff --git a/src/main/java/it/cavallium/dbengine/buffers/Buf.java b/src/main/java/it/cavallium/dbengine/buffers/Buf.java deleted file mode 100644 index 2e678d2..0000000 --- a/src/main/java/it/cavallium/dbengine/buffers/Buf.java +++ /dev/null @@ -1,182 +0,0 @@ -package it.cavallium.dbengine.buffers; - -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; -import it.unimi.dsi.fastutil.bytes.ByteArrayList; -import it.unimi.dsi.fastutil.bytes.ByteList; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.RandomAccess; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.warp.commonutils.stream.SafeByteArrayInputStream; -import org.warp.commonutils.stream.SafeByteArrayOutputStream; -import org.warp.commonutils.stream.SafeDataOutput; - -public interface Buf extends ByteList, RandomAccess { - static Buf wrap(ByteList bytes) { - if (bytes instanceof Buf buf) { - return buf; - } else if (bytes instanceof ByteArrayList byteArrayList) { - return ByteListBuf.wrap(byteArrayList.elements(), byteArrayList.size()); - } else { - return ByteListBuf.wrap(bytes.toByteArray()); - } - } - static Buf wrap(ByteList bytes, int from, int to) { - if (bytes instanceof Buf buf) { - return buf.subList(from, to); - } else if (bytes instanceof ByteArrayList byteArrayList) { - return ByteListBuf.wrap(byteArrayList.elements(), byteArrayList.size()).subList(from, to); - } else { - return ByteListBuf.wrap(bytes.toByteArray()).subList(from, to); - } - } - - static Buf wrap(byte[] bytes) { - return ByteListBuf.wrap(bytes); - } - - static Buf wrap(byte[] bytes, int from, int to) { - return ByteListBuf.wrap(bytes, to).subList(from, to); - } - - static Buf create(int initialCapacity) { - return new ByteListBuf(initialCapacity); - } - - static Buf copyOf(byte[] original) { - return new ByteListBuf(original); - } - - static Buf create() { - return new ByteListBuf(); - } - - static Buf wrap(byte[] array, int length) { - return ByteListBuf.wrap(array, length); - } - - static Buf createZeroes(int length) { - return ByteListBuf.wrap(new byte[length], length); - } - - /** - * Get this element as an array, converting it if needed - */ - byte @NotNull[] asArray(); - - /** - * Get this element as an array, only if it's already an array, otherwise return null - */ - byte @Nullable[] asArrayStrict(); - - /** - * Get this element as an array with equal or bigger size, converting it if needed - * The returned array may be bigger than expected! - */ - byte @Nullable[] asUnboundedArray(); - - /** - * Get this element as an array with equal or bigger size, only if it's already an array, otherwise return null - * The returned array may be bigger than expected! - */ - byte @Nullable[] asUnboundedArrayStrict(); - - boolean isMutable(); - - void freeze(); - - @Override - Buf subList(int from, int to); - - Buf copy(); - - SafeByteArrayInputStream binaryInputStream(); - - void writeTo(SafeDataOutput dataOutput); - - default long getLong(int i) { - return Longs.fromBytes(getByte(i), - getByte(i + 1), - getByte(i + 2), - getByte(i + 3), - getByte(i + 4), - getByte(i + 5), - getByte(i + 6), - getByte(i + 7) - ); - } - - default int getInt(int i) { - return Ints.fromBytes(getByte(i), - getByte(i + 1), - getByte(i + 2), - getByte(i + 3) - ); - } - - default float getFloat(int i) { - return Float.intBitsToFloat(getInt(i)); - } - - default double getDouble(int i) { - return Double.longBitsToDouble(getLong(i)); - } - - default boolean getBoolean(int i) { - return getByte(i) != 0; - } - - default void setBoolean(int i, boolean val) { - set(i, val ? (byte) 1 : 0); - } - - default void setByte(int i, byte val) { - set(i, val); - } - - default void setInt(int i, int val) { - set(i, (byte) (val >> 24)); - set(i + 1, (byte) (val >> 16)); - set(i + 2, (byte) (val >> 8)); - set(i + 3, (byte) val); - } - - default void setLong(int i, long val) { - set(i, (byte) (val >> 56)); - set(i + 1, (byte) (val >> 48)); - set(i + 2, (byte) (val >> 40)); - set(i + 3, (byte) (val >> 32)); - set(i + 4, (byte) (val >> 24)); - set(i + 5, (byte) (val >> 16)); - set(i + 6, (byte) (val >> 8)); - set(i + 7, (byte) val); - } - - default void setFloat(int i, float val) { - setInt(i, Float.floatToRawIntBits(val)); - } - - default void setDouble(int i, double val) { - setLong(i, Double.doubleToRawLongBits(val)); - } - - default SafeByteArrayOutputStream binaryOutputStream() { - return binaryOutputStream(0, size()); - } - - default SafeByteArrayOutputStream binaryOutputStream(int from) { - return binaryOutputStream(from, size()); - } - - SafeByteArrayOutputStream binaryOutputStream(int from, int to); - - boolean equals(int aStartIndex, Buf b, int bStartIndex, int length); - - boolean equals(int aStartIndex, byte[] b, int bStartIndex, int length); - - default String toString(Charset charset) { - return new String(this.asArray(), charset); - } -} diff --git a/src/main/java/it/cavallium/dbengine/buffers/BufDataInput.java b/src/main/java/it/cavallium/dbengine/buffers/BufDataInput.java deleted file mode 100644 index 13db4ac..0000000 --- a/src/main/java/it/cavallium/dbengine/buffers/BufDataInput.java +++ /dev/null @@ -1,42 +0,0 @@ -package it.cavallium.dbengine.buffers; - -import org.jetbrains.annotations.NotNull; -import org.warp.commonutils.stream.SafeByteArrayInputStream; -import org.warp.commonutils.stream.SafeDataInputStream; - - -public class BufDataInput extends SafeDataInputStream { - - /** - * Creates a DataInputStream that uses the specified underlying InputStream. - * - * @param in the specified input stream - */ - private BufDataInput(@NotNull SafeByteArrayInputStream in) { - super(in); - } - - public static BufDataInput create(Buf byteList) { - return new BufDataInput(byteList.binaryInputStream()); - } - - @Deprecated - @Override - public void close() { - } - - @Override - public void mark(int readlimit) { - throw new UnsupportedOperationException(); - } - - @Override - public void reset() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean markSupported() { - return false; - } -} diff --git a/src/main/java/it/cavallium/dbengine/buffers/BufDataOutput.java b/src/main/java/it/cavallium/dbengine/buffers/BufDataOutput.java deleted file mode 100644 index 238e213..0000000 --- a/src/main/java/it/cavallium/dbengine/buffers/BufDataOutput.java +++ /dev/null @@ -1,235 +0,0 @@ -package it.cavallium.dbengine.buffers; - -import static org.warp.commonutils.stream.SafeDataOutputStream.strLen; -import static org.warp.commonutils.stream.SafeDataOutputStream.utfLen; - -import it.unimi.dsi.fastutil.Arrays; -import java.io.DataOutput; -import java.io.IOException; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; -import org.warp.commonutils.stream.SafeByteArrayOutputStream; -import org.warp.commonutils.stream.SafeDataOutputStream; - -public class BufDataOutput implements DataOutput { - - private final SafeByteArrayOutputStream buf; - private final SafeDataOutputStream dOut; - private final int limit; - - private BufDataOutput(SafeByteArrayOutputStream buf) { - this.buf = buf; - this.dOut = new SafeDataOutputStream(buf); - limit = Integer.MAX_VALUE; - } - - private BufDataOutput(SafeByteArrayOutputStream buf, int maxSize) { - this.buf = buf; - this.dOut = new SafeDataOutputStream(buf); - this.limit = maxSize; - } - - public static BufDataOutput createLimited(int maxSize, int hint) { - if (hint >= 0) { - if (maxSize < 0 || maxSize == Integer.MAX_VALUE) { - return create(hint); - } else { - return new BufDataOutput(new SafeByteArrayOutputStream(Math.min(maxSize, hint)), maxSize); - } - } else { - return createLimited(maxSize); - } - } - - public static BufDataOutput createLimited(int maxSize) { - if (maxSize < 0 || maxSize == Integer.MAX_VALUE) { - return create(); - } else { - return new BufDataOutput(new SafeByteArrayOutputStream(maxSize), maxSize); - } - } - - public static BufDataOutput create() { - return new BufDataOutput(new SafeByteArrayOutputStream()); - } - - public static BufDataOutput create(int hint) { - if (hint >= 0) { - return new BufDataOutput(new SafeByteArrayOutputStream(hint)); - } else { - return create(); - } - } - - public static BufDataOutput wrap(Buf buf, int from, int to) { - Arrays.ensureFromTo(buf.size(), from, to); - if (buf.isEmpty()) { - return createLimited(0); - } else { - return new BufDataOutput(buf.binaryOutputStream(from), to - from); - } - } - - public static BufDataOutput wrap(Buf buf) { - if (buf.isEmpty()) { - return createLimited(0); - } else { - return new BufDataOutput(buf.binaryOutputStream(), buf.size()); - } - } - - private IllegalStateException unreachable(IOException ex) { - return new IllegalStateException(ex); - } - - @Override - public void write(int b) { - checkOutOfBounds(1); - dOut.write(b); - } - - private void checkOutOfBounds(int delta) { - if (dOut.size() + delta > limit) { - throw new IndexOutOfBoundsException(limit); - } - } - - @Override - public void write(byte @NotNull [] b) { - checkOutOfBounds(b.length); - dOut.write(b); - } - - @Override - public void write(byte @NotNull [] b, int off, int len) { - checkOutOfBounds(Math.max(0, Math.min(b.length - off, len))); - dOut.write(b, off, len); - } - - @Override - public void writeBoolean(boolean v) { - checkOutOfBounds(1); - dOut.writeBoolean(v); - } - - @Override - public void writeByte(int v) { - checkOutOfBounds(Byte.BYTES); - dOut.writeByte(v); - } - - @Override - public void writeShort(int v) { - checkOutOfBounds(Short.BYTES); - dOut.writeShort(v); - } - - @Override - public void writeChar(int v) { - checkOutOfBounds(Character.BYTES); - dOut.writeChar(v); - } - - @Override - public void writeInt(int v) { - checkOutOfBounds(Integer.BYTES); - dOut.writeInt(v); - } - - @Override - public void writeLong(long v) { - checkOutOfBounds(Long.BYTES); - dOut.writeLong(v); - } - - @Override - public void writeFloat(float v) { - checkOutOfBounds(Float.BYTES); - dOut.writeFloat(v); - } - - @Override - public void writeDouble(double v) { - checkOutOfBounds(Double.BYTES); - dOut.writeDouble(v); - } - - public void ensureWritable(int size) { - dOut.flush(); - buf.ensureWritable(size); - } - - @Override - public void writeBytes(@NotNull String s) { - checkOutOfBounds(s.length() * Byte.BYTES); - dOut.writeBytes(s); - } - - // todo: check - public void writeBytes(Buf deserialized) { - checkOutOfBounds(deserialized.size()); - deserialized.writeTo(dOut); - } - - public void writeBytes(byte[] b, int off, int len) { - write(b, off, len); - } - - @Override - public void writeChars(@NotNull String s) { - checkOutOfBounds(Character.BYTES * s.length()); - dOut.writeChars(s); - } - - private static String tooLongMsg(String s, int bits32) { - int slen = s.length(); - String head = s.substring(0, 8); - String tail = s.substring(slen - 8, slen); - // handle int overflow with max 3x expansion - long actualLength = (long)slen + Integer.toUnsignedLong(bits32 - slen); - return "encoded string (" + head + "..." + tail + ") too long: " - + actualLength + " bytes"; - } - - @Override - public void writeUTF(@NotNull String str) { - var strlen = strLen(str); - var utflen = utfLen(str, strlen); - var bytes = Short.BYTES + utflen; - checkOutOfBounds(bytes); - dOut.writeUTF(strlen, utflen, str); - } - - public Buf asList() { - dOut.flush(); - return Buf.wrap(this.buf.array, this.buf.length); - } - - @Override - public String toString() { - return dOut.toString(); - } - - @Override - public int hashCode() { - return dOut.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - BufDataOutput that = (BufDataOutput) o; - - return Objects.equals(dOut, that.dOut); - } - - public int size() { - return dOut.size(); - } -} diff --git a/src/main/java/it/cavallium/dbengine/buffers/ByteListBuf.java b/src/main/java/it/cavallium/dbengine/buffers/ByteListBuf.java deleted file mode 100644 index 3afbb85..0000000 --- a/src/main/java/it/cavallium/dbengine/buffers/ByteListBuf.java +++ /dev/null @@ -1,467 +0,0 @@ -package it.cavallium.dbengine.buffers; - -import it.unimi.dsi.fastutil.bytes.AbstractByteList; -import it.unimi.dsi.fastutil.bytes.ByteArrayList; -import it.unimi.dsi.fastutil.bytes.ByteCollection; -import it.unimi.dsi.fastutil.bytes.ByteConsumer; -import it.unimi.dsi.fastutil.bytes.ByteIterator; -import it.unimi.dsi.fastutil.bytes.ByteIterators; -import it.unimi.dsi.fastutil.bytes.ByteList; -import it.unimi.dsi.fastutil.bytes.ByteListIterator; -import it.unimi.dsi.fastutil.bytes.ByteSpliterator; -import it.unimi.dsi.fastutil.bytes.ByteSpliterators; -import java.io.Serial; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.NoSuchElementException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.warp.commonutils.stream.SafeByteArrayInputStream; -import org.warp.commonutils.stream.SafeByteArrayOutputStream; -import org.warp.commonutils.stream.SafeDataOutput; - -class ByteListBuf extends ByteArrayList implements Buf { - - private boolean mutable = true; - - protected ByteListBuf(byte[] a, boolean wrapped) { - super(a, wrapped); - } - - public ByteListBuf(int capacity) { - super(capacity); - } - - public ByteListBuf() { - } - - public ByteListBuf(Collection c) { - super(c); - } - - public ByteListBuf(ByteCollection c) { - super(c); - } - - public ByteListBuf(ByteList l) { - super(l); - } - - public ByteListBuf(byte[] a) { - super(a); - } - - public ByteListBuf(byte[] a, int offset, int length) { - super(a, offset, length); - } - - public ByteListBuf(Iterator i) { - super(i); - } - - public ByteListBuf(ByteIterator i) { - super(i); - } - - /** - * Wraps a given array into an array list of given size. - * - *

- * Note it is guaranteed that the type of the array returned by {@link #elements()} will be the same - * (see the comments in the class documentation). - * - * @param a an array to wrap. - * @param length the length of the resulting array list. - * @return a new array list of the given size, wrapping the given array. - */ - public static ByteListBuf wrap(final byte[] a, final int length) { - if (length > a.length) throw new IllegalArgumentException("The specified length (" + length + ") is greater than the array size (" + a.length + ")"); - final ByteListBuf l = new ByteListBuf(a, true); - l.size = length; - return l; - } - - /** - * Wraps a given array into an array list. - * - *

- * Note it is guaranteed that the type of the array returned by {@link #elements()} will be the same - * (see the comments in the class documentation). - * - * @param a an array to wrap. - * @return a new array list wrapping the given array. - */ - public static ByteListBuf wrap(final byte[] a) { - return wrap(a, a.length); - } - - /** - * Creates a new empty array list. - * - * @return a new empty array list. - */ - public static ByteListBuf of() { - return new ByteListBuf(); - } - - /** - * Creates an array list using an array of elements. - * - * @param init a the array the will become the new backing array of the array list. - * @return a new array list backed by the given array. - * @see #wrap - */ - - public static ByteListBuf of(final byte... init) { - return wrap(init); - } - - @Override - public byte @NotNull [] asArray() { - if (this.size() == a.length) { - return this.a; - } else { - return this.toByteArray(); - } - } - - @Override - public byte @Nullable [] asArrayStrict() { - if (this.size() == a.length) { - return a; - } else { - return null; - } - } - - @Override - public byte @Nullable [] asUnboundedArray() { - return a; - } - - @Override - public byte @Nullable [] asUnboundedArrayStrict() { - return a; - } - - @Override - public boolean isMutable() { - return mutable; - } - - @Override - public void freeze() { - mutable = false; - } - - @Override - public Buf subList(int from, int to) { - if (from == 0 && to == size()) return this; - ensureIndex(from); - ensureIndex(to); - if (from > to) throw new IndexOutOfBoundsException("Start index (" + from + ") is greater than end index (" + to + ")"); - return new SubList(from, to); - } - - @Override - public Buf copy() { - var copied = ByteListBuf.wrap(this.a.clone()); - copied.size = this.size; - return copied; - } - - @Override - public SafeByteArrayInputStream binaryInputStream() { - return new SafeByteArrayInputStream(this.a, 0, this.size); - } - - @Override - public void writeTo(SafeDataOutput dataOutput) { - dataOutput.write(this.a, 0, this.size); - } - - @Override - public SafeByteArrayOutputStream binaryOutputStream(int from, int to) { - it.unimi.dsi.fastutil.Arrays.ensureFromTo(size, from, to); - return new SafeByteArrayOutputStream(a, from, to); - } - - @Override - public boolean equals(int aStartIndex, Buf b, int bStartIndex, int length) { - return b.equals(bStartIndex, this.a, aStartIndex, length); - } - - @Override - public boolean equals(int aStartIndex, byte[] b, int bStartIndex, int length) { - if (aStartIndex < 0) return false; - if (aStartIndex + length > this.size) { - return false; - } - return Arrays.equals(a, aStartIndex, aStartIndex + length, b, bStartIndex, bStartIndex + length); - } - - @Override - public String toString(Charset charset) { - return new String(a, 0, size, charset); - } - - private class SubList extends AbstractByteList.ByteRandomAccessSubList implements Buf { - @Serial - private static final long serialVersionUID = -3185226345314976296L; - - private boolean subMutable = true; - - protected SubList(int from, int to) { - super(ByteListBuf.this, from, to); - } - - // Most of the inherited methods should be fine, but we can override a few of them for performance. - // Needed because we can't access the parent class' instance variables directly in a different - // instance of SubList. - private byte[] getParentArray() { - return a; - } - - @Override - public @NotNull Buf subList(int from, int to) { - it.unimi.dsi.fastutil.Arrays.ensureFromTo(a.length, from, to); - if (from > to) throw new IllegalArgumentException("Start index (" + from + ") is greater than end index (" + to + ")"); - // Sadly we have to rewrap this, because if there is a sublist of a sublist, and the - // subsublist adds, both sublists need to update their "to" value. - return new SubList(from, to); - } - - @Override - public Buf copy() { - return Buf.wrap(Arrays.copyOfRange(a, from, to)); - } - - @Override - public SafeByteArrayInputStream binaryInputStream() { - return new SafeByteArrayInputStream(a, from, size()); - } - - @Override - public void writeTo(SafeDataOutput dataOutput) { - dataOutput.write(a, from, size()); - } - - @Override - public SafeByteArrayOutputStream binaryOutputStream(int from, int to) { - it.unimi.dsi.fastutil.Arrays.ensureFromTo(size(), from, to); - return new SafeByteArrayOutputStream(a, from + this.from, to + this.from); - } - - @Override - public boolean equals(int aStartIndex, Buf b, int bStartIndex, int length) { - return b.equals(bStartIndex, a, aStartIndex + from, length); - } - - @Override - public boolean equals(int aStartIndex, byte[] b, int bStartIndex, int length) { - var aFrom = from + aStartIndex; - var aTo = from + aStartIndex + length; - if (aFrom < from) return false; - if (aTo > to) return false; - return Arrays.equals(a, aFrom, aTo, b, bStartIndex, bStartIndex + length); - } - - @Override - public byte getByte(int i) { - ensureRestrictedIndex(i); - return a[i + from]; - } - - @Override - public byte @NotNull [] asArray() { - if (this.from == 0 && this.to == a.length) { - return a; - } else { - return toByteArray(); - } - } - - @Override - public byte @Nullable [] asArrayStrict() { - if (this.from == 0 && this.to == a.length) { - return a; - } else { - return null; - } - } - - @Override - public byte @Nullable [] asUnboundedArray() { - if (from == 0) { - return a; - } else { - return toByteArray(); - } - } - - @Override - public byte @Nullable [] asUnboundedArrayStrict() { - if (from == 0) { - return a; - } else { - return null; - } - } - - @Override - public boolean isMutable() { - return mutable && subMutable; - } - - @Override - public void freeze() { - subMutable = false; - } - - private final class SubListIterator extends ByteIterators.AbstractIndexBasedListIterator { - // We are using pos == 0 to be 0 relative to SubList.from (meaning you need to do a[from + i] when - // accessing array). - SubListIterator(int index) { - super(0, index); - } - - @Override - protected byte get(int i) { - return a[from + i]; - } - - @Override - protected void add(int i, byte k) { - ByteListBuf.SubList.this.add(i, k); - } - - @Override - protected void set(int i, byte k) { - ByteListBuf.SubList.this.set(i, k); - } - - @Override - protected void remove(int i) { - ByteListBuf.SubList.this.removeByte(i); - } - - @Override - protected int getMaxPos() { - return to - from; - } - - @Override - public byte nextByte() { - if (!hasNext()) throw new NoSuchElementException(); - return a[from + (lastReturned = pos++)]; - } - - @Override - public byte previousByte() { - if (!hasPrevious()) throw new NoSuchElementException(); - return a[from + (lastReturned = --pos)]; - } - - @Override - public void forEachRemaining(final ByteConsumer action) { - final int max = to - from; - while (pos < max) { - action.accept(a[from + (lastReturned = pos++)]); - } - } - } - - @Override - public @NotNull ByteListIterator listIterator(int index) { - return new ByteListBuf.SubList.SubListIterator(index); - } - - private final class SubListSpliterator extends ByteSpliterators.LateBindingSizeIndexBasedSpliterator { - // We are using pos == 0 to be 0 relative to real array 0 - SubListSpliterator() { - super(from); - } - - private SubListSpliterator(int pos, int maxPos) { - super(pos, maxPos); - } - - @Override - protected int getMaxPosFromBackingStore() { - return to; - } - - @Override - protected byte get(int i) { - return a[i]; - } - - @Override - protected ByteListBuf.SubList.SubListSpliterator makeForSplit(int pos, int maxPos) { - return new ByteListBuf.SubList.SubListSpliterator(pos, maxPos); - } - - @Override - public boolean tryAdvance(final ByteConsumer action) { - if (pos >= getMaxPos()) return false; - action.accept(a[pos++]); - return true; - } - - @Override - public void forEachRemaining(final ByteConsumer action) { - final int max = getMaxPos(); - while (pos < max) { - action.accept(a[pos++]); - } - } - } - - @Override - public ByteSpliterator spliterator() { - return new ByteListBuf.SubList.SubListSpliterator(); - } - - boolean contentsEquals(byte[] otherA, int otherAFrom, int otherATo) { - if (a == otherA && from == otherAFrom && to == otherATo) return true; - return Arrays.equals(a, from, to, otherA, otherAFrom, otherATo); - } - - @Override - public boolean equals(Object o) { - if (o == this) return true; - if (o == null) return false; - if (!(o instanceof java.util.List)) return false; - if (o instanceof ByteListBuf other) { - return contentsEquals(other.a, 0, other.size()); - } - if (o instanceof SubList other) { - return contentsEquals(other.getParentArray(), other.from, other.to); - } - return super.equals(o); - } - - int contentsCompareTo(byte[] otherA, int otherAFrom, int otherATo) { - if (a == otherA && from == otherAFrom && to == otherATo) return 0; - return Arrays.compareUnsigned(a, from, to, otherA, otherAFrom, otherATo); - } - - @Override - public int compareTo(final java.util.@NotNull List l) { - if (l instanceof ByteListBuf other) { - return contentsCompareTo(other.a, 0, other.size()); - } - if (l instanceof ByteListBuf.SubList other) { - return contentsCompareTo(other.getParentArray(), other.from, other.to); - } - return super.compareTo(l); - } - - @Override - public String toString(Charset charset) { - return new String(a, from, to, charset); - } - } -} diff --git a/src/main/java/it/cavallium/dbengine/client/BadBlock.java b/src/main/java/it/cavallium/dbengine/client/BadBlock.java index aee9a2c..1edfdbc 100644 --- a/src/main/java/it/cavallium/dbengine/client/BadBlock.java +++ b/src/main/java/it/cavallium/dbengine/client/BadBlock.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.client; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.rpc.current.data.Column; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java b/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java index 021be3b..e41b142 100644 --- a/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java +++ b/src/main/java/it/cavallium/dbengine/client/MappedSerializer.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.client; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.Serializer; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java b/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java index 36fc752..d9a1fb7 100644 --- a/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java +++ b/src/main/java/it/cavallium/dbengine/client/MappedSerializerFixedLength.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.client; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/it/cavallium/dbengine/client/query/QueryMoshi.java b/src/main/java/it/cavallium/dbengine/client/query/QueryMoshi.java index e711b5c..daabed5 100644 --- a/src/main/java/it/cavallium/dbengine/client/query/QueryMoshi.java +++ b/src/main/java/it/cavallium/dbengine/client/query/QueryMoshi.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.client.query; import com.squareup.moshi.JsonAdapter; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.IntOpenHashSetJsonAdapter; import it.cavallium.dbengine.client.query.current.CurrentVersion; import it.cavallium.dbengine.client.query.current.IBaseType; diff --git a/src/main/java/it/cavallium/dbengine/database/LLDelta.java b/src/main/java/it/cavallium/dbengine/database/LLDelta.java index f661cb6..c696048 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLDelta.java +++ b/src/main/java/it/cavallium/dbengine/database/LLDelta.java @@ -2,7 +2,7 @@ package it.cavallium.dbengine.database; import static it.cavallium.dbengine.database.LLUtils.unmodifiableBytes; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import java.util.StringJoiner; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/it/cavallium/dbengine/database/LLDictionary.java b/src/main/java/it/cavallium/dbengine/database/LLDictionary.java index 90433e1..a196572 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/LLDictionary.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.database.disk.BinarySerializationFunction; import it.cavallium.dbengine.database.serialization.KVSerializationFunction; diff --git a/src/main/java/it/cavallium/dbengine/database/LLEntry.java b/src/main/java/it/cavallium/dbengine/database/LLEntry.java index 469732e..61330f0 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLEntry.java +++ b/src/main/java/it/cavallium/dbengine/database/LLEntry.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import java.util.Objects; import java.util.StringJoiner; import org.apache.logging.log4j.LogManager; diff --git a/src/main/java/it/cavallium/dbengine/database/LLRange.java b/src/main/java/it/cavallium/dbengine/database/LLRange.java index 0f23f4b..7d7306d 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLRange.java +++ b/src/main/java/it/cavallium/dbengine/database/LLRange.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import java.util.StringJoiner; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/it/cavallium/dbengine/database/LLSingleton.java b/src/main/java/it/cavallium/dbengine/database/LLSingleton.java index 3883a5a..c642cb5 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLSingleton.java +++ b/src/main/java/it/cavallium/dbengine/database/LLSingleton.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.disk.BinarySerializationFunction; import java.io.IOException; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/it/cavallium/dbengine/database/LLUtils.java b/src/main/java/it/cavallium/dbengine/database/LLUtils.java index b53fd9c..96e74a4 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLUtils.java +++ b/src/main/java/it/cavallium/dbengine/database/LLUtils.java @@ -4,7 +4,7 @@ import static org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.HitEntry; import it.cavallium.dbengine.client.HitKey; import it.cavallium.dbengine.database.serialization.SerializationFunction; diff --git a/src/main/java/it/cavallium/dbengine/database/OptionalBuf.java b/src/main/java/it/cavallium/dbengine/database/OptionalBuf.java index c8fca38..b08c1af 100644 --- a/src/main/java/it/cavallium/dbengine/database/OptionalBuf.java +++ b/src/main/java/it/cavallium/dbengine/database/OptionalBuf.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; diff --git a/src/main/java/it/cavallium/dbengine/database/SerializedKey.java b/src/main/java/it/cavallium/dbengine/database/SerializedKey.java index b2ed6e4..23233fc 100644 --- a/src/main/java/it/cavallium/dbengine/database/SerializedKey.java +++ b/src/main/java/it/cavallium/dbengine/database/SerializedKey.java @@ -1,5 +1,5 @@ package it.cavallium.dbengine.database; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; public record SerializedKey(T key, Buf serialized) {} diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseEmpty.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseEmpty.java index cf935b9..c049baa 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseEmpty.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseEmpty.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.Serializer; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseInt.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseInt.java index 54a3eae..9572c6f 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseInt.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseInt.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure; import it.cavallium.dbengine.database.LLSingleton; import it.cavallium.dbengine.database.LLSnapshot; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseLong.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseLong.java index a66e8fa..c78e3fc 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseLong.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseLong.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure; import it.cavallium.dbengine.database.LLSingleton; import it.cavallium.dbengine.database.LLSnapshot; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java index fdf0b83..53f9978 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.Delta; import it.cavallium.dbengine.database.LLDelta; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryDeep.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryDeep.java index 6980d0b..ee2e250 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryDeep.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryDeep.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryHashed.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryHashed.java index ef2f8c0..dd760ea 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryHashed.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionaryHashed.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapSingle.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapSingle.java index 97dbfcb..7ba2b61 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapSingle.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapSingle.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.Delta; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionary.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionary.java index 0f2e4dc..995ee89 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionary.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionaryHashed.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionaryHashed.java index 51b7745..67a3f90 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionaryHashed.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionaryHashed.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSingleton.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSingleton.java index f11d342..2ce42a5 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSingleton.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSingleton.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.Delta; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetter.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetter.java index fe44243..a660c8f 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetter.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetter.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashMap.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashMap.java index 721b615..d849032 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashMap.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashMap.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.serialization.Serializer; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashSet.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashSet.java index f860ea2..0b9de2d 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashSet.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterHashSet.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMap.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMap.java index 17ae587..77ccab2 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMap.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMap.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.serialization.Serializer; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMapDeep.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMapDeep.java index e0b6894..8b45acc 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMapDeep.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterMapDeep.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSet.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSet.java index 4b4b315..69d8b32 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSet.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSet.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingle.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingle.java index ee5079a..9fc3fc7 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingle.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingle.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.serialization.Serializer; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingleBytes.java b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingleBytes.java index e7122e6..27706e2 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingleBytes.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/SubStageGetterSingleBytes.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.serialization.Serializer; public class SubStageGetterSingleBytes extends SubStageGetterSingle { diff --git a/src/main/java/it/cavallium/dbengine/database/collections/ValueWithHashSerializer.java b/src/main/java/it/cavallium/dbengine/database/collections/ValueWithHashSerializer.java index 05d0373..46e4f37 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/ValueWithHashSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/ValueWithHashSerializer.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.Serializer; import java.util.Map; diff --git a/src/main/java/it/cavallium/dbengine/database/collections/ValuesSetSerializer.java b/src/main/java/it/cavallium/dbengine/database/collections/ValuesSetSerializer.java index 2f3f28b..d1cdcb3 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/ValuesSetSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/ValuesSetSerializer.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.collections; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.Serializer; import it.unimi.dsi.fastutil.objects.ObjectArraySet; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java index 9e594d1..976027e 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java @@ -6,7 +6,7 @@ import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.RepeatedElementList; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/BinarySerializationFunction.java b/src/main/java/it/cavallium/dbengine/database/disk/BinarySerializationFunction.java index 1b67697..18adba5 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/BinarySerializationFunction.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/BinarySerializationFunction.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.serialization.SerializationFunction; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/CappedWriteBatch.java b/src/main/java/it/cavallium/dbengine/database/disk/CappedWriteBatch.java index 16349b3..1ba2b4c 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/CappedWriteBatch.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/CappedWriteBatch.java @@ -2,7 +2,7 @@ package it.cavallium.dbengine.database.disk; import static it.cavallium.dbengine.database.LLUtils.asArray; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import java.nio.ByteBuffer; import org.rocksdb.ColumnFamilyHandle; import org.rocksdb.RocksDBException; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/KeyMayExistGetter.java b/src/main/java/it/cavallium/dbengine/database/disk/KeyMayExistGetter.java index 367183a..3896fc7 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/KeyMayExistGetter.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/KeyMayExistGetter.java @@ -4,7 +4,7 @@ import static java.lang.Boolean.parseBoolean; import static java.lang.System.getProperty; import static java.util.Objects.requireNonNull; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLUtils; import java.nio.ByteBuffer; import org.apache.logging.log4j.LogManager; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java index f9a9f60..844c7e5 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java @@ -20,7 +20,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Streams; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Timer; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.database.ColumnUtils; import it.cavallium.dbengine.database.LLDelta; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalEntryReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalEntryReactiveRocksIterator.java index 7a16647..50ff8d3 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalEntryReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalEntryReactiveRocksIterator.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLEntry; import it.cavallium.dbengine.database.LLRange; import java.util.function.Supplier; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedEntryReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedEntryReactiveRocksIterator.java index c1978e1..bf8be85 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedEntryReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedEntryReactiveRocksIterator.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLEntry; import it.cavallium.dbengine.database.LLRange; import java.util.function.Supplier; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedKeyReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedKeyReactiveRocksIterator.java index 6742d96..28fea9a 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedKeyReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedKeyReactiveRocksIterator.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import java.util.function.Supplier; import org.rocksdb.ReadOptions; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedReactiveRocksIterator.java index 73d6b04..a13abb8 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalGroupedReactiveRocksIterator.java @@ -4,7 +4,7 @@ import static it.cavallium.dbengine.database.LLUtils.MARKER_ROCKSDB; import static it.cavallium.dbengine.database.LLUtils.generateCustomReadOptions; import static it.cavallium.dbengine.database.LLUtils.isBoundedRange; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.disk.rocksdb.RocksIteratorObj; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyPrefixReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyPrefixReactiveRocksIterator.java index e090785..920ced4 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyPrefixReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyPrefixReactiveRocksIterator.java @@ -7,7 +7,7 @@ import static it.cavallium.dbengine.utils.StreamUtils.streamWhileNonNull; import com.google.common.collect.Iterators; import com.google.common.collect.Streams; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.utils.DBException; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyReactiveRocksIterator.java index 66ff3ae..155ef51 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyReactiveRocksIterator.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import java.util.function.Supplier; import org.rocksdb.ReadOptions; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMigrationReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMigrationReactiveRocksIterator.java index 6d50a56..941ea60 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMigrationReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMigrationReactiveRocksIterator.java @@ -3,7 +3,7 @@ package it.cavallium.dbengine.database.disk; import static it.cavallium.dbengine.database.LLUtils.generateCustomReadOptions; import static it.cavallium.dbengine.utils.StreamUtils.streamWhileNonNull; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLEntry; import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLUtils; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalReactiveRocksIterator.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalReactiveRocksIterator.java index 312f51a..e1dc389 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalReactiveRocksIterator.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalReactiveRocksIterator.java @@ -5,7 +5,7 @@ import static it.cavallium.dbengine.database.LLUtils.generateCustomReadOptions; import static it.cavallium.dbengine.database.LLUtils.isBoundedRange; import static it.cavallium.dbengine.utils.StreamUtils.streamWhileNonNull; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.disk.rocksdb.RocksIteratorObj; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalSingleton.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalSingleton.java index 4886d04..229da8e 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalSingleton.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalSingleton.java @@ -3,7 +3,7 @@ package it.cavallium.dbengine.database.disk; import static it.cavallium.dbengine.database.disk.UpdateAtomicResultMode.DELTA; import com.google.common.util.concurrent.AbstractScheduledService.Scheduler; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDelta; import it.cavallium.dbengine.database.LLSingleton; import it.cavallium.dbengine.database.LLSnapshot; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java index 3469221..8f535ba 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java @@ -4,7 +4,7 @@ import static it.cavallium.dbengine.database.LLUtils.MARKER_ROCKSDB; import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.MeterRegistry; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDelta; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.lucene.ExponentialPageLimits; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/PessimisticRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/PessimisticRocksDBColumn.java index 1c46c8b..54b4993 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/PessimisticRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/PessimisticRocksDBColumn.java @@ -3,7 +3,7 @@ package it.cavallium.dbengine.database.disk; import static it.cavallium.dbengine.database.LLUtils.MARKER_ROCKSDB; import io.micrometer.core.instrument.MeterRegistry; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDelta; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.utils.DBException; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/RocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/RocksDBColumn.java index 4a16a51..745c59c 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/RocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/RocksDBColumn.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.disk; import io.micrometer.core.instrument.MeterRegistry; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.disk.rocksdb.RocksIteratorObj; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/StandardRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/StandardRocksDBColumn.java index a9f752d..8055369 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/StandardRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/StandardRocksDBColumn.java @@ -3,7 +3,7 @@ package it.cavallium.dbengine.database.disk; import static it.cavallium.dbengine.database.LLUtils.MARKER_ROCKSDB; import io.micrometer.core.instrument.MeterRegistry; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDelta; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.utils.DBException; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultCurrent.java b/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultCurrent.java index 00fca63..8b57d0d 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultCurrent.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultCurrent.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; public record UpdateAtomicResultCurrent(Buf current) implements UpdateAtomicResult { } diff --git a/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultPrevious.java b/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultPrevious.java index fbaafa3..8ef5dd6 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultPrevious.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/UpdateAtomicResultPrevious.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.disk; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; public record UpdateAtomicResultPrevious(Buf previous) implements UpdateAtomicResult { diff --git a/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/RocksIteratorObj.java b/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/RocksIteratorObj.java index 36db90b..ec8a214 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/RocksIteratorObj.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/RocksIteratorObj.java @@ -2,7 +2,7 @@ package it.cavallium.dbengine.database.disk.rocksdb; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Timer; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.utils.SimpleResource; import java.nio.ByteBuffer; diff --git a/src/main/java/it/cavallium/dbengine/database/memory/BLRange.java b/src/main/java/it/cavallium/dbengine/database/memory/BLRange.java index 6491992..00f316c 100644 --- a/src/main/java/it/cavallium/dbengine/database/memory/BLRange.java +++ b/src/main/java/it/cavallium/dbengine/database/memory/BLRange.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.memory; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; public class BLRange { diff --git a/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryDictionary.java b/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryDictionary.java index 86534f3..43b6b95 100644 --- a/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryDictionary.java @@ -4,7 +4,7 @@ import static it.cavallium.dbengine.utils.StreamUtils.count; import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.mapping; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.database.LLDelta; import it.cavallium.dbengine.database.LLDictionary; diff --git a/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryKeyValueDatabase.java b/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryKeyValueDatabase.java index bbbbd2a..75bb016 100644 --- a/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryKeyValueDatabase.java +++ b/src/main/java/it/cavallium/dbengine/database/memory/LLMemoryKeyValueDatabase.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.memory; import io.micrometer.core.instrument.MeterRegistry; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.MemoryStats; import it.cavallium.dbengine.database.ColumnProperty; import it.cavallium.dbengine.database.LLDictionary; diff --git a/src/main/java/it/cavallium/dbengine/database/memory/LLMemorySingleton.java b/src/main/java/it/cavallium/dbengine/database/memory/LLMemorySingleton.java index 80ad4c7..5dd81a2 100644 --- a/src/main/java/it/cavallium/dbengine/database/memory/LLMemorySingleton.java +++ b/src/main/java/it/cavallium/dbengine/database/memory/LLMemorySingleton.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.database.memory; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDelta; import it.cavallium.dbengine.database.LLDictionaryResultType; import it.cavallium.dbengine.database.LLSingleton; diff --git a/src/main/java/it/cavallium/dbengine/database/remote/BufSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/BufSerializer.java index 41cf82d..fa3c340 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/BufSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/BufSerializer.java @@ -1,7 +1,9 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,7 +12,7 @@ import org.jetbrains.annotations.NotNull; public class BufSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull Buf bytes) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Buf bytes) { dataOutput.writeInt(bytes.size()); for (Byte aByte : bytes) { dataOutput.writeByte(aByte); @@ -18,7 +20,7 @@ public class BufSerializer implements DataSerializer { } @Override - public @NotNull Buf deserialize(DataInput dataInput) throws IOException { + public @NotNull Buf deserialize(SafeDataInput dataInput) { var size = dataInput.readInt(); var bal = Buf.create(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/it/cavallium/dbengine/database/remote/ColumnFamilyHandleSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/ColumnFamilyHandleSerializer.java index 1f963e8..f6e468e 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/ColumnFamilyHandleSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/ColumnFamilyHandleSerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.rocksdb.ColumnFamilyHandle; public class ColumnFamilyHandleSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull ColumnFamilyHandle columnFamilyHandle) { + public void serialize(SafeDataOutput dataOutput, @NotNull ColumnFamilyHandle columnFamilyHandle) { throw new UnsupportedOperationException("Can't encode this type"); } @Override - public @NotNull ColumnFamilyHandle deserialize(DataInput dataInput) { + public @NotNull ColumnFamilyHandle deserialize(SafeDataInput dataInput) { throw new UnsupportedOperationException("Can't encode this type"); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/CompressionSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/CompressionSerializer.java index 53a84aa..4bf1a0b 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/CompressionSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/CompressionSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.client.Compression; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.jetbrains.annotations.NotNull; public class CompressionSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull Compression compression) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Compression compression) { dataOutput.writeInt(compression.ordinal()); } @Override - public @NotNull Compression deserialize(DataInput dataInput) throws IOException { + public @NotNull Compression deserialize(SafeDataInput dataInput) { return Compression.values()[dataInput.readInt()]; } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/DurationSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/DurationSerializer.java index 742e357..04f5c7c 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/DurationSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/DurationSerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -11,7 +13,7 @@ import org.jetbrains.annotations.NotNull; public class DurationSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull Duration duration) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Duration duration) { var units = duration.getUnits(); var smallestUnit = (ChronoUnit) units.get(units.size() - 1); dataOutput.writeInt(smallestUnit.ordinal()); @@ -19,7 +21,7 @@ public class DurationSerializer implements DataSerializer { } @Override - public @NotNull Duration deserialize(DataInput dataInput) throws IOException { + public @NotNull Duration deserialize(SafeDataInput dataInput) { var smallestUnit = ChronoUnit.values()[dataInput.readInt()]; return Duration.of(dataInput.readLong(), smallestUnit); } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/LLSnapshotSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/LLSnapshotSerializer.java index 841c047..9e520ee 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/LLSnapshotSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/LLSnapshotSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.database.LLSnapshot; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.jetbrains.annotations.NotNull; public class LLSnapshotSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull LLSnapshot llSnapshot) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull LLSnapshot llSnapshot) { dataOutput.writeLong(llSnapshot.getSequenceNumber()); } @Override - public @NotNull LLSnapshot deserialize(DataInput dataInput) throws IOException { + public @NotNull LLSnapshot deserialize(SafeDataInput dataInput) { return new LLSnapshot(dataInput.readLong()); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/LuceneHacksSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/LuceneHacksSerializer.java index 3b3aef0..7f457e7 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/LuceneHacksSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/LuceneHacksSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.lucene.LuceneHacks; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,14 +12,14 @@ import org.jetbrains.annotations.NotNull; public class LuceneHacksSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull LuceneHacks luceneHacks) { + public void serialize(SafeDataOutput dataOutput, @NotNull LuceneHacks luceneHacks) { if (luceneHacks.customLocalSearcher() != null || luceneHacks.customMultiSearcher() != null) { throw new UnsupportedOperationException("Can't encode this type"); } } @Override - public @NotNull LuceneHacks deserialize(DataInput dataInput) { + public @NotNull LuceneHacks deserialize(SafeDataInput dataInput) { return new LuceneHacks(null, null); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/PathSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/PathSerializer.java index e9c57ff..e96be5d 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/PathSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/PathSerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.jetbrains.annotations.NotNull; public class PathSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull Path path) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Path path) { dataOutput.writeUTF(path.toString()); } @Override - public @NotNull Path deserialize(DataInput dataInput) throws IOException { + public @NotNull Path deserialize(SafeDataInput dataInput) { return Path.of(dataInput.readUTF()); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/RocksDBSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/RocksDBSerializer.java index 1fa220d..3d1a23a 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/RocksDBSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/RocksDBSerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.rocksdb.RocksDB; public class RocksDBSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull RocksDB rocksDB) { + public void serialize(SafeDataOutput dataOutput, @NotNull RocksDB rocksDB) { throw new UnsupportedOperationException("Can't encode this type"); } @Override - public @NotNull RocksDB deserialize(DataInput dataInput) { + public @NotNull RocksDB deserialize(SafeDataInput dataInput) { throw new UnsupportedOperationException("Can't encode this type"); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/String2ColumnFamilyHandleMapSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/String2ColumnFamilyHandleMapSerializer.java index e53faac..ff846d2 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/String2ColumnFamilyHandleMapSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/String2ColumnFamilyHandleMapSerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -11,13 +13,12 @@ import org.rocksdb.ColumnFamilyHandle; public class String2ColumnFamilyHandleMapSerializer implements DataSerializer> { @Override - public void serialize(DataOutput dataOutput, @NotNull Map stringColumnFamilyHandleMap) - throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Map stringColumnFamilyHandleMap) { throw new UnsupportedOperationException("Can't encode this type"); } @Override - public @NotNull Map deserialize(DataInput dataInput) { + public @NotNull Map deserialize(SafeDataInput dataInput) { throw new UnsupportedOperationException("Can't encode this type"); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/String2FieldAnalyzerMapSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/String2FieldAnalyzerMapSerializer.java index b9afa01..53693c6 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/String2FieldAnalyzerMapSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/String2FieldAnalyzerMapSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -16,8 +18,7 @@ public class String2FieldAnalyzerMapSerializer implements DataSerializer stringTextFieldsAnalyzerMap) - throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Map stringTextFieldsAnalyzerMap) { dataOutput.writeInt(stringTextFieldsAnalyzerMap.size()); for (Entry entry : stringTextFieldsAnalyzerMap.entrySet()) { dataOutput.writeUTF(entry.getKey()); @@ -26,7 +27,7 @@ public class String2FieldAnalyzerMapSerializer implements DataSerializer deserialize(DataInput dataInput) throws IOException { + public @NotNull Map deserialize(SafeDataInput dataInput) { var size = dataInput.readInt(); var result = new HashMap(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/it/cavallium/dbengine/database/remote/String2FieldSimilarityMapSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/String2FieldSimilarityMapSerializer.java index 0d40f98..be15bab 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/String2FieldSimilarityMapSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/String2FieldSimilarityMapSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -16,8 +18,7 @@ public class String2FieldSimilarityMapSerializer implements DataSerializer stringTextFieldsSimilarityMap) - throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Map stringTextFieldsSimilarityMap) { dataOutput.writeInt(stringTextFieldsSimilarityMap.size()); for (Entry entry : stringTextFieldsSimilarityMap.entrySet()) { dataOutput.writeUTF(entry.getKey()); @@ -26,7 +27,7 @@ public class String2FieldSimilarityMapSerializer implements DataSerializer deserialize(DataInput dataInput) throws IOException { + public @NotNull Map deserialize(SafeDataInput dataInput) { var size = dataInput.readInt(); var result = new HashMap(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/it/cavallium/dbengine/database/remote/StringEntrySerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/StringEntrySerializer.java index b8aa3d6..46ef7af 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/StringEntrySerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/StringEntrySerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -11,13 +13,13 @@ import org.jetbrains.annotations.NotNull; public class StringEntrySerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull Map.Entry entry) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Map.Entry entry) { dataOutput.writeUTF((String) entry.getKey()); dataOutput.writeUTF((String) entry.getValue()); } @Override - public @NotNull Map.Entry deserialize(DataInput dataInput) throws IOException { + public @NotNull Map.Entry deserialize(SafeDataInput dataInput) { return Map.entry(dataInput.readUTF(), dataInput.readUTF()); } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/StringMapSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/StringMapSerializer.java index 51f420b..6071e1c 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/StringMapSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/StringMapSerializer.java @@ -1,6 +1,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -13,8 +15,7 @@ import org.jetbrains.annotations.NotNull; public class StringMapSerializer implements DataSerializer> { @Override - public void serialize(DataOutput dataOutput, @NotNull Map stringTextFieldsAnalyzerMap) - throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull Map stringTextFieldsAnalyzerMap) { dataOutput.writeInt(stringTextFieldsAnalyzerMap.size()); for (Entry entry : stringTextFieldsAnalyzerMap.entrySet()) { dataOutput.writeUTF(entry.getKey()); @@ -23,7 +24,7 @@ public class StringMapSerializer implements DataSerializer> } @Override - public @NotNull Map deserialize(DataInput dataInput) throws IOException { + public @NotNull Map deserialize(SafeDataInput dataInput) { var size = dataInput.readInt(); var result = new HashMap(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsAnalyzerSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsAnalyzerSerializer.java index e564395..1a3026f 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsAnalyzerSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsAnalyzerSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.jetbrains.annotations.NotNull; public class TextFieldsAnalyzerSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull TextFieldsAnalyzer textFieldsAnalyzer) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull TextFieldsAnalyzer textFieldsAnalyzer) { dataOutput.writeInt(textFieldsAnalyzer.ordinal()); } @Override - public @NotNull TextFieldsAnalyzer deserialize(DataInput dataInput) throws IOException { + public @NotNull TextFieldsAnalyzer deserialize(SafeDataInput dataInput) { return TextFieldsAnalyzer.values()[dataInput.readInt()]; } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsSimilaritySerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsSimilaritySerializer.java index cf3ee48..a5751a5 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsSimilaritySerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/TextFieldsSimilaritySerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.jetbrains.annotations.NotNull; public class TextFieldsSimilaritySerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull TextFieldsSimilarity textFieldsSimilarity) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull TextFieldsSimilarity textFieldsSimilarity) { dataOutput.writeInt(textFieldsSimilarity.ordinal()); } @Override - public @NotNull TextFieldsSimilarity deserialize(DataInput dataInput) throws IOException { + public @NotNull TextFieldsSimilarity deserialize(SafeDataInput dataInput) { return TextFieldsSimilarity.values()[dataInput.readInt()]; } } diff --git a/src/main/java/it/cavallium/dbengine/database/remote/UpdateReturnModeSerializer.java b/src/main/java/it/cavallium/dbengine/database/remote/UpdateReturnModeSerializer.java index dc70f02..0590fc3 100644 --- a/src/main/java/it/cavallium/dbengine/database/remote/UpdateReturnModeSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/remote/UpdateReturnModeSerializer.java @@ -2,6 +2,8 @@ package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.database.UpdateReturnMode; +import it.cavallium.stream.SafeDataInput; +import it.cavallium.stream.SafeDataOutput; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -10,12 +12,12 @@ import org.jetbrains.annotations.NotNull; public class UpdateReturnModeSerializer implements DataSerializer { @Override - public void serialize(DataOutput dataOutput, @NotNull UpdateReturnMode updateReturnMode) throws IOException { + public void serialize(SafeDataOutput dataOutput, @NotNull UpdateReturnMode updateReturnMode) { dataOutput.writeInt(updateReturnMode.ordinal()); } @Override - public @NotNull UpdateReturnMode deserialize(DataInput dataInput) throws IOException { + public @NotNull UpdateReturnMode deserialize(SafeDataInput dataInput) { return UpdateReturnMode.values()[dataInput.readInt()]; } } diff --git a/src/main/java/it/cavallium/dbengine/database/serialization/Codec.java b/src/main/java/it/cavallium/dbengine/database/serialization/Codec.java index bc1521d..82a8b8c 100644 --- a/src/main/java/it/cavallium/dbengine/database/serialization/Codec.java +++ b/src/main/java/it/cavallium/dbengine/database/serialization/Codec.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.serialization; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import java.io.IOException; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java b/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java index fbc0e0b..50e69eb 100644 --- a/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java @@ -1,7 +1,7 @@ package it.cavallium.dbengine.database.serialization; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import java.io.IOError; import java.io.IOException; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/it/cavallium/dbengine/database/serialization/Serializer.java b/src/main/java/it/cavallium/dbengine/database/serialization/Serializer.java index c8dd9d5..a7f6190 100644 --- a/src/main/java/it/cavallium/dbengine/database/serialization/Serializer.java +++ b/src/main/java/it/cavallium/dbengine/database/serialization/Serializer.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.serialization; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import java.nio.charset.StandardCharsets; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/it/cavallium/dbengine/database/serialization/SerializerFixedBinaryLength.java b/src/main/java/it/cavallium/dbengine/database/serialization/SerializerFixedBinaryLength.java index e9fbde6..2e80b8c 100644 --- a/src/main/java/it/cavallium/dbengine/database/serialization/SerializerFixedBinaryLength.java +++ b/src/main/java/it/cavallium/dbengine/database/serialization/SerializerFixedBinaryLength.java @@ -1,8 +1,8 @@ package it.cavallium.dbengine.database.serialization; -import it.cavallium.dbengine.buffers.Buf; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.Buf; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import java.nio.charset.StandardCharsets; import java.util.Objects; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/it/cavallium/dbengine/utils/ByteListJsonAdapter.java b/src/main/java/it/cavallium/dbengine/utils/ByteListJsonAdapter.java index 8db5487..d65e97c 100644 --- a/src/main/java/it/cavallium/dbengine/utils/ByteListJsonAdapter.java +++ b/src/main/java/it/cavallium/dbengine/utils/ByteListJsonAdapter.java @@ -3,7 +3,7 @@ package it.cavallium.dbengine.utils; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.JsonReader; import com.squareup.moshi.JsonWriter; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import java.io.IOException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index bf24a73..513e5a9 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,4 @@ module dbengine { - exports org.warp.commonutils.stream; exports it.cavallium.dbengine.lucene; exports it.cavallium.dbengine.database; exports it.cavallium.dbengine.rpc.current.data; @@ -18,7 +17,6 @@ module dbengine { opens it.cavallium.dbengine.database.remote; exports it.cavallium.dbengine.utils; exports it.cavallium.dbengine.database.disk.rocksdb; - exports it.cavallium.dbengine.buffers; exports it.cavallium.dbengine.lucene.hugepq.search; requires org.jetbrains.annotations; requires com.google.common; diff --git a/src/main/java/org/warp/commonutils/stream/ByteBufferBackedInputStream.java b/src/main/java/org/warp/commonutils/stream/ByteBufferBackedInputStream.java deleted file mode 100644 index 3efa9ae..0000000 --- a/src/main/java/org/warp/commonutils/stream/ByteBufferBackedInputStream.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.warp.commonutils.stream; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import org.jetbrains.annotations.NotNull; - -/** - * Simple {@link InputStream} implementation that exposes currently - * available content of a {@link ByteBuffer}. - */ -public class ByteBufferBackedInputStream extends InputStream { - protected final ByteBuffer _b; - - public ByteBufferBackedInputStream(ByteBuffer buf) { _b = buf; } - - @Override public int available() { return _b.remaining(); } - - @Override - public int read() { return _b.hasRemaining() ? (_b.get() & 0xFF) : -1; } - - @Override - public int read(byte @NotNull [] bytes, int off, int len) { - if (!_b.hasRemaining()) return -1; - len = Math.min(len, _b.remaining()); - _b.get(bytes, off, len); - return len; - } -} \ No newline at end of file diff --git a/src/main/java/org/warp/commonutils/stream/DataInputOutput.java b/src/main/java/org/warp/commonutils/stream/DataInputOutput.java deleted file mode 100644 index 7435511..0000000 --- a/src/main/java/org/warp/commonutils/stream/DataInputOutput.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.warp.commonutils.stream; - -import java.io.DataInput; -import java.io.DataOutput; - -public interface DataInputOutput extends DataInput, DataOutput { - - DataInput getIn(); - - DataOutput getOut(); -} diff --git a/src/main/java/org/warp/commonutils/stream/DataInputOutputImpl.java b/src/main/java/org/warp/commonutils/stream/DataInputOutputImpl.java deleted file mode 100644 index 9acf2fe..0000000 --- a/src/main/java/org/warp/commonutils/stream/DataInputOutputImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.warp.commonutils.stream; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import org.jetbrains.annotations.NotNull; - -public class DataInputOutputImpl implements DataInputOutput { - - private final DataInput in; - private final DataOutput out; - - public DataInputOutputImpl(DataInput in, DataOutput out) { - this.in = in; - this.out = out; - } - - @Override - public DataInput getIn() { - return this; - } - - @Override - public DataOutput getOut() { - return this; - } - - @Override - public void readFully(byte @NotNull [] bytes) throws IOException { - in.readFully(bytes); - } - - @Override - public void readFully(byte @NotNull [] bytes, int i, int i1) throws IOException { - in.readFully(bytes, i, i1); - } - - @Override - public int skipBytes(int i) throws IOException { - return in.skipBytes(i); - } - - @Override - public boolean readBoolean() throws IOException { - return in.readBoolean(); - } - - @Override - public byte readByte() throws IOException { - return in.readByte(); - } - - @Override - public int readUnsignedByte() throws IOException { - return in.readUnsignedByte(); - } - - @Override - public short readShort() throws IOException { - return in.readShort(); - } - - @Override - public int readUnsignedShort() throws IOException { - return in.readUnsignedShort(); - } - - @Override - public char readChar() throws IOException { - return in.readChar(); - } - - @Override - public int readInt() throws IOException { - return in.readInt(); - } - - @Override - public long readLong() throws IOException { - return in.readLong(); - } - - @Override - public float readFloat() throws IOException { - return in.readFloat(); - } - - @Override - public double readDouble() throws IOException { - return in.readDouble(); - } - - @Override - public String readLine() throws IOException { - return in.readLine(); - } - - @NotNull - @Override - public String readUTF() throws IOException { - return in.readUTF(); - } - - @Override - public void write(int i) throws IOException { - out.write(i); - } - - @Override - public void write(byte @NotNull [] bytes) throws IOException { - out.write(bytes); - } - - @Override - public void write(byte @NotNull [] bytes, int i, int i1) throws IOException { - out.write(bytes, i, i1); - } - - @Override - public void writeBoolean(boolean b) throws IOException { - out.writeBoolean(b); - } - - @Override - public void writeByte(int i) throws IOException { - out.writeByte(i); - } - - @Override - public void writeShort(int i) throws IOException { - out.writeShort(i); - } - - @Override - public void writeChar(int i) throws IOException { - out.writeChar(i); - } - - @Override - public void writeInt(int i) throws IOException { - out.writeInt(i); - } - - @Override - public void writeLong(long l) throws IOException { - out.writeLong(l); - } - - @Override - public void writeFloat(float v) throws IOException { - out.writeFloat(v); - } - - @Override - public void writeDouble(double v) throws IOException { - out.writeDouble(v); - } - - @Override - public void writeBytes(@NotNull String s) throws IOException { - out.writeBytes(s); - } - - @Override - public void writeChars(@NotNull String s) throws IOException { - out.writeChars(s); - } - - @Override - public void writeUTF(@NotNull String s) throws IOException { - out.writeUTF(s); - } -} diff --git a/src/main/java/org/warp/commonutils/stream/DataInputOutputStream.java b/src/main/java/org/warp/commonutils/stream/DataInputOutputStream.java deleted file mode 100644 index 16a1a3a..0000000 --- a/src/main/java/org/warp/commonutils/stream/DataInputOutputStream.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.warp.commonutils.stream; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import org.jetbrains.annotations.NotNull; - -public class DataInputOutputStream extends DataOutputStream implements DataInputOutput { - - private final DataInputStream in; - - public DataInputOutputStream(DataInputStream in, DataOutputStream out) { - super(out); - this.in = in; - } - - @Override - public DataInputStream getIn() { - return in; - } - - @Override - public DataOutputStream getOut() { - return this; - } - - @Override - public void readFully(byte @NotNull [] bytes) throws IOException { - in.readFully(bytes); - } - - @Override - public void readFully(byte @NotNull [] bytes, int i, int i1) throws IOException { - in.readFully(bytes, i, i1); - } - - @Override - public int skipBytes(int i) throws IOException { - return in.skipBytes(i); - } - - @Override - public boolean readBoolean() throws IOException { - return in.readBoolean(); - } - - @Override - public byte readByte() throws IOException { - return in.readByte(); - } - - @Override - public int readUnsignedByte() throws IOException { - return in.readUnsignedByte(); - } - - @Override - public short readShort() throws IOException { - return in.readShort(); - } - - @Override - public int readUnsignedShort() throws IOException { - return in.readUnsignedShort(); - } - - @Override - public char readChar() throws IOException { - return in.readChar(); - } - - @Override - public int readInt() throws IOException { - return in.readInt(); - } - - @Override - public long readLong() throws IOException { - return in.readLong(); - } - - @Override - public float readFloat() throws IOException { - return in.readFloat(); - } - - @Override - public double readDouble() throws IOException { - return in.readDouble(); - } - - @Deprecated - @Override - public String readLine() throws IOException { - return in.readLine(); - } - - @NotNull - @Override - public String readUTF() throws IOException { - return in.readUTF(); - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeByteArrayInputStream.java b/src/main/java/org/warp/commonutils/stream/SafeByteArrayInputStream.java deleted file mode 100644 index b2975dd..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeByteArrayInputStream.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2005-2022 Sebastiano Vigna - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.warp.commonutils.stream; - -/** Simple, fast and repositionable byte-array input stream. - * - *

Warning: this class implements the correct semantics - * of {@link #read(byte[], int, int)} as described in {@link java.io.InputStream}. - * The implementation given in {@link java.io.ByteArrayInputStream} is broken, - * but it will never be fixed because it's too late. - * - * @author Sebastiano Vigna - */ - -public class SafeByteArrayInputStream extends SafeMeasurableInputStream implements SafeRepositionableStream { - - /** The array backing the input stream. */ - public byte[] array; - - /** The first valid entry. */ - public int offset; - - /** The number of valid bytes in {@link #array} starting from {@link #offset}. */ - public int length; - - /** The current position as a distance from {@link #offset}. */ - private int position; - - /** The current mark as a position, or -1 if no mark exists. */ - private int mark; - - /** Creates a new array input stream using a given array fragment. - * - * @param array the backing array. - * @param offset the first valid entry of the array. - * @param length the number of valid bytes. - */ - public SafeByteArrayInputStream(final byte[] array, final int offset, final int length) { - this.array = array; - this.offset = offset; - this.length = length; - } - - /** Creates a new array input stream using a given array. - * - * @param array the backing array. - */ - public SafeByteArrayInputStream(final byte[] array) { - this(array, 0, array.length); - } - - @Override - public boolean markSupported() { - return true; - } - - @Override - public void reset() { - position = mark; - } - - /** Closing a fast byte array input stream has no effect. */ - @Override - public void close() {} - - @Override - public void mark(final int dummy) { - mark = position; - } - - @Override - public int available() { - return length - position; - } - - @Override - public long skip(long n) { - if (n <= length - position) { - position += (int)n; - return n; - } - n = length - position; - position = length; - return n; - } - - @Override - public int read() { - if (length == position) return -1; - return array[offset + position++] & 0xFF; - } - - /** Reads bytes from this byte-array input stream as - * specified in {@link java.io.InputStream#read(byte[], int, int)}. - * Note that the implementation given in {@link java.io.ByteArrayInputStream#read(byte[], int, int)} - * will return -1 on a zero-length read at EOF, contrarily to the specification. We won't. - */ - - @Override - public int read(final byte b[], final int offset, final int length) { - if (this.length == this.position) return length == 0 ? 0 : -1; - final int n = Math.min(length, this.length - this.position); - System.arraycopy(array, this.offset + this.position, b, offset, n); - this.position += n; - return n; - } - - @Override - public long position() { - return position; - } - - @Override - public void position(final long newPosition) { - position = (int)Math.min(newPosition, length); - } - - @Override - public long length() { - return length; - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeByteArrayOutputStream.java b/src/main/java/org/warp/commonutils/stream/SafeByteArrayOutputStream.java deleted file mode 100644 index 760f709..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeByteArrayOutputStream.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2005-2022 Sebastiano Vigna - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.warp.commonutils.stream; - -import it.unimi.dsi.fastutil.Arrays; -import it.unimi.dsi.fastutil.bytes.ByteArrays; - -/** Simple, fast byte-array output stream that exposes the backing array. - * - *

{@link java.io.ByteArrayOutputStream} is nice, but to get its content you - * must generate each time a new object. This doesn't happen here. - * - *

This class will automatically enlarge the backing array, doubling its - * size whenever new space is needed. The {@link #reset()} method will - * mark the content as empty, but will not decrease the capacity: use - * {@link #trim()} for that purpose. - * - * @author Sebastiano Vigna - */ - -public class SafeByteArrayOutputStream extends SafeMeasurableOutputStream implements SafeRepositionableStream { - - /** The array backing the output stream. */ - public static final int DEFAULT_INITIAL_CAPACITY = 16; - private final boolean wrapped; - private final int initialPosition; - private final int initialLength; - - /** The array backing the output stream. */ - public byte[] array; - - /** The number of valid bytes in {@link #array}. */ - public int length; - - /** The current writing position. */ - private int position; - - /** Creates a new array output stream with an initial capacity of {@link #DEFAULT_INITIAL_CAPACITY} bytes. */ - public SafeByteArrayOutputStream() { - this(DEFAULT_INITIAL_CAPACITY); - } - - /** Creates a new array output stream with a given initial capacity. - * - * @param initialCapacity the initial length of the backing array. - */ - public SafeByteArrayOutputStream(final int initialCapacity) { - array = new byte[initialCapacity]; - wrapped = false; - initialPosition = 0; - initialLength = 0; - } - - /** Creates a new array output stream wrapping a given byte array. - * - * @param a the byte array to wrap. - */ - public SafeByteArrayOutputStream(final byte[] a) { - array = a; - wrapped = true; - initialPosition = 0; - initialLength = a.length; - } - - /** Creates a new array output stream wrapping a given byte array. - * - * @param a the byte array to wrap. - */ - public SafeByteArrayOutputStream(final byte[] a, int from, int to) { - Arrays.ensureFromTo(a.length, from, to); - wrapped = true; - array = a; - initialPosition = from; - initialLength = to; - position = from; - length = to - from; - } - - /** Marks this array output stream as empty. */ - public void reset() { - length = initialLength; - position = initialPosition; - } - - /** Ensures that the length of the backing array is equal to {@link #length}. */ - public void trim() { - if (!wrapped) { - array = ByteArrays.trim(array, length); - } - } - - public void ensureWritable(int size) { - growBy(size); - } - - @Override - public void write(final int b) { - if (position >= array.length) { - if (wrapped) { - throw new ArrayIndexOutOfBoundsException(position); - } else { - array = ByteArrays.grow(array, position + 1, length); - } - } - array[position++] = (byte)b; - if (length < position) length = position; - } - - @Override - public void write(final byte[] b, final int off, final int len) { - ByteArrays.ensureOffsetLength(b, off, len); - growBy(len); - System.arraycopy(b, off, array, position, len); - if (position + len > length) length = position += len; - } - - private void growBy(int len) { - if (position + len > array.length) { - if (wrapped) { - throw new ArrayIndexOutOfBoundsException(position + len - 1); - } else { - array = ByteArrays.grow(array, position + len, position); - } - } - } - - @Override - public void position(final long newPosition) { - position = (int)newPosition; - } - - @Override - public long position() { - return position; - } - - @Override - public long length() { - return length; - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeDataInputStream.java b/src/main/java/org/warp/commonutils/stream/SafeDataInputStream.java deleted file mode 100644 index c5bd5e2..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeDataInputStream.java +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ - -package org.warp.commonutils.stream; - -import java.io.DataInput; -import org.jetbrains.annotations.NotNull; - -/** - * A data input stream lets an application read primitive Java data - * types from an underlying input stream in a machine-independent - * way. An application uses a data output stream to write data that - * can later be read by a data input stream. - *

- * DataInputStream is not necessarily safe for multithreaded access. - * Thread safety is optional and is the responsibility of users of - * methods in this class. - * - * @author Arthur van Hoff - * @see java.io.DataOutputStream - * @since 1.0 - */ -public class SafeDataInputStream extends SafeFilterInputStream implements DataInput { - - /** - * Creates a DataInputStream that uses the specified - * underlying InputStream. - * - * @param in the specified input stream - */ - public SafeDataInputStream(SafeInputStream in) { - super(in); - } - - /** - * working arrays initialized on demand by readUTF - */ - private byte[] bytearr = new byte[80]; - private char[] chararr = new char[80]; - - /** - * Reads some number of bytes from the contained input stream and - * stores them into the buffer array {@code b}. The number of - * bytes actually read is returned as an integer. This method blocks - * until input data is available, end of file is detected, or an - * exception is thrown. - * - *

If {@code b} is null, a {@code NullPointerException} is - * thrown. If the length of {@code b} is zero, then no bytes are - * read and {@code 0} is returned; otherwise, there is an attempt - * to read at least one byte. If no byte is available because the - * stream is at end of file, the value {@code -1} is returned; - * otherwise, at least one byte is read and stored into {@code b}. - * - *

The first byte read is stored into element {@code b[0]}, the - * next one into {@code b[1]}, and so on. The number of bytes read - * is, at most, equal to the length of {@code b}. Let {@code k} - * be the number of bytes actually read; these bytes will be stored in - * elements {@code b[0]} through {@code b[k-1]}, leaving - * elements {@code b[k]} through {@code b[b.length-1]} - * unaffected. - * - *

The {@code read(b)} method has the same effect as: - *

-	 * read(b, 0, b.length)
-	 * 
- * - * @param b the buffer into which the data is read. - * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end - * of the stream has been reached. - * @see SafeFilterInputStream#in - * @see java.io.InputStream#read(byte[], int, int) - */ - public final int read(byte[] b) { - return in.read(b, 0, b.length); - } - - /** - * Reads up to {@code len} bytes of data from the contained - * input stream into an array of bytes. An attempt is made to read - * as many as {@code len} bytes, but a smaller number may be read, - * possibly zero. The number of bytes actually read is returned as an - * integer. - * - *

This method blocks until input data is available, end of file is - * detected, or an exception is thrown. - * - *

If {@code len} is zero, then no bytes are read and - * {@code 0} is returned; otherwise, there is an attempt to read at - * least one byte. If no byte is available because the stream is at end of - * file, the value {@code -1} is returned; otherwise, at least one - * byte is read and stored into {@code b}. - * - *

The first byte read is stored into element {@code b[off]}, the - * next one into {@code b[off+1]}, and so on. The number of bytes read - * is, at most, equal to {@code len}. Let k be the number of - * bytes actually read; these bytes will be stored in elements - * {@code b[off]} through {@code b[off+}k{@code -1]}, - * leaving elements {@code b[off+}k{@code ]} through - * {@code b[off+len-1]} unaffected. - * - *

In every case, elements {@code b[0]} through - * {@code b[off]} and elements {@code b[off+len]} through - * {@code b[b.length-1]} are unaffected. - * - * @param b the buffer into which the data is read. - * @param off the start offset in the destination array {@code b} - * @param len the maximum number of bytes read. - * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end - * of the stream has been reached. - * @throws NullPointerException If {@code b} is {@code null}. - * @throws IndexOutOfBoundsException If {@code off} is negative, - * {@code len} is negative, or {@code len} is greater than - * {@code b.length - off} - * @see SafeFilterInputStream#in - * @see java.io.InputStream#read(byte[], int, int) - */ - public final int read(byte[] b, int off, int len) { - return in.read(b, off, len); - } - - /** - * See the general contract of the {@code readFully} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @param b the buffer into which the data is read. - * @throws NullPointerException if {@code b} is {@code null}. - * @see SafeFilterInputStream#in - */ - public final void readFully(byte @NotNull [] b) { - readFully(b, 0, b.length); - } - - /** - * See the general contract of the {@code readFully} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @param b the buffer into which the data is read. - * @param off the start offset in the data array {@code b}. - * @param len the number of bytes to read. - * @throws NullPointerException if {@code b} is {@code null}. - * @throws IndexOutOfBoundsException if {@code off} is negative, - * {@code len} is negative, or {@code len} is greater than - * {@code b.length - off}. - * @see SafeFilterInputStream#in - */ - public final void readFully(byte @NotNull [] b, int off, int len) { - if (len < 0) - throw new IndexOutOfBoundsException(); - int n = 0; - while (n < len) { - int count = in.read(b, off + n, len - n); - if (count < 0) - throw new IndexOutOfBoundsException(); - n += count; - } - } - - /** - * See the general contract of the {@code skipBytes} - * method of {@code DataInput}. - *

- * Bytes for this operation are read from the contained - * input stream. - * - * @param n the number of bytes to be skipped. - * @return the actual number of bytes skipped. - */ - public final int skipBytes(int n) { - int total = 0; - int cur; - - while ((total 0)) { - total += cur; - } - - return total; - } - - /** - * See the general contract of the {@code readBoolean} - * method of {@code DataInput}. - *

- * Bytes for this operation are read from the contained - * input stream. - * - * @return the {@code boolean} value read. - * @see SafeFilterInputStream#in - */ - public final boolean readBoolean() { - int ch = in.read(); - if (ch < 0) - throw new IndexOutOfBoundsException(); - return (ch != 0); - } - - /** - * See the general contract of the {@code readByte} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next byte of this input stream as a signed 8-bit - * {@code byte}. - * @see SafeFilterInputStream#in - */ - public final byte readByte() { - int ch = in.read(); - if (ch < 0) - throw new IndexOutOfBoundsException(); - return (byte)(ch); - } - - /** - * See the general contract of the {@code readUnsignedByte} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next byte of this input stream, interpreted as an - * unsigned 8-bit number. - * @see SafeFilterInputStream#in - */ - public final int readUnsignedByte() { - int ch = in.read(); - if (ch < 0) - throw new IndexOutOfBoundsException(); - return ch; - } - - /** - * See the general contract of the {@code readShort} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next two bytes of this input stream, interpreted as a - * signed 16-bit number. - * @see SafeFilterInputStream#in - */ - public final short readShort() { - int ch1 = in.read(); - int ch2 = in.read(); - if ((ch1 | ch2) < 0) - throw new IndexOutOfBoundsException(); - return (short)((ch1 << 8) + (ch2 << 0)); - } - - /** - * See the general contract of the {@code readUnsignedShort} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next two bytes of this input stream, interpreted as an - * unsigned 16-bit integer. - * @see SafeFilterInputStream#in - */ - public final int readUnsignedShort() { - int ch1 = in.read(); - int ch2 = in.read(); - if ((ch1 | ch2) < 0) - throw new IndexOutOfBoundsException(); - return (ch1 << 8) + (ch2 << 0); - } - - /** - * See the general contract of the {@code readChar} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next two bytes of this input stream, interpreted as a - * {@code char}. - * @see SafeFilterInputStream#in - */ - public final char readChar() { - int ch1 = in.read(); - int ch2 = in.read(); - if ((ch1 | ch2) < 0) - throw new IndexOutOfBoundsException(); - return (char)((ch1 << 8) + (ch2 << 0)); - } - - /** - * See the general contract of the {@code readInt} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next four bytes of this input stream, interpreted as an - * {@code int}. - * @see SafeFilterInputStream#in - */ - public final int readInt() { - int ch1 = in.read(); - int ch2 = in.read(); - int ch3 = in.read(); - int ch4 = in.read(); - if ((ch1 | ch2 | ch3 | ch4) < 0) - throw new IndexOutOfBoundsException(); - return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)); - } - - private final byte[] readBuffer = new byte[8]; - - /** - * See the general contract of the {@code readLong} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next eight bytes of this input stream, interpreted as a - * {@code long}. - * @see SafeFilterInputStream#in - */ - public final long readLong() { - readFully(readBuffer, 0, 8); - return (((long)readBuffer[0] << 56) + - ((long)(readBuffer[1] & 255) << 48) + - ((long)(readBuffer[2] & 255) << 40) + - ((long)(readBuffer[3] & 255) << 32) + - ((long)(readBuffer[4] & 255) << 24) + - ((readBuffer[5] & 255) << 16) + - ((readBuffer[6] & 255) << 8) + - ((readBuffer[7] & 255) << 0)); - } - - /** - * See the general contract of the {@code readFloat} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next four bytes of this input stream, interpreted as a - * {@code float}. - * @see SafeDataInputStream#readInt() - * @see Float#intBitsToFloat(int) - */ - public final float readFloat() { - return Float.intBitsToFloat(readInt()); - } - - /** - * See the general contract of the {@code readDouble} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return the next eight bytes of this input stream, interpreted as a - * {@code double}. - * @see SafeDataInputStream#readLong() - * @see Double#longBitsToDouble(long) - */ - public final double readDouble() { - return Double.longBitsToDouble(readLong()); - } - - private char[] lineBuffer; - - /** - * See the general contract of the {@code readLine} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @deprecated This method does not properly convert bytes to characters. - * As of JDK 1.1, the preferred way to read lines of text is via the - * {@code BufferedReader.readLine()} method. Programs that use the - * {@code DataInputStream} class to read lines can be converted to use - * the {@code BufferedReader} class by replacing code of the form: - *

-	 *     DataInputStream d = new DataInputStream(in);
-	 * 
- * with: - *
-	 *     BufferedReader d
-	 *          = new BufferedReader(new InputStreamReader(in));
-	 * 
- * - * @return the next line of text from this input stream. - * @see java.io.BufferedReader#readLine() - * @see SafeFilterInputStream#in - */ - @Deprecated - public final String readLine() { - char[] buf = lineBuffer; - - if (buf == null) { - buf = lineBuffer = new char[128]; - } - - int room = buf.length; - int offset = 0; - int c; - - loop: while (true) { - switch (c = in.read()) { - case -1: - case '\n': - break loop; - - case '\r': - int c2 = in.read(); - if ((c2 != '\n') && (c2 != -1)) { - if (!(in instanceof SafePushbackInputStream)) { - this.in = new SafePushbackInputStream(in); - } - ((SafePushbackInputStream)in).unread(c2); - } - break loop; - - default: - if (--room < 0) { - buf = new char[offset + 128]; - room = buf.length - offset - 1; - System.arraycopy(lineBuffer, 0, buf, 0, offset); - lineBuffer = buf; - } - buf[offset++] = (char) c; - break; - } - } - if ((c == -1) && (offset == 0)) { - return null; - } - return String.copyValueOf(buf, 0, offset); - } - - /** - * See the general contract of the {@code readUTF} - * method of {@code DataInput}. - *

- * Bytes - * for this operation are read from the contained - * input stream. - * - * @return a Unicode string. - * @see SafeDataInputStream#readUTF(SafeDataInputStream) - */ - public final @NotNull String readUTF() { - return readUTF(this); - } - - /** - * Reads from the - * stream {@code in} a representation - * of a Unicode character string encoded in - * modified UTF-8 format; - * this string of characters is then returned as a {@code String}. - * The details of the modified UTF-8 representation - * are exactly the same as for the {@code readUTF} - * method of {@code DataInput}. - * - * @param in a data input stream. - * @return a Unicode string. - * @see SafeDataInputStream#readUnsignedShort() - */ - public static String readUTF(SafeDataInputStream in) { - int utflen = in.readUnsignedShort(); - byte[] bytearr; - char[] chararr; - if (in.bytearr.length < utflen){ - in.bytearr = new byte[utflen*2]; - in.chararr = new char[utflen*2]; - } - chararr = in.chararr; - bytearr = in.bytearr; - - int c, char2, char3; - int count = 0; - int chararr_count=0; - - in.readFully(bytearr, 0, utflen); - - while (count < utflen) { - c = (int) bytearr[count] & 0xff; - if (c > 127) break; - count++; - chararr[chararr_count++]=(char)c; - } - - while (count < utflen) { - c = (int) bytearr[count] & 0xff; - switch (c >> 4) { - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: - /* 0xxxxxxx*/ - count++; - chararr[chararr_count++]=(char)c; - break; - case 12: case 13: - /* 110x xxxx 10xx xxxx*/ - count += 2; - if (count > utflen) - throw new IllegalArgumentException( - "malformed input: partial character at end"); - char2 = bytearr[count-1]; - if ((char2 & 0xC0) != 0x80) - throw new IllegalArgumentException( - "malformed input around byte " + count); - chararr[chararr_count++]=(char)(((c & 0x1F) << 6) | - (char2 & 0x3F)); - break; - case 14: - /* 1110 xxxx 10xx xxxx 10xx xxxx */ - count += 3; - if (count > utflen) - throw new IllegalArgumentException( - "malformed input: partial character at end"); - char2 = bytearr[count-2]; - char3 = bytearr[count-1]; - if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) - throw new IllegalArgumentException( - "malformed input around byte " + (count-1)); - chararr[chararr_count++]=(char)(((c & 0x0F) << 12) | - ((char2 & 0x3F) << 6) | - ((char3 & 0x3F) << 0)); - break; - default: - /* 10xx xxxx, 1111 xxxx */ - throw new IllegalArgumentException( - "malformed input around byte " + count); - } - } - // The number of chars produced may be less than utflen - return new String(chararr, 0, chararr_count); - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeDataOutput.java b/src/main/java/org/warp/commonutils/stream/SafeDataOutput.java deleted file mode 100644 index a48aa34..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeDataOutput.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved. - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ - -package org.warp.commonutils.stream; - -/** - * The {@code SafeDataOutput} interface provides - * for converting data from any of the Java - * primitive types to a series of bytes and - * writing these bytes to a binary stream. - * There is also a facility for converting - * a {@code String} into - * modified UTF-8 - * format and writing the resulting series - * of bytes. - *

- * For all the methods in this interface that - * write bytes, it is generally true that if - * a byte cannot be written for any reason, - * an {@code IOException} is thrown. - * - * @author Frank Yellin - * @see java.io.DataInput - * @see java.io.DataOutputStream - * @since 1.0 - */ -public interface SafeDataOutput { - /** - * Writes to the output stream the eight - * low-order bits of the argument {@code b}. - * The 24 high-order bits of {@code b} - * are ignored. - * - * @param b the byte to be written. - */ - void write(int b); - - /** - * Writes to the output stream all the bytes in array {@code b}. - * If {@code b} is {@code null}, - * a {@code NullPointerException} is thrown. - * If {@code b.length} is zero, then - * no bytes are written. Otherwise, the byte - * {@code b[0]} is written first, then - * {@code b[1]}, and so on; the last byte - * written is {@code b[b.length-1]}. - * - * @param b the data. - */ - void write(byte b[]); - - /** - * Writes {@code len} bytes from array - * {@code b}, in order, to - * the output stream. If {@code b} - * is {@code null}, a {@code NullPointerException} - * is thrown. If {@code off} is negative, - * or {@code len} is negative, or {@code off+len} - * is greater than the length of the array - * {@code b}, then an {@code IndexOutOfBoundsException} - * is thrown. If {@code len} is zero, - * then no bytes are written. Otherwise, the - * byte {@code b[off]} is written first, - * then {@code b[off+1]}, and so on; the - * last byte written is {@code b[off+len-1]}. - * - * @param b the data. - * @param off the start offset in the data. - * @param len the number of bytes to write. - */ - void write(byte b[], int off, int len); - - /** - * Writes a {@code boolean} value to this output stream. - * If the argument {@code v} - * is {@code true}, the value {@code (byte)1} - * is written; if {@code v} is {@code false}, - * the value {@code (byte)0} is written. - * The byte written by this method may - * be read by the {@code readBoolean} - * method of interface {@code DataInput}, - * which will then return a {@code boolean} - * equal to {@code v}. - * - * @param v the boolean to be written. - */ - void writeBoolean(boolean v); - - /** - * Writes to the output stream the eight low-order - * bits of the argument {@code v}. - * The 24 high-order bits of {@code v} - * are ignored. (This means that {@code writeByte} - * does exactly the same thing as {@code write} - * for an integer argument.) The byte written - * by this method may be read by the {@code readByte} - * method of interface {@code DataInput}, - * which will then return a {@code byte} - * equal to {@code (byte)v}. - * - * @param v the byte value to be written. - */ - void writeByte(int v); - - /** - * Writes two bytes to the output - * stream to represent the value of the argument. - * The byte values to be written, in the order - * shown, are: - *

{@code
-	 * (byte)(0xff & (v >> 8))
-	 * (byte)(0xff & v)
-	 * }

- * The bytes written by this method may be - * read by the {@code readShort} method - * of interface {@code DataInput}, which - * will then return a {@code short} equal - * to {@code (short)v}. - * - * @param v the {@code short} value to be written. - */ - void writeShort(int v); - - /** - * Writes a {@code char} value, which - * is comprised of two bytes, to the - * output stream. - * The byte values to be written, in the order - * shown, are: - *

{@code
-	 * (byte)(0xff & (v >> 8))
-	 * (byte)(0xff & v)
-	 * }

- * The bytes written by this method may be - * read by the {@code readChar} method - * of interface {@code DataInput}, which - * will then return a {@code char} equal - * to {@code (char)v}. - * - * @param v the {@code char} value to be written. - */ - void writeChar(int v); - - /** - * Writes an {@code int} value, which is - * comprised of four bytes, to the output stream. - * The byte values to be written, in the order - * shown, are: - *

{@code
-	 * (byte)(0xff & (v >> 24))
-	 * (byte)(0xff & (v >> 16))
-	 * (byte)(0xff & (v >>  8))
-	 * (byte)(0xff & v)
-	 * }

- * The bytes written by this method may be read - * by the {@code readInt} method of interface - * {@code DataInput}, which will then - * return an {@code int} equal to {@code v}. - * - * @param v the {@code int} value to be written. - */ - void writeInt(int v); - - /** - * Writes a {@code long} value, which is - * comprised of eight bytes, to the output stream. - * The byte values to be written, in the order - * shown, are: - *

{@code
-	 * (byte)(0xff & (v >> 56))
-	 * (byte)(0xff & (v >> 48))
-	 * (byte)(0xff & (v >> 40))
-	 * (byte)(0xff & (v >> 32))
-	 * (byte)(0xff & (v >> 24))
-	 * (byte)(0xff & (v >> 16))
-	 * (byte)(0xff & (v >>  8))
-	 * (byte)(0xff & v)
-	 * }

- * The bytes written by this method may be - * read by the {@code readLong} method - * of interface {@code DataInput}, which - * will then return a {@code long} equal - * to {@code v}. - * - * @param v the {@code long} value to be written. - */ - void writeLong(long v); - - /** - * Writes a {@code float} value, - * which is comprised of four bytes, to the output stream. - * It does this as if it first converts this - * {@code float} value to an {@code int} - * in exactly the manner of the {@code Float.floatToIntBits} - * method and then writes the {@code int} - * value in exactly the manner of the {@code writeInt} - * method. The bytes written by this method - * may be read by the {@code readFloat} - * method of interface {@code DataInput}, - * which will then return a {@code float} - * equal to {@code v}. - * - * @param v the {@code float} value to be written. - */ - void writeFloat(float v); - - /** - * Writes a {@code double} value, - * which is comprised of eight bytes, to the output stream. - * It does this as if it first converts this - * {@code double} value to a {@code long} - * in exactly the manner of the {@code Double.doubleToLongBits} - * method and then writes the {@code long} - * value in exactly the manner of the {@code writeLong} - * method. The bytes written by this method - * may be read by the {@code readDouble} - * method of interface {@code DataInput}, - * which will then return a {@code double} - * equal to {@code v}. - * - * @param v the {@code double} value to be written. - */ - void writeDouble(double v); - - /** - * Writes a string to the output stream. - * For every character in the string - * {@code s}, taken in order, one byte - * is written to the output stream. If - * {@code s} is {@code null}, a {@code NullPointerException} - * is thrown.

If {@code s.length} - * is zero, then no bytes are written. Otherwise, - * the character {@code s[0]} is written - * first, then {@code s[1]}, and so on; - * the last character written is {@code s[s.length-1]}. - * For each character, one byte is written, - * the low-order byte, in exactly the manner - * of the {@code writeByte} method . The - * high-order eight bits of each character - * in the string are ignored. - * - * @param s the string of bytes to be written. - */ - void writeBytes(String s); - - /** - * Writes every character in the string {@code s}, - * to the output stream, in order, - * two bytes per character. If {@code s} - * is {@code null}, a {@code NullPointerException} - * is thrown. If {@code s.length} - * is zero, then no characters are written. - * Otherwise, the character {@code s[0]} - * is written first, then {@code s[1]}, - * and so on; the last character written is - * {@code s[s.length-1]}. For each character, - * two bytes are actually written, high-order - * byte first, in exactly the manner of the - * {@code writeChar} method. - * - * @param s the string value to be written. - */ - void writeChars(String s); - - /** - * Writes two bytes of length information - * to the output stream, followed - * by the - * modified UTF-8 - * representation - * of every character in the string {@code s}. - * If {@code s} is {@code null}, - * a {@code NullPointerException} is thrown. - * Each character in the string {@code s} - * is converted to a group of one, two, or - * three bytes, depending on the value of the - * character.

- * If a character {@code c} - * is in the range \u0001 through - * \u007f, it is represented - * by one byte: - *

(byte)c 

- * If a character {@code c} is \u0000 - * or is in the range \u0080 - * through \u07ff, then it is - * represented by two bytes, to be written - * in the order shown:

{@code
-	 * (byte)(0xc0 | (0x1f & (c >> 6)))
-	 * (byte)(0x80 | (0x3f & c))
-	 * }

If a character - * {@code c} is in the range \u0800 - * through {@code uffff}, then it is - * represented by three bytes, to be written - * in the order shown:

{@code
-	 * (byte)(0xe0 | (0x0f & (c >> 12)))
-	 * (byte)(0x80 | (0x3f & (c >>  6)))
-	 * (byte)(0x80 | (0x3f & c))
-	 * }

First, - * the total number of bytes needed to represent - * all the characters of {@code s} is - * calculated. If this number is larger than - * {@code 65535}, then a {@code UTFDataFormatException} - * is thrown. Otherwise, this length is written - * to the output stream in exactly the manner - * of the {@code writeShort} method; - * after this, the one-, two-, or three-byte - * representation of each character in the - * string {@code s} is written.

The - * bytes written by this method may be read - * by the {@code readUTF} method of interface - * {@code DataInput}, which will then - * return a {@code String} equal to {@code s}. - * - * @param s the string value to be written. - */ - void writeUTF(String s); -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeDataOutputStream.java b/src/main/java/org/warp/commonutils/stream/SafeDataOutputStream.java deleted file mode 100644 index f7f1d85..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeDataOutputStream.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ - -package org.warp.commonutils.stream; - -import java.io.DataOutputStream; - -/** - * A data output stream lets an application write primitive Java data - * types to an output stream in a portable way. An application can - * then use a data input stream to read the data back in. - * - * @author unascribed - * @see java.io.DataInputStream - * @since 1.0 - */ -public class SafeDataOutputStream extends SafeFilterOutputStream implements SafeDataOutput { - /** - * The number of bytes written to the data output stream so far. - * If this counter overflows, it will be wrapped to Integer.MAX_VALUE. - */ - protected int written; - - /** - * bytearr is initialized on demand by writeUTF - */ - private byte[] bytearr = null; - - /** - * Creates a new data output stream to write data to the specified - * underlying output stream. The counter {@code written} is - * set to zero. - * - * @param out the underlying output stream, to be saved for later - * use. - * @see SafeFilterOutputStream#out - */ - public SafeDataOutputStream(SafeOutputStream out) { - super(out); - } - - /** - * Increases the written counter by the specified value - * until it reaches Integer.MAX_VALUE. - */ - private void incCount(int value) { - int temp = written + value; - if (temp < 0) { - temp = Integer.MAX_VALUE; - } - written = temp; - } - - /** - * Writes the specified byte (the low eight bits of the argument - * {@code b}) to the underlying output stream. If no exception - * is thrown, the counter {@code written} is incremented by - * {@code 1}. - *

- * Implements the {@code write} method of {@code OutputStream}. - * - * @param b the {@code byte} to be written. - * @see SafeFilterOutputStream#out - */ - public void write(int b) { - out.write(b); - incCount(1); - } - - /** - * Writes {@code len} bytes from the specified byte array - * starting at offset {@code off} to the underlying output stream. - * If no exception is thrown, the counter {@code written} is - * incremented by {@code len}. - * - * @param b the data. - * @param off the start offset in the data. - * @param len the number of bytes to write. - * @see SafeFilterOutputStream#out - */ - public void write(byte[] b, int off, int len) - { - out.write(b, off, len); - incCount(len); - } - - /** - * Flushes this data output stream. This forces any buffered output - * bytes to be written out to the stream. - *

- * The {@code flush} method of {@code SafeDataOutputStream} - * calls the {@code flush} method of its underlying output stream. - * - * @see SafeFilterOutputStream#out - * @see java.io.OutputStream#flush() - */ - public void flush() { - out.flush(); - } - - /** - * Writes a {@code boolean} to the underlying output stream as - * a 1-byte value. The value {@code true} is written out as the - * value {@code (byte)1}; the value {@code false} is - * written out as the value {@code (byte)0}. If no exception is - * thrown, the counter {@code written} is incremented by - * {@code 1}. - * - * @param v a {@code boolean} value to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeBoolean(boolean v) { - out.write(v ? 1 : 0); - incCount(1); - } - - /** - * Writes out a {@code byte} to the underlying output stream as - * a 1-byte value. If no exception is thrown, the counter - * {@code written} is incremented by {@code 1}. - * - * @param v a {@code byte} value to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeByte(int v) { - out.write(v); - incCount(1); - } - - /** - * Writes a {@code short} to the underlying output stream as two - * bytes, high byte first. If no exception is thrown, the counter - * {@code written} is incremented by {@code 2}. - * - * @param v a {@code short} to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeShort(int v) { - out.write((v >>> 8) & 0xFF); - out.write((v) & 0xFF); - incCount(2); - } - - /** - * Writes a {@code char} to the underlying output stream as a - * 2-byte value, high byte first. If no exception is thrown, the - * counter {@code written} is incremented by {@code 2}. - * - * @param v a {@code char} value to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeChar(int v) { - out.write((v >>> 8) & 0xFF); - out.write((v) & 0xFF); - incCount(2); - } - - /** - * Writes an {@code int} to the underlying output stream as four - * bytes, high byte first. If no exception is thrown, the counter - * {@code written} is incremented by {@code 4}. - * - * @param v an {@code int} to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeInt(int v) { - out.write((v >>> 24) & 0xFF); - out.write((v >>> 16) & 0xFF); - out.write((v >>> 8) & 0xFF); - out.write((v) & 0xFF); - incCount(4); - } - - private final byte[] writeBuffer = new byte[8]; - - /** - * Writes a {@code long} to the underlying output stream as eight - * bytes, high byte first. In no exception is thrown, the counter - * {@code written} is incremented by {@code 8}. - * - * @param v a {@code long} to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeLong(long v) { - writeBuffer[0] = (byte)(v >>> 56); - writeBuffer[1] = (byte)(v >>> 48); - writeBuffer[2] = (byte)(v >>> 40); - writeBuffer[3] = (byte)(v >>> 32); - writeBuffer[4] = (byte)(v >>> 24); - writeBuffer[5] = (byte)(v >>> 16); - writeBuffer[6] = (byte)(v >>> 8); - writeBuffer[7] = (byte)(v); - out.write(writeBuffer, 0, 8); - incCount(8); - } - - /** - * Converts the float argument to an {@code int} using the - * {@code floatToIntBits} method in class {@code Float}, - * and then writes that {@code int} value to the underlying - * output stream as a 4-byte quantity, high byte first. If no - * exception is thrown, the counter {@code written} is - * incremented by {@code 4}. - * - * @param v a {@code float} value to be written. - * @see SafeFilterOutputStream#out - * @see Float#floatToIntBits(float) - */ - public final void writeFloat(float v) { - writeInt(Float.floatToIntBits(v)); - } - - /** - * Converts the double argument to a {@code long} using the - * {@code doubleToLongBits} method in class {@code Double}, - * and then writes that {@code long} value to the underlying - * output stream as an 8-byte quantity, high byte first. If no - * exception is thrown, the counter {@code written} is - * incremented by {@code 8}. - * - * @param v a {@code double} value to be written. - * @see SafeFilterOutputStream#out - * @see Double#doubleToLongBits(double) - */ - public final void writeDouble(double v) { - writeLong(Double.doubleToLongBits(v)); - } - - /** - * Writes out the string to the underlying output stream as a - * sequence of bytes. Each character in the string is written out, in - * sequence, by discarding its high eight bits. If no exception is - * thrown, the counter {@code written} is incremented by the - * length of {@code s}. - * - * @param s a string of bytes to be written. - * @see SafeFilterOutputStream#out - */ - public final void writeBytes(String s) { - int len = s.length(); - for (int i = 0 ; i < len ; i++) { - out.write((byte)s.charAt(i)); - } - incCount(len); - } - - /** - * Writes a string to the underlying output stream as a sequence of - * characters. Each character is written to the data output stream as - * if by the {@code writeChar} method. If no exception is - * thrown, the counter {@code written} is incremented by twice - * the length of {@code s}. - * - * @param s a {@code String} value to be written. - * @see SafeDataOutputStream#writeChar(int) - * @see SafeFilterOutputStream#out - */ - public final void writeChars(String s) { - int len = s.length(); - for (int i = 0 ; i < len ; i++) { - int v = s.charAt(i); - out.write((v >>> 8) & 0xFF); - out.write((v) & 0xFF); - } - incCount(len * 2); - } - - /** - * Writes a string to the underlying output stream using - * modified UTF-8 - * encoding in a machine-independent manner. - *

- * First, two bytes are written to the output stream as if by the - * {@code writeShort} method giving the number of bytes to - * follow. This value is the number of bytes actually written out, - * not the length of the string. Following the length, each character - * of the string is output, in sequence, using the modified UTF-8 encoding - * for the character. If no exception is thrown, the counter - * {@code written} is incremented by the total number of - * bytes written to the output stream. This will be at least two - * plus the length of {@code str}, and at most two plus - * thrice the length of {@code str}. - * - * @param str a string to be written. - * @see #writeChars(String) - */ - public final void writeUTF(String str) { - writeUTF(str, this); - } - - public final void writeUTF(int strlen, int utflen, String str) { - writeUTF(strlen, utflen, str, this); - } - - /** - * Writes a string to the specified DataOutput using - * modified UTF-8 - * encoding in a machine-independent manner. - *

- * First, two bytes are written to out as if by the {@code writeShort} - * method giving the number of bytes to follow. This value is the number of - * bytes actually written out, not the length of the string. Following the - * length, each character of the string is output, in sequence, using the - * modified UTF-8 encoding for the character. If no exception is thrown, the - * counter {@code written} is incremented by the total number of - * bytes written to the output stream. This will be at least two - * plus the length of {@code str}, and at most two plus - * thrice the length of {@code str}. - * - * @param str a string to be written. - * @param out destination to write to - * @return The number of bytes written out. - */ - static int writeUTF(String str, SafeDataOutput out) { - int strlen = strLen(str); - int utflen = utfLen(str, strlen); - return writeUTF(strlen, utflen, str, out); - } - - public static int strLen(String str) { - return str.length(); - } - - public static int utfLen(String str, int strLen) { - int utflen = strLen; // optimized for ASCII - - for (int i = 0; i < strLen; i++) { - int c = str.charAt(i); - if (c >= 0x80 || c == 0) - utflen += (c >= 0x800) ? 2 : 1; - } - - if (utflen > 65535 || /* overflow */ utflen < strLen) - throw new IllegalArgumentException(tooLongMsg(str, utflen)); - return utflen; - } - - static int writeUTF(int strlen, int utflen, String str, SafeDataOutput out) { - final byte[] bytearr; - if (out instanceof SafeDataOutputStream dos) { - if (dos.bytearr == null || (dos.bytearr.length < (utflen + 2))) - dos.bytearr = new byte[(utflen*2) + 2]; - bytearr = dos.bytearr; - } else { - bytearr = new byte[utflen + 2]; - } - - int count = 0; - bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF); - bytearr[count++] = (byte) ((utflen) & 0xFF); - - int i; - for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII - int c = str.charAt(i); - if (c >= 0x80 || c == 0) break; - bytearr[count++] = (byte) c; - } - - for (; i < strlen; i++) { - int c = str.charAt(i); - if (c < 0x80 && c != 0) { - bytearr[count++] = (byte) c; - } else if (c >= 0x800) { - bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); - bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); - bytearr[count++] = (byte) (0x80 | ((c) & 0x3F)); - } else { - bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); - bytearr[count++] = (byte) (0x80 | ((c) & 0x3F)); - } - } - out.write(bytearr, 0, utflen + 2); - return utflen + 2; - } - - private static String tooLongMsg(String s, int bits32) { - int slen = s.length(); - String head = s.substring(0, 8); - String tail = s.substring(slen - 8, slen); - // handle int overflow with max 3x expansion - long actualLength = (long)slen + Integer.toUnsignedLong(bits32 - slen); - return "encoded string (" + head + "..." + tail + ") too long: " - + actualLength + " bytes"; - } - - /** - * Returns the current value of the counter {@code written}, - * the number of bytes written to this data output stream so far. - * If the counter overflows, it will be wrapped to Integer.MAX_VALUE. - * - * @return the value of the {@code written} field. - * @see SafeDataOutputStream#written - */ - public final int size() { - return written; - } - - public DataOutputStream asDataOutputStream() { - return new DataOutputStream(this.out); - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeFilterInputStream.java b/src/main/java/org/warp/commonutils/stream/SafeFilterInputStream.java deleted file mode 100644 index 7e8247b..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeFilterInputStream.java +++ /dev/null @@ -1,210 +0,0 @@ -package org.warp.commonutils.stream; - -/** - * A {@code FilterInputStream} contains - * some other input stream, which it uses as - * its basic source of data, possibly transforming - * the data along the way or providing additional - * functionality. The class {@code FilterInputStream} - * itself simply overrides all methods of - * {@code InputStream} with versions that - * pass all requests to the contained input - * stream. Subclasses of {@code FilterInputStream} - * may further override some of these methods - * and may also provide additional methods - * and fields. - * - * @author Jonathan Payne - * @since 1.0 - */ -public class SafeFilterInputStream extends SafeInputStream { - /** - * The input stream to be filtered. - */ - protected volatile SafeInputStream in; - - /** - * Creates a {@code FilterInputStream} - * by assigning the argument {@code in} - * to the field {@code this.in} so as - * to remember it for later use. - * - * @param in the underlying input stream, or {@code null} if - * this instance is to be created without an underlying stream. - */ - protected SafeFilterInputStream(SafeInputStream in) { - this.in = in; - } - - /** - * Reads the next byte of data from this input stream. The value - * byte is returned as an {@code int} in the range - * {@code 0} to {@code 255}. If no byte is available - * because the end of the stream has been reached, the value - * {@code -1} is returned. This method blocks until input data - * is available, the end of the stream is detected, or an exception - * is thrown. - *

- * This method - * simply performs {@code in.read()} and returns the result. - * - * @return the next byte of data, or {@code -1} if the end of the - * stream is reached. - * @see SafeFilterInputStream#in - */ - public int read() { - return in.read(); - } - - /** - * Reads up to {@code b.length} bytes of data from this - * input stream into an array of bytes. This method blocks until some - * input is available. - *

- * This method simply performs the call - * {@code read(b, 0, b.length)} and returns - * the result. It is important that it does - * not do {@code in.read(b)} instead; - * certain subclasses of {@code FilterInputStream} - * depend on the implementation strategy actually - * used. - * - * @param b the buffer into which the data is read. - * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end of - * the stream has been reached. - * @see SafeFilterInputStream#read(byte[], int, int) - */ - public int read(byte b[]) { - return read(b, 0, b.length); - } - - /** - * Reads up to {@code len} bytes of data from this input stream - * into an array of bytes. If {@code len} is not zero, the method - * blocks until some input is available; otherwise, no - * bytes are read and {@code 0} is returned. - *

- * This method simply performs {@code in.read(b, off, len)} - * and returns the result. - * - * @param b the buffer into which the data is read. - * @param off the start offset in the destination array {@code b} - * @param len the maximum number of bytes read. - * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end of - * the stream has been reached. - * @throws NullPointerException If {@code b} is {@code null}. - * @throws IndexOutOfBoundsException If {@code off} is negative, - * {@code len} is negative, or {@code len} is greater than - * {@code b.length - off} - * @see SafeFilterInputStream#in - */ - public int read(byte b[], int off, int len) { - return in.read(b, off, len); - } - - /** - * Skips over and discards {@code n} bytes of data from the - * input stream. The {@code skip} method may, for a variety of - * reasons, end up skipping over some smaller number of bytes, - * possibly {@code 0}. The actual number of bytes skipped is - * returned. - *

- * This method simply performs {@code in.skip(n)}. - * - * @param n the number of bytes to be skipped. - * @return the actual number of bytes skipped. - */ - public long skip(long n) { - return in.skip(n); - } - - /** - * Returns an estimate of the number of bytes that can be read (or - * skipped over) from this input stream without blocking by the next - * caller of a method for this input stream. The next caller might be - * the same thread or another thread. A single read or skip of this - * many bytes will not block, but may read or skip fewer bytes. - *

- * This method returns the result of {@link #in in}.available(). - * - * @return an estimate of the number of bytes that can be read (or skipped - * over) from this input stream without blocking. - */ - public int available() { - return in.available(); - } - - /** - * Closes this input stream and releases any system resources - * associated with the stream. - * This - * method simply performs {@code in.close()}. - * - * @see SafeFilterInputStream#in - */ - public void close() { - in.close(); - } - - /** - * Marks the current position in this input stream. A subsequent - * call to the {@code reset} method repositions this stream at - * the last marked position so that subsequent reads re-read the same bytes. - *

- * The {@code readlimit} argument tells this input stream to - * allow that many bytes to be read before the mark position gets - * invalidated. - *

- * This method simply performs {@code in.mark(readlimit)}. - * - * @param readlimit the maximum limit of bytes that can be read before - * the mark position becomes invalid. - * @see SafeFilterInputStream#in - * @see SafeFilterInputStream#reset() - */ - public void mark(int readlimit) { - in.mark(readlimit); - } - - /** - * Repositions this stream to the position at the time the - * {@code mark} method was last called on this input stream. - *

- * This method - * simply performs {@code in.reset()}. - *

- * Stream marks are intended to be used in - * situations where you need to read ahead a little to see what's in - * the stream. Often this is most easily done by invoking some - * general parser. If the stream is of the type handled by the - * parse, it just chugs along happily. If the stream is not of - * that type, the parser should toss an exception when it fails. - * If this happens within readlimit bytes, it allows the outer - * code to reset the stream and try another parser. - * - * @see SafeFilterInputStream#in - * @see SafeFilterInputStream#mark(int) - */ - public void reset() { - in.reset(); - } - - /** - * Tests if this input stream supports the {@code mark} - * and {@code reset} methods. - * This method - * simply performs {@code in.markSupported()}. - * - * @return {@code true} if this stream type supports the - * {@code mark} and {@code reset} method; - * {@code false} otherwise. - * @see SafeFilterInputStream#in - * @see java.io.InputStream#mark(int) - * @see java.io.InputStream#reset() - */ - public boolean markSupported() { - return in.markSupported(); - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeFilterOutputStream.java b/src/main/java/org/warp/commonutils/stream/SafeFilterOutputStream.java deleted file mode 100644 index f4fd0e5..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeFilterOutputStream.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.warp.commonutils.stream; - - -/** - * This class is the superclass of all classes that filter output - * streams. These streams sit on top of an already existing output - * stream (the underlying output stream) which it uses as its - * basic sink of data, but possibly transforming the data along the - * way or providing additional functionality. - *

- * The class {@code FilterOutputStream} itself simply overrides - * all methods of {@code SafeOutputStream} with versions that pass - * all requests to the underlying output stream. Subclasses of - * {@code FilterOutputStream} may further override some of these - * methods as well as provide additional methods and fields. - * - * @author Jonathan Payne - * @since 1.0 - */ -public class SafeFilterOutputStream extends SafeOutputStream { - /** - * The underlying output stream to be filtered. - */ - protected SafeOutputStream out; - - /** - * Whether the stream is closed; implicitly initialized to false. - */ - private volatile boolean closed; - - /** - * Object used to prevent a race on the 'closed' instance variable. - */ - private final Object closeLock = new Object(); - - /** - * Creates an output stream filter built on top of the specified - * underlying output stream. - * - * @param out the underlying output stream to be assigned to - * the field {@code this.out} for later use, or - * {@code null} if this instance is to be - * created without an underlying stream. - */ - public SafeFilterOutputStream(SafeOutputStream out) { - this.out = out; - } - - /** - * Writes the specified {@code byte} to this output stream. - *

- * The {@code write} method of {@code FilterOutputStream} - * calls the {@code write} method of its underlying output stream, - * that is, it performs {@code out.write(b)}. - *

- * Implements the abstract {@code write} method of {@code SafeOutputStream}. - * - * @param b the {@code byte}. - */ - @Override - public void write(int b) { - out.write(b); - } - - /** - * Writes {@code b.length} bytes to this output stream. - *

- * The {@code write} method of {@code FilterOutputStream} - * calls its {@code write} method of three arguments with the - * arguments {@code b}, {@code 0}, and - * {@code b.length}. - *

- * Note that this method does not call the one-argument - * {@code write} method of its underlying output stream with - * the single argument {@code b}. - * - * @param b the data to be written. - * @see SafeFilterOutputStream#write(byte[], int, int) - */ - @Override - public void write(byte b[]) { - write(b, 0, b.length); - } - - /** - * Writes {@code len} bytes from the specified - * {@code byte} array starting at offset {@code off} to - * this output stream. - *

- * The {@code write} method of {@code FilterOutputStream} - * calls the {@code write} method of one argument on each - * {@code byte} to output. - *

- * Note that this method does not call the {@code write} method - * of its underlying output stream with the same arguments. Subclasses - * of {@code FilterOutputStream} should provide a more efficient - * implementation of this method. - * - * @param b the data. - * @param off the start offset in the data. - * @param len the number of bytes to write. - * @see SafeFilterOutputStream#write(int) - */ - @Override - public void write(byte b[], int off, int len) { - if ((off | len | (b.length - (len + off)) | (off + len)) < 0) - throw new IndexOutOfBoundsException(); - - for (int i = 0 ; i < len ; i++) { - write(b[off + i]); - } - } - - /** - * Flushes this output stream and forces any buffered output bytes - * to be written out to the stream. - *

- * The {@code flush} method of {@code FilterOutputStream} - * calls the {@code flush} method of its underlying output stream. - * - * @see SafeFilterOutputStream#out - */ - @Override - public void flush() { - out.flush(); - } - - /** - * Closes this output stream and releases any system resources - * associated with the stream. - *

- * When not already closed, the {@code close} method of {@code - * FilterOutputStream} calls its {@code flush} method, and then - * calls the {@code close} method of its underlying output stream. - * - * @see SafeFilterOutputStream#flush() - * @see SafeFilterOutputStream#out - */ - @Override - public void close() { - if (closed) { - return; - } - synchronized (closeLock) { - if (closed) { - return; - } - closed = true; - } - - Throwable flushException = null; - try { - flush(); - } catch (Throwable e) { - flushException = e; - throw e; - } finally { - if (flushException == null) { - out.close(); - } else { - try { - out.close(); - } catch (Throwable closeException) { - // evaluate possible precedence of flushException over closeException - if ((flushException instanceof ThreadDeath) && - !(closeException instanceof ThreadDeath)) { - flushException.addSuppressed(closeException); - throw (ThreadDeath) flushException; - } - - if (flushException != closeException) { - closeException.addSuppressed(flushException); - } - - throw closeException; - } - } - } - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeInputStream.java b/src/main/java/org/warp/commonutils/stream/SafeInputStream.java deleted file mode 100644 index 89020b0..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeInputStream.java +++ /dev/null @@ -1,201 +0,0 @@ -package org.warp.commonutils.stream; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -public abstract class SafeInputStream extends InputStream { - - // MAX_SKIP_BUFFER_SIZE is used to determine the maximum buffer size to - // use when skipping. - private static final int MAX_SKIP_BUFFER_SIZE = 2048; - - private static final int DEFAULT_BUFFER_SIZE = 8192; - - @Override - public abstract int read(); - - public int read(byte b[]) { - return read(b, 0, b.length); - } - - public int read(byte b[], int off, int len) { - Objects.checkFromIndexSize(off, len, b.length); - if (len == 0) { - return 0; - } - - int c = read(); - if (c == -1) { - return -1; - } - b[off] = (byte)c; - - int i = 1; - for (; i < len ; i++) { - c = read(); - if (c == -1) { - break; - } - b[off + i] = (byte)c; - } - return i; - } - - public byte[] readAllBytes() { - return readNBytes(Integer.MAX_VALUE); - } - - private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; - - public byte[] readNBytes(int len) { - if (len < 0) { - throw new IllegalArgumentException("len < 0"); - } - - List bufs = null; - byte[] result = null; - int total = 0; - int remaining = len; - int n; - do { - byte[] buf = new byte[Math.min(remaining, DEFAULT_BUFFER_SIZE)]; - int nread = 0; - - // read to EOF which may read more or less than buffer size - while ((n = read(buf, nread, - Math.min(buf.length - nread, remaining))) > 0) { - nread += n; - remaining -= n; - } - - if (nread > 0) { - if (MAX_BUFFER_SIZE - total < nread) { - throw new OutOfMemoryError("Required array size too large"); - } - total += nread; - if (result == null) { - result = buf; - } else { - if (bufs == null) { - bufs = new ArrayList<>(); - bufs.add(result); - } - bufs.add(buf); - } - } - // if the last call to read returned -1 or the number of bytes - // requested have been read then break - } while (n >= 0 && remaining > 0); - - if (bufs == null) { - if (result == null) { - return new byte[0]; - } - return result.length == total ? - result : Arrays.copyOf(result, total); - } - - result = new byte[total]; - int offset = 0; - remaining = total; - for (byte[] b : bufs) { - int count = Math.min(b.length, remaining); - System.arraycopy(b, 0, result, offset, count); - offset += count; - remaining -= count; - } - - return result; - } - - public int readNBytes(byte[] b, int off, int len) { - Objects.checkFromIndexSize(off, len, b.length); - - int n = 0; - while (n < len) { - int count = read(b, off + n, len - n); - if (count < 0) - break; - n += count; - } - return n; - } - - public long skip(long n) { - long remaining = n; - int nr; - - if (n <= 0) { - return 0; - } - - int size = (int)Math.min(MAX_SKIP_BUFFER_SIZE, remaining); - byte[] skipBuffer = new byte[size]; - while (remaining > 0) { - nr = read(skipBuffer, 0, (int)Math.min(size, remaining)); - if (nr < 0) { - break; - } - remaining -= nr; - } - - return n - remaining; - } - - public void skipNBytes(long n) { - if (n > 0) { - long ns = skip(n); - if (ns >= 0 && ns < n) { // skipped too few bytes - // adjust number to skip - n -= ns; - // read until requested number skipped or EOS reached - while (n > 0 && read() != -1) { - n--; - } - // if not enough skipped, then EOFE - if (n != 0) { - throw new IndexOutOfBoundsException(); - } - } else if (ns != n) { // skipped negative or too many bytes - throw new IllegalArgumentException("Unable to skip exactly"); - } - } - } - - public int available() { - return 0; - } - - public void close() {} - - public void mark(int readlimit) {} - - public void reset() { - throw new UnsupportedOperationException("mark/reset not supported"); - } - - public boolean markSupported() { - return false; - } - - public long transferTo(OutputStream out) { - Objects.requireNonNull(out, "out"); - long transferred = 0; - byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; - int read; - while ((read = this.read(buffer, 0, DEFAULT_BUFFER_SIZE)) >= 0) { - try { - out.write(buffer, 0, read); - } catch (IOException e) { - throw new IllegalStateException(e); - } - transferred += read; - } - return transferred; - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeMeasurableInputStream.java b/src/main/java/org/warp/commonutils/stream/SafeMeasurableInputStream.java deleted file mode 100644 index 547f847..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeMeasurableInputStream.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.warp.commonutils.stream; - -/* - * Copyright (C) 2005-2020 Sebastiano Vigna - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import java.io.InputStream; - -/** An {@link InputStream} that implements also the {@link SafeMeasurableStream} interface. - * - * @since 5.0.4 - */ - -public abstract class SafeMeasurableInputStream extends SafeInputStream implements SafeMeasurableStream { -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeMeasurableOutputStream.java b/src/main/java/org/warp/commonutils/stream/SafeMeasurableOutputStream.java deleted file mode 100644 index fb67530..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeMeasurableOutputStream.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.warp.commonutils.stream; - -/* - * Copyright (C) 2005-2020 Sebastiano Vigna - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.OutputStream; - -/** An {@link OutputStream} that implements also the {@link SafeMeasurableStream} interface. - * - * @since 6.0.0 - */ - -public abstract class SafeMeasurableOutputStream extends SafeOutputStream implements SafeMeasurableStream { -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeMeasurableStream.java b/src/main/java/org/warp/commonutils/stream/SafeMeasurableStream.java deleted file mode 100644 index a5db872..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeMeasurableStream.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.warp.commonutils.stream; - -/* - * Copyright (C) 2005-2020 Sebastiano Vigna - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import it.unimi.dsi.fastutil.io.FastBufferedInputStream; -import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; -import it.unimi.dsi.fastutil.io.MeasurableInputStream; - -/** An stream that provides eager access to its length, - * and keeps track of the current position (e.g., the number of bytes read so far, or the current - * position of the file pointer). - * - *

This class has two methods, both specified as optional. This apparently bizarre - * behaviour is necessary because of wrapper classes which use reflection - * to support those methods (see, e.g., {@link MeasurableInputStream}, {@link FastBufferedInputStream} and {@link FastBufferedOutputStream}). - * - * @since 6.0.0 - */ - -public interface SafeMeasurableStream { - - /** Returns the overall length of this stream (optional operation). In most cases, this will require the - * stream to perform some extra action, possibly changing the state of the input stream itself (typically, reading - * all the bytes up to the end, or flushing on output stream). - * Implementing classes should always document what state will the input stream be in - * after calling this method, and which kind of exception could be thrown. - */ - long length(); - - /** Returns the current position in this stream (optional operation). - * - *

Usually, the position is just the number of bytes read or written - * since the stream was opened, but in the case of a - * {@link it.unimi.dsi.fastutil.io.RepositionableStream} it - * represent the current position. - */ - long position(); -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeOutputStream.java b/src/main/java/org/warp/commonutils/stream/SafeOutputStream.java deleted file mode 100644 index bc67d8e..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeOutputStream.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.warp.commonutils.stream; - -import java.io.Closeable; -import java.io.Flushable; -import java.io.OutputStream; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; - -/** - * This abstract class is the superclass of all classes representing - * an output stream of bytes. An output stream accepts output bytes - * and sends them to some sink. - *

- * Applications that need to define a subclass of - * {@code OutputStream} must always provide at least a method - * that writes one byte of output. - * - * @author Arthur van Hoff - * @see java.io.BufferedOutputStream - * @see java.io.ByteArrayOutputStream - * @see java.io.DataOutputStream - * @see java.io.FilterOutputStream - * @see java.io.InputStream - * @see OutputStream#write(int) - * @since 1.0 - */ -public abstract class SafeOutputStream extends OutputStream implements Closeable, Flushable { - /** - * Constructor for subclasses to call. - */ - public SafeOutputStream() {} - - /** - * Returns a new {@code OutputStream} which discards all bytes. The - * returned stream is initially open. The stream is closed by calling - * the {@code close()} method. Subsequent calls to {@code close()} have - * no effect. - * - *

While the stream is open, the {@code write(int)}, {@code - * write(byte[])}, and {@code write(byte[], int, int)} methods do nothing. - * After the stream has been closed, these methods all throw {@code - * IOException}. - * - *

The {@code flush()} method does nothing. - * - * @return an {@code OutputStream} which discards all bytes - * - * @since 11 - */ - public static OutputStream nullOutputStream() { - return new OutputStream() { - private volatile boolean closed; - - private void ensureOpen() { - if (closed) { - throw new IllegalStateException("Stream closed"); - } - } - - @Override - public void write(int b) { - ensureOpen(); - } - - @Override - public void write(byte @NotNull [] b, int off, int len) { - Objects.checkFromIndexSize(off, len, b.length); - ensureOpen(); - } - - @Override - public void close() { - closed = true; - } - }; - } - - /** - * Writes the specified byte to this output stream. The general - * contract for {@code write} is that one byte is written - * to the output stream. The byte to be written is the eight - * low-order bits of the argument {@code b}. The 24 - * high-order bits of {@code b} are ignored. - *

- * Subclasses of {@code OutputStream} must provide an - * implementation for this method. - * - * @param b the {@code byte}. - */ - public abstract void write(int b); - - /** - * Writes {@code b.length} bytes from the specified byte array - * to this output stream. The general contract for {@code write(b)} - * is that it should have exactly the same effect as the call - * {@code write(b, 0, b.length)}. - * - * @param b the data. - * @see OutputStream#write(byte[], int, int) - */ - public void write(byte @NotNull [] b) { - write(b, 0, b.length); - } - - /** - * Writes {@code len} bytes from the specified byte array - * starting at offset {@code off} to this output stream. - * The general contract for {@code write(b, off, len)} is that - * some of the bytes in the array {@code b} are written to the - * output stream in order; element {@code b[off]} is the first - * byte written and {@code b[off+len-1]} is the last byte written - * by this operation. - *

- * The {@code write} method of {@code OutputStream} calls - * the write method of one argument on each of the bytes to be - * written out. Subclasses are encouraged to override this method and - * provide a more efficient implementation. - *

- * If {@code b} is {@code null}, a - * {@code NullPointerException} is thrown. - *

- * If {@code off} is negative, or {@code len} is negative, or - * {@code off+len} is greater than the length of the array - * {@code b}, then an {@code IndexOutOfBoundsException} is thrown. - * - * @param b the data. - * @param off the start offset in the data. - * @param len the number of bytes to write. - */ - public void write(byte[] b, int off, int len) { - Objects.checkFromIndexSize(off, len, b.length); - // len == 0 condition implicitly handled by loop bounds - for (int i = 0 ; i < len ; i++) { - write(b[off + i]); - } - } - - /** - * Flushes this output stream and forces any buffered output bytes - * to be written out. The general contract of {@code flush} is - * that calling it is an indication that, if any bytes previously - * written have been buffered by the implementation of the output - * stream, such bytes should immediately be written to their - * intended destination. - *

- * If the intended destination of this stream is an abstraction provided by - * the underlying operating system, for example a file, then flushing the - * stream guarantees only that bytes previously written to the stream are - * passed to the operating system for writing; it does not guarantee that - * they are actually written to a physical device such as a disk drive. - *

- * The {@code flush} method of {@code OutputStream} does nothing. - * - */ - public void flush() { - } - - /** - * Closes this output stream and releases any system resources - * associated with this stream. The general contract of {@code close} - * is that it closes the output stream. A closed stream cannot perform - * output operations and cannot be reopened. - *

- * The {@code close} method of {@code OutputStream} does nothing. - * - */ - public void close() { - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafePushbackInputStream.java b/src/main/java/org/warp/commonutils/stream/SafePushbackInputStream.java deleted file mode 100644 index ab8c929..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafePushbackInputStream.java +++ /dev/null @@ -1,332 +0,0 @@ -package org.warp.commonutils.stream; - -/** - * A {@code PushbackInputStream} adds - * functionality to another input stream, namely - * the ability to "push back" or "unread" bytes, - * by storing pushed-back bytes in an internal buffer. - * This is useful in situations where - * it is convenient for a fragment of code - * to read an indefinite number of data bytes - * that are delimited by a particular byte - * value; after reading the terminating byte, - * the code fragment can "unread" it, so that - * the next read operation on the input stream - * will reread the byte that was pushed back. - * For example, bytes representing the characters - * constituting an identifier might be terminated - * by a byte representing an operator character; - * a method whose job is to read just an identifier - * can read until it sees the operator and - * then push the operator back to be re-read. - * - * @author David Connelly - * @author Jonathan Payne - * @since 1.0 - */ -public class SafePushbackInputStream extends SafeFilterInputStream { - /** - * The pushback buffer. - * @since 1.1 - */ - protected byte[] buf; - - /** - * The position within the pushback buffer from which the next byte will - * be read. When the buffer is empty, {@code pos} is equal to - * {@code buf.length}; when the buffer is full, {@code pos} is - * equal to zero. - * - * @since 1.1 - */ - protected int pos; - - /** - * Check to make sure that this stream has not been closed - */ - private void ensureOpen() { - if (in == null) - throw new IllegalStateException("Stream closed"); - } - - /** - * Creates a {@code PushbackInputStream} - * with a pushback buffer of the specified {@code size}, - * and saves its argument, the input stream - * {@code in}, for later use. Initially, - * the pushback buffer is empty. - * - * @param in the input stream from which bytes will be read. - * @param size the size of the pushback buffer. - * @throws IllegalArgumentException if {@code size <= 0} - * @since 1.1 - */ - public SafePushbackInputStream(SafeInputStream in, int size) { - super(in); - if (size <= 0) { - throw new IllegalArgumentException("size <= 0"); - } - this.buf = new byte[size]; - this.pos = size; - } - - /** - * Creates a {@code PushbackInputStream} - * with a 1-byte pushback buffer, and saves its argument, the input stream - * {@code in}, for later use. Initially, - * the pushback buffer is empty. - * - * @param in the input stream from which bytes will be read. - */ - public SafePushbackInputStream(SafeInputStream in) { - this(in, 1); - } - - /** - * Reads the next byte of data from this input stream. The value - * byte is returned as an {@code int} in the range - * {@code 0} to {@code 255}. If no byte is available - * because the end of the stream has been reached, the value - * {@code -1} is returned. This method blocks until input data - * is available, the end of the stream is detected, or an exception - * is thrown. - * - *

This method returns the most recently pushed-back byte, if there is - * one, and otherwise calls the {@code read} method of its underlying - * input stream and returns whatever value that method returns. - * - * @return the next byte of data, or {@code -1} if the end of the - * stream has been reached. - * or an I/O error occurs. - * @see java.io.InputStream#read() - */ - public int read() { - ensureOpen(); - if (pos < buf.length) { - return buf[pos++] & 0xff; - } - return super.read(); - } - - /** - * Reads up to {@code len} bytes of data from this input stream into - * an array of bytes. This method first reads any pushed-back bytes; after - * that, if fewer than {@code len} bytes have been read then it - * reads from the underlying input stream. If {@code len} is not zero, the method - * blocks until at least 1 byte of input is available; otherwise, no - * bytes are read and {@code 0} is returned. - * - * @param b the buffer into which the data is read. - * @param off the start offset in the destination array {@code b} - * @param len the maximum number of bytes read. - * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end of - * the stream has been reached. - * @throws NullPointerException If {@code b} is {@code null}. - * @throws IndexOutOfBoundsException If {@code off} is negative, - * {@code len} is negative, or {@code len} is greater than - * {@code b.length - off} - * or an I/O error occurs. - * @see java.io.InputStream#read(byte[], int, int) - */ - public int read(byte[] b, int off, int len) { - ensureOpen(); - if (b == null) { - throw new NullPointerException(); - } else if (off < 0 || len < 0 || len > b.length - off) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return 0; - } - - int avail = buf.length - pos; - if (avail > 0) { - if (len < avail) { - avail = len; - } - System.arraycopy(buf, pos, b, off, avail); - pos += avail; - off += avail; - len -= avail; - } - if (len > 0) { - len = super.read(b, off, len); - if (len == -1) { - return avail == 0 ? -1 : avail; - } - return avail + len; - } - return avail; - } - - /** - * Pushes back a byte by copying it to the front of the pushback buffer. - * After this method returns, the next byte to be read will have the value - * {@code (byte)b}. - * - * @param b the {@code int} value whose low-order - * byte is to be pushed back. - */ - public void unread(int b) { - ensureOpen(); - if (pos == 0) { - throw new IllegalStateException("Push back buffer is full"); - } - buf[--pos] = (byte)b; - } - - /** - * Pushes back a portion of an array of bytes by copying it to the front - * of the pushback buffer. After this method returns, the next byte to be - * read will have the value {@code b[off]}, the byte after that will - * have the value {@code b[off+1]}, and so forth. - * - * @param b the byte array to push back. - * @param off the start offset of the data. - * @param len the number of bytes to push back. - * @throws NullPointerException If {@code b} is {@code null}. - * @since 1.1 - */ - public void unread(byte[] b, int off, int len) { - ensureOpen(); - if (len > pos) { - throw new IllegalStateException("Push back buffer is full"); - } - pos -= len; - System.arraycopy(b, off, buf, pos, len); - } - - /** - * Pushes back an array of bytes by copying it to the front of the - * pushback buffer. After this method returns, the next byte to be read - * will have the value {@code b[0]}, the byte after that will have the - * value {@code b[1]}, and so forth. - * - * @param b the byte array to push back - * @throws NullPointerException If {@code b} is {@code null}. - * @since 1.1 - */ - public void unread(byte[] b) { - unread(b, 0, b.length); - } - - /** - * Returns an estimate of the number of bytes that can be read (or - * skipped over) from this input stream without blocking by the next - * invocation of a method for this input stream. The next invocation might be - * the same thread or another thread. A single read or skip of this - * many bytes will not block, but may read or skip fewer bytes. - * - *

The method returns the sum of the number of bytes that have been - * pushed back and the value returned by {@link - * SafeFilterInputStream#available available}. - * - * @return the number of bytes that can be read (or skipped over) from - * the input stream without blocking. - * @see SafeFilterInputStream#in - * @see java.io.InputStream#available() - */ - public int available() { - ensureOpen(); - int n = buf.length - pos; - int avail = super.available(); - return n > (Integer.MAX_VALUE - avail) - ? Integer.MAX_VALUE - : n + avail; - } - - /** - * Skips over and discards {@code n} bytes of data from this - * input stream. The {@code skip} method may, for a variety of - * reasons, end up skipping over some smaller number of bytes, - * possibly zero. If {@code n} is negative, no bytes are skipped. - * - *

The {@code skip} method of {@code PushbackInputStream} - * first skips over the bytes in the pushback buffer, if any. It then - * calls the {@code skip} method of the underlying input stream if - * more bytes need to be skipped. The actual number of bytes skipped - * is returned. - * - * @param n {@inheritDoc} - * @return {@inheritDoc} - * @see SafeFilterInputStream#in - * @see java.io.InputStream#skip(long n) - * @since 1.2 - */ - public long skip(long n) { - ensureOpen(); - if (n <= 0) { - return 0; - } - - long pskip = buf.length - pos; - if (pskip > 0) { - if (n < pskip) { - pskip = n; - } - pos += pskip; - n -= pskip; - } - if (n > 0) { - pskip += super.skip(n); - } - return pskip; - } - - /** - * Tests if this input stream supports the {@code mark} and - * {@code reset} methods, which it does not. - * - * @return {@code false}, since this class does not support the - * {@code mark} and {@code reset} methods. - * @see java.io.InputStream#mark(int) - * @see java.io.InputStream#reset() - */ - public boolean markSupported() { - return false; - } - - /** - * Marks the current position in this input stream. - * - *

The {@code mark} method of {@code PushbackInputStream} - * does nothing. - * - * @param readlimit the maximum limit of bytes that can be read before - * the mark position becomes invalid. - * @see java.io.InputStream#reset() - */ - public void mark(int readlimit) { - } - - /** - * Repositions this stream to the position at the time the - * {@code mark} method was last called on this input stream. - * - *

The method {@code reset} for class - * {@code PushbackInputStream} does nothing except throw an - * {@code IOException}. - * - * @see java.io.InputStream#mark(int) - * @see java.io.IOException - */ - public void reset() { - throw new UnsupportedOperationException("mark/reset not supported"); - } - - /** - * Closes this input stream and releases any system resources - * associated with the stream. - * Once the stream has been closed, further read(), unread(), - * available(), reset(), or skip() invocations will throw an IOException. - * Closing a previously closed stream has no effect. - * - */ - public void close() { - if (in == null) - return; - in.close(); - in = null; - buf = null; - } -} diff --git a/src/main/java/org/warp/commonutils/stream/SafeRepositionableStream.java b/src/main/java/org/warp/commonutils/stream/SafeRepositionableStream.java deleted file mode 100644 index e79f2df..0000000 --- a/src/main/java/org/warp/commonutils/stream/SafeRepositionableStream.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.warp.commonutils.stream; - -/* - * Copyright (C) 2005-2020 Sebastiano Vigna - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** A basic interface specifying positioning methods for a byte stream. - * - * @author Sebastiano Vigna - * @since 4.4 - */ - -public interface SafeRepositionableStream { - - /** Sets the current stream position. - * - * @param newPosition the new stream position. - */ - void position(long newPosition); - - /** Returns the current stream position. - * - * @return the current stream position. - */ - long position(); - -} diff --git a/src/test/java/it/cavallium/dbengine/tests/DbTestUtils.java b/src/test/java/it/cavallium/dbengine/tests/DbTestUtils.java index d932eeb..1519de2 100644 --- a/src/test/java/it/cavallium/dbengine/tests/DbTestUtils.java +++ b/src/test/java/it/cavallium/dbengine/tests/DbTestUtils.java @@ -2,8 +2,8 @@ package it.cavallium.dbengine.tests; import static org.junit.jupiter.api.Assertions.assertEquals; -import it.cavallium.dbengine.buffers.BufDataInput; -import it.cavallium.dbengine.buffers.BufDataOutput; +import it.cavallium.buffer.BufDataInput; +import it.cavallium.buffer.BufDataOutput; import it.cavallium.dbengine.client.LuceneIndex; import it.cavallium.dbengine.client.LuceneIndexImpl; import it.cavallium.dbengine.database.LLDatabaseConnection; diff --git a/src/test/java/it/cavallium/dbengine/tests/TestLLDictionary.java b/src/test/java/it/cavallium/dbengine/tests/TestLLDictionary.java index 511d342..d9808d0 100644 --- a/src/test/java/it/cavallium/dbengine/tests/TestLLDictionary.java +++ b/src/test/java/it/cavallium/dbengine/tests/TestLLDictionary.java @@ -6,7 +6,7 @@ import static it.cavallium.dbengine.utils.StreamUtils.toList; import static org.junit.jupiter.api.Assertions.assertEquals; import it.cavallium.dbengine.tests.DbTestUtils.TempDb; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.LLDictionaryResultType; import it.cavallium.dbengine.database.LLKeyValueDatabase; diff --git a/src/test/java/it/cavallium/dbengine/tests/TestLLDictionaryLeaks.java b/src/test/java/it/cavallium/dbengine/tests/TestLLDictionaryLeaks.java index 6e3d3d0..5185000 100644 --- a/src/test/java/it/cavallium/dbengine/tests/TestLLDictionaryLeaks.java +++ b/src/test/java/it/cavallium/dbengine/tests/TestLLDictionaryLeaks.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import it.cavallium.dbengine.tests.DbTestUtils.TempDb; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.LLDictionaryResultType; import it.cavallium.dbengine.database.LLKeyValueDatabase; diff --git a/src/test/java/it/cavallium/dbengine/tests/TestLuceneIndex.java b/src/test/java/it/cavallium/dbengine/tests/TestLuceneIndex.java index 6463ff4..35678c2 100644 --- a/src/test/java/it/cavallium/dbengine/tests/TestLuceneIndex.java +++ b/src/test/java/it/cavallium/dbengine/tests/TestLuceneIndex.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import it.cavallium.dbengine.tests.DbTestUtils.TempDb; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.LuceneIndex; import it.cavallium.dbengine.client.Sort; import it.cavallium.dbengine.client.query.current.data.MatchAllDocsQuery; diff --git a/src/test/java/it/cavallium/dbengine/tests/TestRanges.java b/src/test/java/it/cavallium/dbengine/tests/TestRanges.java index 88ede82..2497a2e 100644 --- a/src/test/java/it/cavallium/dbengine/tests/TestRanges.java +++ b/src/test/java/it/cavallium/dbengine/tests/TestRanges.java @@ -1,6 +1,6 @@ package it.cavallium.dbengine.tests; -import it.cavallium.dbengine.buffers.Buf; +import it.cavallium.buffer.Buf; import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.collections.DatabaseMapDictionaryDeep; import java.util.Arrays;