You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2024/06/11 21:57:34 UTC
(datasketches-memory) 01/01: Prepare for java 8,11 3.0.0
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch prepare_java8_11_3.0.0
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit 6bea9d2a50e85de726a0feddc183e685faa93e0f
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Tue Jun 11 14:57:20 2024 -0700
Prepare for java 8,11 3.0.0
---
.../org/apache/datasketches/memory/BaseBuffer.java | 40 +-
.../org/apache/datasketches/memory/Buffer.java | 78 +--
.../memory/DefaultMemoryRequestServer.java | 2 +-
.../org/apache/datasketches/memory/Memory.java | 171 ++----
.../datasketches/memory/MemoryRequestServer.java | 4 +-
.../org/apache/datasketches/memory/Resource.java | 12 +-
.../apache/datasketches/memory/WritableBuffer.java | 79 ++-
.../apache/datasketches/memory/WritableMemory.java | 364 ++++++------
.../org/apache/datasketches/memory/XxHash.java | 15 -
.../memory/internal/BaseBufferImpl.java | 16 +
.../memory/internal/BaseWritableBufferImpl.java | 53 +-
.../memory/internal/BaseWritableMemoryImpl.java | 105 +---
.../datasketches/memory/internal/ResourceImpl.java | 6 +-
.../apache/datasketches/memory/internal/Utf8.java | 631 ---------------------
.../datasketches/memory/internal/XxHash64.java | 15 -
.../internal/AllocateDirectMapMemoryTest.java | 37 +-
.../memory/internal/AllocateDirectMemoryTest.java | 6 +-
.../AllocateDirectWritableMapMemoryTest.java | 2 +-
.../memory/internal/BaseBufferTest.java | 2 +-
.../datasketches/memory/internal/Buffer2Test.java | 26 +-
.../memory/internal/BufferInvariantsTest.java | 4 +-
.../memory/internal/BufferReadWriteSafetyTest.java | 5 -
.../datasketches/memory/internal/BufferTest.java | 9 +-
.../memory/internal/CommonBufferTest.java | 31 +-
.../memory/internal/CommonMemoryTest.java | 27 +-
.../memory/internal/CopyMemoryOverlapTest.java | 4 +-
.../memory/internal/CopyMemoryTest.java | 2 +-
.../memory/internal/IgnoredArrayOverflowTest.java | 2 +-
.../datasketches/memory/internal/LeafImplTest.java | 16 +-
.../memory/internal/MemoryReadWriteSafetyTest.java | 17 +-
.../datasketches/memory/internal/MemoryTest.java | 21 +-
.../memory/internal/MemoryWriteToTest.java | 2 +-
.../internal/NativeWritableBufferImplTest.java | 43 +-
.../internal/NativeWritableMemoryImplTest.java | 57 +-
.../internal/NonNativeWritableBufferImplTest.java | 8 +-
.../internal/NonNativeWritableMemoryImplTest.java | 4 +-
.../memory/internal/SpecificLeafTest.java | 2 +-
.../datasketches/memory/internal/ThreadTest.java | 9 +-
.../datasketches/memory/internal/Utf8Test.java | 517 -----------------
.../memory/internal/WritableDirectCopyTest.java | 24 +-
.../memory/internal/WritableMemoryTest.java | 24 +-
.../datasketches/memory/internal/XxHash64Test.java | 6 -
.../memory/internal/ZeroCapacityTest.java | 2 +-
tools/MemoryCheckstyle.xml | 2 +-
44 files changed, 592 insertions(+), 1910 deletions(-)
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
index 4ba4ce0..b0a765f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseBuffer.java
@@ -21,9 +21,19 @@ package org.apache.datasketches.memory;
/**
* Defines the relative positional API.
- *
- * <p>The classes in this package are not thread-safe.</p>
- *
+ * This is different from and simpler than Java ByteBuffer positional API.
+ * <ul><li>All based on longs instead of ints.</li>
+ * <li>Eliminated "mark". Rarely used and confusing with its silent side effects.</li>
+ * <li>The invariants are {@code 0 <= start <= position <= end <= capacity}.</li>
+ * <li>It always starts up as (0, 0, capacity, capacity).</li>
+ * <li>You set (start, position, end) in one call with
+ * {@link #setStartPositionEnd(long, long, long)}</li>
+ * <li>Position can be set directly or indirectly when using the positional get/put methods.
+ * <li>Added incrementPosition(long), which is much easier when you know the increment.</li>
+ * <li>This approach eliminated a number of methods and checks, and has no unseen side effects,
+ * e.g., mark being invalidated.</li>
+ * <li>Clearer method naming (IMHO).</li>
+ * </ul>
* @author Lee Rhodes
*/
public interface BaseBuffer extends Resource {
@@ -85,14 +95,27 @@ public interface BaseBuffer extends Resource {
/**
* Sets the current position.
+ * Asserts that the positional invariants are not violated,
+ * otherwise, if asserts are enabled throws an {@link AssertionError}.
* @param position the given current position.
* @return BaseBuffer
* @throws BufferPositionInvariantsException if positional invariants have been violated.
*/
BaseBuffer setPosition(long position);
+ /**
+ * Sets the current position.
+ * Checks that the positional invariants are not violated,
+ * otherwise, throws an {@link IllegalArgumentException}.
+ * @param position the given current position.
+ * @return BaseBuffer
+ */
+ BaseBuffer setAndCheckPosition(long position);
+
/**
* Sets start position, current position, and end position.
+ * Asserts that the positional invariants are not violated,
+ * otherwise, if asserts are enabled throws an {@link AssertionError}.
* @param start the start position in the buffer
* @param position the current position between the start and end
* @param end the end position in the buffer
@@ -101,4 +124,15 @@ public interface BaseBuffer extends Resource {
*/
BaseBuffer setStartPositionEnd(long start, long position, long end);
+ /**
+ * Sets start position, current position, and end position.
+ * Checks that the positional invariants are not violated,
+ * otherwise, throws an {@link IllegalArgumentException}.
+ * @param start the start position in the buffer
+ * @param position the current position between the start and end
+ * @param end the end position in the buffer
+ * @return BaseBuffer
+ */
+ BaseBuffer setAndCheckStartPositionEnd(long start, long position, long end);
+
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
index c6d4156..507b83f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
@@ -19,52 +19,54 @@
package org.apache.datasketches.memory;
-import static org.apache.datasketches.memory.internal.Util.negativeCheck;
-
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.util.Objects;
import org.apache.datasketches.memory.internal.BaseWritableBufferImpl;
/**
* Defines the read-only API for relative positional access to a resource.
*
- * <p>The classes in this package are not thread-safe.</p>
- *
* @author Lee Rhodes
*/
public interface Buffer extends BaseBuffer {
//BYTE BUFFER
/**
- * Accesses the given ByteBuffer for read-only operations. The returned Buffer object has the
- * same byte order, as the given ByteBuffer.
+ * Provides a view of the given <i>ByteBuffer</i> for read-only operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * However, the returned <i>WritableBuffer</i> will have a position and end set to the
+ * ByteBuffer's position and limit, respectively.
+ * The returned WritableBuffer will use the native <i>ByteOrder</i>,
+ * ignoring the ByteOrder of the given ByteBuffer.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
* @param byteBuffer the given ByteBuffer, must not be null.
- * @return a new Buffer for read-only operations on the given ByteBuffer.
+ * @return a new <i>Buffer</i> for read-only operations on the given ByteBuffer.
*/
static Buffer wrap(ByteBuffer byteBuffer) {
return wrap(byteBuffer, byteBuffer.order());
}
/**
- * Accesses the given ByteBuffer for read-only operations. The returned Buffer object has
- * the given byte order, ignoring the byte order of the given ByteBuffer.
- * @param byteBuffer the given ByteBuffer, must not be null
- * @param byteOrder the byte order to be used, which may be independent of the byte order
- * state of the given ByteBuffer
- * @return a new Buffer for read-only operations on the given ByteBuffer.
+ * Provides a view of the given <i>ByteBuffer</i> for read-only operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * However, the returned <i>WritableBuffer</i> will have a position and end set to the
+ * ByteBuffer's position and limit, respectively.
+ * The returned WritableBuffer will use the native <i>ByteOrder</i>,
+ * ignoring the ByteOrder of the given ByteBuffer.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given ByteBuffer. It must be non-null
+ * @param byteOrder the ByteOrder to be used. It must be non-null.
+ * @return a new <i>Buffer</i> for read-only operations on the given ByteBuffer.
*/
static Buffer wrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
- Objects.requireNonNull(byteBuffer, "byteBuffer must not be null");
- Objects.requireNonNull(byteOrder, "byteOrder must not be null");
- negativeCheck(byteBuffer.capacity(), "byteBuffer");
return BaseWritableBufferImpl.wrapByteBuffer(byteBuffer, true, byteOrder, null);
}
//DUPLICATES
/**
- * Returns a read-only duplicate view of this Buffer with the same but independent values of
+ * Returns a read-only duplicate view of this Buffer with the same byte order,
+ * but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
* <ul>
* <li>Returned object's origin = this object's origin</li>
@@ -78,7 +80,9 @@ public interface Buffer extends BaseBuffer {
* @return a read-only duplicate view of this Buffer with the same but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
*/
- Buffer duplicate();
+ default Buffer duplicate() {
+ return duplicate(getTypeByteOrder());
+ }
/**
* Returns a read-only duplicate view of this Buffer with the same but independent values of
@@ -98,11 +102,13 @@ public interface Buffer extends BaseBuffer {
*/
Buffer duplicate(ByteOrder byteOrder);
- //NO MAP
+ //NO MAP use Memory
+ //NO ALLOCATE DIRECT, makes no sense
//REGIONS
/**
- * A region is a read-only view of this object.
+ * A region is a read-only view of this object from <i>position</i> to <i>end</i>
+ * and with the same byte order.
* <ul>
* <li>Returned object's origin = this object's <i>position</i></li>
* <li>Returned object's <i>start</i> = 0</li>
@@ -115,10 +121,13 @@ public interface Buffer extends BaseBuffer {
* @return a new <i>Buffer</i> representing the defined region based on the current
* <i>position</i> and <i>end</i>.
*/
- Buffer region();
+ default Buffer region() {
+ return region(getPosition(), getEnd() - getPosition(), getTypeByteOrder());
+ }
/**
- * A region is a read-only view of this object.
+ * A region is a read-only view of this object from offsetBytes and with a length of
+ * capacityBytes and with the given byte order.
* <ul>
* <li>Returned object's origin = this objects' origin + <i>offsetBytes</i></li>
* <li>Returned object's <i>start</i> = 0</li>
@@ -145,7 +154,7 @@ public interface Buffer extends BaseBuffer {
* @return Memory
*/
default Memory asMemory() {
- return asMemory(getByteOrder());
+ return asMemory(getTypeByteOrder());
}
/**
@@ -156,12 +165,16 @@ public interface Buffer extends BaseBuffer {
*/
Memory asMemory(ByteOrder byteOrder);
- //NO ACCESS PRIMITIVE HEAP ARRAYS for readOnly
+ //NO ALLOCATE HEAP BYTE ARRAYS, makes no sense. Use WritableMemory
+ //NO WRAP - ACCESS PRIMITIVE HEAP ARRAYS for readOnly.
+ // Because of the ambiguity of positional API with the multibyte primitives. Use Memory instead.
+ //END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE getX() and getXArray()
+
/**
* Gets the boolean value at the current position.
- * Increments the position by 1.
+ * Increments the position by <i>Byte.BYTES</i>.
* @return the boolean at the current position
*/
boolean getBoolean();
@@ -174,15 +187,6 @@ public interface Buffer extends BaseBuffer {
*/
boolean getBoolean(long offsetBytes);
- /**
- * Gets the boolean array at the current position.
- * Increments the position by <i>lengthBooleans - dstOffsetBooleans</i>.
- * @param dstArray The preallocated destination array.
- * @param dstOffsetBooleans offset in array units
- * @param lengthBooleans number of array units to transfer
- */
- void getBooleanArray(boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans);
-
/**
* Gets the byte value at the current position.
* Increments the position by <i>Byte.BYTES</i>.
@@ -351,7 +355,9 @@ public interface Buffer extends BaseBuffer {
*/
void getShortArray(short[] dstArray, int dstOffsetShorts, int lengthShorts);
- //SPECIAL PRIMITIVE READ METHODS: compareTo
+ //SPECIAL PRIMITIVE READ METHODS: compareTo.
+ // No copyTo, No writeTo. Use Memory for that.
+
/**
* Compares the bytes of this Buffer to <i>that</i> Buffer.
* This uses absolute offsets not the start, position and end.
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
index f8f828c..51c2d2b 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
@@ -73,7 +73,7 @@ public final class DefaultMemoryRequestServer implements MemoryRequestServer {
*/
@Override
public WritableMemory request(final WritableMemory currentWritableMemory, final long capacityBytes) {
- final WritableMemory wmem = WritableMemory.allocate((int)capacityBytes, currentWritableMemory.getByteOrder());
+ final WritableMemory wmem = WritableMemory.allocate((int)capacityBytes, currentWritableMemory.getTypeByteOrder());
return wmem;
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
index eed7a4e..461c247 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -19,8 +19,6 @@
package org.apache.datasketches.memory;
-import static org.apache.datasketches.memory.internal.Util.negativeCheck;
-
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -35,8 +33,6 @@ import org.apache.datasketches.memory.internal.ResourceImpl;
/**
* Defines the read-only API for offset access to a resource.
*
- * <p>The classes in this package are not thread-safe.</p>
- *
* @author Lee Rhodes
*/
public interface Memory extends Resource {
@@ -44,9 +40,11 @@ public interface Memory extends Resource {
//BYTE BUFFER
/**
- * Accesses the given <i>ByteBuffer</i> for read-only operations. The returned <i>Memory</i> object has
- * the same byte order, as the given <i>ByteBuffer</i>.
- * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null and with capacity ≥ 0.
+ * Provides a view of the given <i>ByteBuffer</i> for read-only operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * The returned <i>WritableMemory</i> will use the <i>ByteOrder</i> of the <i>ByteBuffer</i>.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null.
* @return a new <i>Memory</i> for read-only operations on the given <i>ByteBuffer</i>.
*/
static Memory wrap(ByteBuffer byteBuffer) {
@@ -54,48 +52,58 @@ public interface Memory extends Resource {
}
/**
- * Accesses the given <i>ByteBuffer</i> for read-only operations. The returned <i>Memory</i> object has
- * the given byte order, ignoring the byte order of the given <i>ByteBuffer</i> for future reads and writes.
- * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null and with capacity ≥ 0.
+ * Provides a view of the given <i>ByteBuffer</i> for read-only operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * The returned <i>WritableMemory</i> will use the given <i>ByteOrder</i>,
+ * independent of the ByteOrder of the given ByteBuffer.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null.
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>Memory</i> for read-only operations on the given <i>ByteBuffer</i>.
*/
static Memory wrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
- Objects.requireNonNull(byteBuffer, "byteBuffer must not be null");
- Objects.requireNonNull(byteOrder, "byteOrder must not be null");
- negativeCheck(byteBuffer.capacity(), "byteBuffer");
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuffer, true, byteOrder, null);
}
+ //Duplicates make no sense here
+
//MAP
/**
- * Maps the entire given file into native-ordered <i>Memory</i> for read operations
+ * Maps the given file into <i>Memory</i> for read operations
* Calling this method is equivalent to calling
- * {@link #map(File, long, long, ByteOrder) map(file, 0, file.length(), ByteOrder.nativeOrder())}.
- * @param file the given file to map. It must be non-null, length ≥ 0, and readable.
+ * {@link #map(File, long, long, ByteOrder)
+ * map(file, 0, file.length(), scope, ByteOrder.nativeOrder())}.
+ * @param file the given file to map. It must be non-null with a non-negative length and readable.
* @return <i>Memory</i> for managing the mapped memory.
+ * @throws IllegalArgumentException if path is not associated with the default file system.
+ * @throws IllegalStateException if scope has been already closed, or if access occurs from a thread other than the thread owning scope.
+ * @throws IOException if the specified path does not point to an existing file, or if some other I/O error occurs.
+ * @throws SecurityException If a security manager is installed and it denies an unspecified permission
+ * required by the implementation.
*/
- static Memory map(File file) {
+ static Memory map(File file) throws IOException {
return map(file, 0, file.length(), ByteOrder.nativeOrder());
}
/**
* Maps the specified portion of the given file into <i>Memory</i> for read operations.
- * @param file the given file to map. It must be non-null and readable.
- * @param fileOffsetBytes the position in the given file in bytes. It must not be negative.
- * @param capacityBytes the size of the mapped memory. It must not be negative.
- * @param byteOrder the byte order to be used for the mapped memory. It must be non-null.
+ * @param file the given file to map. It must be non-null, readable and length ≥ 0.
+ * @param fileOffsetBytes the position in the given file in bytes. It must ≥ 0.
+ * @param capacityBytes the size of the mapped memory. It must be ≥ 0.
+ * @param byteOrder the byte order to be used. It must be non-null.
* @return <i>Memory</i> for managing the mapped memory.
+ * @throws IllegalArgumentException if path is not associated with the default file system.
+ * @throws IllegalStateException if scope has been already closed, or if access occurs from a thread other than the thread owning scope.
+ * @throws IOException if the specified path does not point to an existing file, or if some other I/O error occurs.
+ * @throws SecurityException If a security manager is installed and it denies an unspecified permission
+ * required by the implementation.
*/
- static Memory map(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) {
- Objects.requireNonNull(file, "file must be non-null.");
- Objects.requireNonNull(byteOrder, "byteOrder must be non-null.");
- if (!file.canRead()) { throw new ReadOnlyException("file must be readable."); }
- negativeCheck(fileOffsetBytes, "fileOffsetBytes");
- negativeCheck(capacityBytes, "capacityBytes");
+ static Memory map(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) throws IOException {
return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, capacityBytes, true, byteOrder);
}
+ //NO ALLOCATE DIRECT, makes no sense
+
//REGIONS
/**
* A region is a read-only view of this object.
@@ -109,7 +117,7 @@ public interface Memory extends Resource {
* offsetBytes and capacityBytes.
*/
default Memory region(long offsetBytes, long capacityBytes) {
- return region(offsetBytes, capacityBytes, ByteOrder.nativeOrder());
+ return region(offsetBytes, capacityBytes, getTypeByteOrder());
}
/**
@@ -141,7 +149,7 @@ public interface Memory extends Resource {
* @return a new <i>Buffer</i>
*/
default Buffer asBuffer() {
- return asBuffer(ByteOrder.nativeOrder());
+ return asBuffer(getTypeByteOrder());
}
/**
@@ -155,15 +163,17 @@ public interface Memory extends Resource {
* <li>Returned object's <i>capacity</i> = this object's capacity</li>
* <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
* </ul>
- * @param byteOrder the given byte order
+ * @param byteOrder the given byte order. It must be non-null.
* @return a new <i>Buffer</i> with the given byteOrder.
*/
Buffer asBuffer(ByteOrder byteOrder);
- //ACCESS PRIMITIVE HEAP ARRAYS for readOnly
+ //NO ALLOCATE HEAP BYTE ARRAYS, makes no sense
+
+ //WRAP - ACCESS PRIMITIVE HEAP ARRAYS for readOnly
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(byte[] array) {
@@ -173,8 +183,8 @@ public interface Memory extends Resource {
/**
* Wraps the given primitive array for read operations with the given byte order.
- * @param array the given primitive array.
- * @param byteOrder the byte order to be used
+ * @param array the given primitive array. It must be non-null.
+ * @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(byte[] array, ByteOrder byteOrder) {
@@ -183,35 +193,21 @@ public interface Memory extends Resource {
/**
* Wraps the given primitive array for read operations with the given byte order.
- * @param array the given primitive array.
- * @param offsetBytes the byte offset into the given array
- * @param lengthBytes the number of bytes to include from the given array
- * @param byteOrder the byte order to be used
+ * @param array the given primitive array. It must be non-null.
+ * @param offsetBytes the byte offset into the given array. It must be ≥ 0.
+ * @param lengthBytes the number of bytes to include from the given array. It must be ≥ 0.
+ * @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(byte[] array, int offsetBytes, int lengthBytes, ByteOrder byteOrder) {
Objects.requireNonNull(array, "array must be non-null");
- Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
- negativeCheck(offsetBytes, "offsetBytes");
- negativeCheck(lengthBytes, "lengthBytes");
ResourceImpl.checkBounds(offsetBytes, lengthBytes, array.length);
return BaseWritableMemoryImpl.wrapHeapArray(array, offsetBytes, lengthBytes, true, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
- static Memory wrap(boolean[] array) {
- Objects.requireNonNull(array, "array must be non-null");
- final long lengthBytes = array.length << Prim.BOOLEAN.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0, lengthBytes, true, ByteOrder.nativeOrder(), null);
- }
-
- /**
- * Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(char[] array) {
@@ -222,60 +218,62 @@ public interface Memory extends Resource {
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(short[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.SHORT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, true, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(int[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.INT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, true, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(long[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.LONG.shift();
return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, true, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(float[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.FLOAT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, true, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for read operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new <i>Memory</i> for read operations
*/
static Memory wrap(double[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.DOUBLE.shift();
return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, true, ByteOrder.nativeOrder(), null);
}
+ //END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE getX() and getXArray()
+
/**
* Gets the boolean value at the given offset
* @param offsetBytes offset bytes relative to this Memory start
@@ -283,15 +281,6 @@ public interface Memory extends Resource {
*/
boolean getBoolean(long offsetBytes);
- /**
- * Gets the boolean array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetBooleans offset in array units
- * @param lengthBooleans number of array units to transfer
- */
- void getBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans);
-
/**
* Gets the byte value at the given offset
* @param offsetBytes offset bytes relative to this Memory start
@@ -324,43 +313,6 @@ public interface Memory extends Resource {
*/
void getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars);
- /**
- * Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
- * utf8LengthBytes, decodes them into characters and appends them to the given Appendable.
- * This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- * @param offsetBytes offset bytes relative to the Memory start
- * @param utf8LengthBytes the number of encoded UTF-8 bytes to decode. It is assumed that the
- * caller has the correct number of utf8 bytes required to decode the number of characters
- * to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
- * character to decode.
- * @param dst the destination Appendable to append the decoded characters to.
- * @return the number of characters decoded
- * @throws IOException if dst.append() throws IOException
- * @throws Utf8CodingException in case of malformed or illegal UTF-8 input
- */
- int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst)
- throws IOException, Utf8CodingException;
-
- /**
- * Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
- * utf8LengthBytes, decodes them into characters and appends them to the given StringBuilder.
- * This method does *not* reset the length of the destination StringBuilder before appending
- * characters to it.
- * This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- * @param offsetBytes offset bytes relative to the Memory start
- * @param utf8LengthBytes the number of encoded UTF-8 bytes to decode. It is assumed that the
- * caller has the correct number of utf8 bytes required to decode the number of characters
- * to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
- * character to decode.
- * @param dst the destination StringBuilder to append decoded characters to.
- * @return the number of characters decoded.
- * @throws Utf8CodingException in case of malformed or illegal UTF-8 input
- */
- int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, StringBuilder dst)
- throws Utf8CodingException;
-
/**
* Gets the double value at the given offset
* @param offsetBytes offset bytes relative to this Memory start
@@ -442,6 +394,7 @@ public interface Memory extends Resource {
void getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts);
//SPECIAL PRIMITIVE READ METHODS: compareTo, copyTo, writeTo
+
/**
* Compares the bytes of this Memory to <i>that</i> Memory.
* Returns <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
index e2ca235..6bef2c6 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
@@ -31,11 +31,11 @@ public interface MemoryRequestServer {
* Request new WritableMemory with the given capacity. The current Writable Memory will be used to
* determine the byte order of the returned WritableMemory and other checks.
* @param currentWritableMemory the current writableMemory of the client. It must be non-null.
- * @param capacityBytes The capacity being requested. It must be ≥ 0.
+ * @param newCapacityBytes The capacity being requested. It must be ≥ 0.
*
* @return new WritableMemory with the given capacity.
*/
- WritableMemory request(WritableMemory currentWritableMemory, long capacityBytes);
+ WritableMemory request(WritableMemory currentWritableMemory, long newCapacityBytes);
/**
* Request close the AutoCloseable resource. This only applies to resources allocated using
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
index a7b27e2..2f841b8 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
@@ -23,14 +23,18 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
- * Methods common to all memory access resources, including attributes like byte order and capacity.
- *
- * <p>The classes in this package are not thread-safe.</p>
+ * The base class for Memory and Buffer plus some common static variables
+ * and check methods.
*
* @author Lee Rhodes
*/
public interface Resource extends AutoCloseable {
+ /**
+ * The java line separator character as a String.
+ */
+ static final String LS = System.getProperty("line.separator");
+
static MemoryRequestServer defaultMemReqSvr = null; //policy choice
/**
@@ -106,7 +110,7 @@ public interface Resource extends AutoCloseable {
* This may be different from the ByteOrder of the backing resource and {@link ByteOrder#nativeOrder()}
* @return the current ByteOrder.
*/
- ByteOrder getByteOrder();
+ ByteOrder getTypeByteOrder();
/**
* Gets the capacity of this object in bytes
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
index 89c7845..adff4ce 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
@@ -21,49 +21,52 @@ package org.apache.datasketches.memory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.util.Objects;
import org.apache.datasketches.memory.internal.BaseWritableBufferImpl;
-import org.apache.datasketches.memory.internal.Util;
/**
* Defines the writable API for relative positional access to a resource
*
- * <p>The classes in this package are not thread-safe.</p>
- *
* @author Lee Rhodes
*/
public interface WritableBuffer extends Buffer {
//BYTE BUFFER
/**
- * Accesses the given <i>ByteBuffer</i> for write operations. The returned <i>WritableBuffer</i> object has
- * the same byte order, as the given <i>ByteBuffer</i>.
- * @param byteBuf the given ByteBuffer. It must be non-null and with capacity ≥ 0.
+ * Provides a view of the given <i>ByteBuffer</i> for write operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * However, the returned <i>WritableBuffer</i> will have a position and end set to the
+ * ByteBuffer's position and limit, respectively.
+ * The returned WritableBuffer will use the native <i>ByteOrder</i>,
+ * ignoring the ByteOrder of the given ByteBuffer.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given ByteBuffer. It must be non-null and writable.
* @return a new <i>WritableBuffer</i> for write operations on the given <i>ByteBuffer</i>.
*/
- static WritableBuffer writableWrap(ByteBuffer byteBuf) {
- return writableWrap(byteBuf, byteBuf.order(), defaultMemReqSvr);
+ static WritableBuffer writableWrap(ByteBuffer byteBuffer) {
+ return writableWrap(byteBuffer, byteBuffer.order(), defaultMemReqSvr);
}
/**
- * Accesses the given <i>ByteBuffer</i> for write operations. The returned <i>WritableBuffer</i> object has
- * the given byte order, ignoring the byte order of the given <i>ByteBuffer</i> for future writes and following reads.
- * However, this does not change the byte order of data already in the <i>ByteBuffer</i>.
- * @param byteBuf the given ByteBuffer. It must be non-null and with capacity ≥ 0.
- * @param byteOrder the byte order to be used.
- * @param memReqSvr A user-specified <i>MemoryRequestServer</i>, which must not be null.
- * This is a callback mechanism for a user client to request a larger <i>WritableBuffer</i>.
+ * Provides a view of the given <i>ByteBuffer</i> for write operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * However, the returned <i>WritableBuffer</i> will have a position and end set to the
+ * ByteBuffer's position and limit, respectively.
+ * The returned WritableBuffer will use the native <i>ByteOrder</i>,
+ * ignoring the ByteOrder of the given ByteBuffer.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given ByteBuffer. It must be non-null and writable.
+ * @param byteOrder the byte order to be used. It must be non-null.
+ * @param memReqSvr A user-specified <i>MemoryRequestServer</i>, which may be null.
+ * This is a callback mechanism for a user client to request more memory.
* @return a new <i>WritableBuffer</i> for write operations on the given <i>ByteBuffer</i>.
+ * @throws IllegalArgumentException if ByteBuffer is not writable
*/
- static WritableBuffer writableWrap(ByteBuffer byteBuf, ByteOrder byteOrder, MemoryRequestServer memReqSvr) {
- Objects.requireNonNull(byteBuf, "ByteBuffer 'byteBuf' must not be null");
- Objects.requireNonNull(byteOrder, "ByteOrder 'byteOrder' must not be null");
- Util.negativeCheck(byteBuf.capacity(), "byteBuf.capacity");
- if (byteBuf.isReadOnly()) {
+ static WritableBuffer writableWrap(ByteBuffer byteBuffer, ByteOrder byteOrder, MemoryRequestServer memReqSvr) {
+ if (byteBuffer.isReadOnly()) {
throw new ReadOnlyException("Cannot create a WritableBuffer from a ReadOnly ByteBuffer.");
}
- return BaseWritableBufferImpl.wrapByteBuffer(byteBuf, false, byteOrder, memReqSvr);
+ return BaseWritableBufferImpl.wrapByteBuffer(byteBuffer, false, byteOrder, memReqSvr);
}
// NO MAP
@@ -99,12 +102,15 @@ public interface WritableBuffer extends Buffer {
* <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable and
* independent of this object's <i>start</i>, <i>position</i> and <i>end</i></li>
* </ul>
- * @param byteOrder the given <i>ByteOrder</i>.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
* @return a duplicate writable view of this Buffer with the same but independent values of
* <i>start</i>, <i>position</i> and <i>end</i>.
*/
WritableBuffer writableDuplicate(ByteOrder byteOrder);
+ // NO MAP use WritableMemory
+ // NO ALLOCATE DIRECT use WritableMemory
+
//REGIONS
/**
* A writable region is a writable view of this object.
@@ -138,12 +144,11 @@ public interface WritableBuffer extends Buffer {
* will return the originating <i>Memory</i> byte order.</p>
* @param offsetBytes the starting offset with respect to the origin of this <i>WritableBuffer</i>
* @param capacityBytes the <i>capacity</i> of the returned region in bytes
- * @param byteOrder the given byte order
+ * @param byteOrder the given byte order. It must be non-null.
* @return a new <i>WritableBuffer</i> representing the defined writable region
* with the given offsetBytes, capacityBytes and byte order.
*/
- WritableBuffer writableRegion(long offsetBytes, long capacityBytes,
- ByteOrder byteOrder);
+ WritableBuffer writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
//AS WRITABLE MEMORY
/**
@@ -160,19 +165,21 @@ public interface WritableBuffer extends Buffer {
* Convert this WritableBuffer to a WritableMemory with the given byte order.
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing storage and byte order are unspecified.
- * @param byteOrder the byte order to be used.
+ * @param byteOrder the byte order to be used. It must be non-null.
* @return WritableMemory
*/
WritableMemory asWritableMemory(ByteOrder byteOrder);
- //NO ALLOCATE HEAP VIA AUTOMATIC BYTE ARRAY
-
+ //NO ALLOCATE HEAP BYTE ARRAY use WritableMemory
+ //NO WRITABLE WRAP -- ACCESS PRIMITIVE HEAP ARRAYS for WRITE
//NO ACCESS PRIMITIVE HEAP ARRAYS for WRITE
+ //END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE putX() and putXArray()
+
/**
* Puts the boolean value at the current position.
- * Increments the position by 1.
+ * Increments the position by <i>Byte.BYTES</i>.
* @param value the value to put
*/
void putBoolean(boolean value);
@@ -185,16 +192,6 @@ public interface WritableBuffer extends Buffer {
*/
void putBoolean(long offsetBytes, boolean value);
- /**
- * Puts the boolean array at the current position.
- * Increments the position by <i>lengthBooleans - srcOffsetBooleans</i>.
- * @param srcArray The source array.
- * @param srcOffsetBooleans offset in array units
- * @param lengthBooleans number of array units to transfer
- */
- void putBooleanArray(boolean[] srcArray, int srcOffsetBooleans,
- int lengthBooleans);
-
/**
* Puts the byte value at the current position.
* Increments the position by <i>Byte.BYTES</i>.
@@ -385,4 +382,6 @@ public interface WritableBuffer extends Buffer {
//NO setBits(...)
+ //NO OTHER WRITABLE API METHODS
+
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index e2dcdd0..ff4c5a5 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -22,6 +22,7 @@ package org.apache.datasketches.memory;
import static org.apache.datasketches.memory.internal.Util.negativeCheck;
import java.io.File;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Objects;
@@ -33,120 +34,122 @@ import org.apache.datasketches.memory.internal.ResourceImpl;
/**
* Defines the writable API for offset access to a resource.
*
- * <p>The classes in this package are not thread-safe.</p>
- *
* @author Lee Rhodes
*/
public interface WritableMemory extends Memory {
//BYTE BUFFER
/**
- * Accesses the given <i>ByteBuffer</i> for write operations. The returned <i>WritableMemory</i> object has
- * the same byte order, as the given <i>ByteBuffer</i>.
- * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null, with capacity ≥ 0, and writable.
+ * Provides a view of the given <i>ByteBuffer</i> for write operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * The returned <i>WritableMemory</i> will assume the <i>ByteOrder</i> of the given <i>ByteBuffer</i>.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null and writable.
* @return a new <i>WritableMemory</i> for write operations on the given <i>ByteBuffer</i>.
*/
static WritableMemory writableWrap(ByteBuffer byteBuffer) {
- return writableWrap(byteBuffer, byteBuffer.order(), defaultMemReqSvr);
- }
-
- /**
- * Accesses the given <i>ByteBuffer</i> for write operations. The returned <i>WritableMemory</i> object has
- * the given byte order, ignoring the byte order of the given <i>ByteBuffer</i> for future writes and following reads.
- * However, this does not change the byte order of data already in the <i>ByteBuffer</i>.
- * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null, with capacity ≥ 0, and writable.
- * @param byteOrder the byte order to be used. It must be non-null.
- * @return a new <i>WritableMemory</i> for write operations on the given <i>ByteBuffer</i>.
- */
- static WritableMemory writableWrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
- return writableWrap(byteBuffer, byteOrder, defaultMemReqSvr);
+ return writableWrap(byteBuffer, byteBuffer.order(), null);
}
/**
- * Accesses the given <i>ByteBuffer</i> for write operations. The returned <i>WritableMemory</i> object has
- * the given byte order, ignoring the byte order of the given <i>ByteBuffer</i> for future reads and writes.
- * However, this does not change the byte order of data already in the <i>ByteBuffer</i>.
- * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null, with capacity ≥ 0, and writable.
+ * Provides a view of the given <i>ByteBuffer</i> for write operations.
+ * The view is of the entire ByteBuffer independent of position and limit.
+ * The returned <i>WritableMemory</i> will assume the given <i>ByteOrder</i>,
+ * independent of the ByteOrder of the given ByteBuffer.
+ * This does not affect the ByteOrder of data already in the ByteBuffer.
+ * @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null and writable.
* @param byteOrder the byte order to be used. It must be non-null.
* @param memReqSvr A user-specified <i>MemoryRequestServer</i>, which may be null.
* This is a callback mechanism for a user client to request a larger <i>WritableMemory</i>.
* @return a new <i>WritableMemory</i> for write operations on the given <i>ByteBuffer</i>.
+ * @throws IllegalArgumentException if ByteBuffer is not writable.
*/
- static WritableMemory writableWrap(ByteBuffer byteBuffer, ByteOrder byteOrder, MemoryRequestServer memReqSvr) {
- Objects.requireNonNull(byteBuffer, "byteBuffer must be non-null");
- Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
- negativeCheck(byteBuffer.capacity(), "byteBuffer");
+ static WritableMemory writableWrap(
+ ByteBuffer byteBuffer,
+ ByteOrder byteOrder,
+ MemoryRequestServer memReqSvr) {
if (byteBuffer.isReadOnly()) { throw new ReadOnlyException("byteBuffer must be writable."); }
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuffer, false, byteOrder, memReqSvr);
}
+ //Duplicates make no sense here
+
//MAP
/**
* Maps the entire given file into native-ordered WritableMemory for write operations
* Calling this method is equivalent to calling
* {@link #writableMap(File, long, long, ByteOrder) writableMap(file, 0, file.length(), ByteOrder.nativeOrder())}.
- * @param file the given file to map. It must be non-null, with length ≥ 0, and writable.
- * @return WritableMemory for managing the mapped Memory.
- */
- static WritableMemory writableMap(File file) {
+ * @param file the given file to map. It must be non-null and writable.
+ * @return a file-mapped WritableMemory
+ * @throws IllegalArgumentException if file is not readable or not writable.
+ * @throws IOException if the specified path does not point to an existing file, or if some other I/O error occurs.
+ * @throws SecurityException If a security manager is installed and it denies an unspecified permission
+ * required by the implementation.
+ */
+ static WritableMemory writableMap(File file) throws IOException {
return writableMap(file, 0, file.length(), ByteOrder.nativeOrder());
}
/**
* Maps the specified portion of the given file into Memory for write operations.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.map(...)</i>.
- * @param file the given file to map. It must be non-null, writable and length ≥ 0.
- * @param fileOffsetBytes the position in the given file in bytes. It must not be negative.
- * @param capacityBytes the size of the mapped Memory. It must not be negative.
- * @param byteOrder the byte order to be used for the given file. It must be non-null.
- * @return WritableMemory for managing the mapped Memory.
- */
- static WritableMemory writableMap(File file, long fileOffsetBytes, long capacityBytes, ByteOrder byteOrder) {
- Objects.requireNonNull(file, "file must be non-null.");
- Objects.requireNonNull(byteOrder, "byteOrder must be non-null.");
+ * @param file the given file to map. It must be non-null and writable.
+ * @param fileOffsetBytes the position in the given file in bytes. It must be ≥ 0.
+ * @param capacityBytes the size of the mapped Memory. It must be ≥ 0.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
+ * @return a file-mapped WritableMemory.
+ * @throws IllegalArgumentException if file is not readable or not writable.
+ * @throws IOException if the specified path does not point to an existing file, or if some other I/O error occurs.
+ * @throws SecurityException If a security manager is installed and it denies an unspecified permission
+ * required by the implementation.
+ */
+ static WritableMemory writableMap(
+ File file,
+ long fileOffsetBytes,
+ long capacityBytes,
+ ByteOrder byteOrder) throws IOException {
if (!file.canWrite()) { throw new ReadOnlyException("file must be writable."); }
- negativeCheck(file.length(), "file.length()");
- negativeCheck(fileOffsetBytes, "fileOffsetBytes");
- negativeCheck(capacityBytes, "capacityBytes");
return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, capacityBytes, false, byteOrder);
}
//ALLOCATE DIRECT
+
/**
* Allocates and provides access to capacityBytes directly in native (off-heap) memory.
* Native byte order is assumed.
- * The allocated memory will be 8-byte aligned, but may not be page aligned.
+ * The allocated memory will be 8-byte aligned.
*
* <p><b>NOTE:</b> Native/Direct memory acquired may have garbage in it.
* It is the responsibility of the using application to clear this memory, if required,
* and to call <i>close()</i> when done.</p>
*
- * @param capacityBytes the size of the desired memory in bytes. It must be ≥ 0.
- * @return WritableMemory for this off-heap resource.
+ * @param capacityBytes the size of the desired memory in bytes.
+ * @param memReqSvr A user-specified MemoryRequestServer, which may be null.
+ * @return WritableMemory for this off-heap, native resource.
*/
- static WritableMemory allocateDirect(long capacityBytes) {
- return allocateDirect(capacityBytes, ByteOrder.nativeOrder(), defaultMemReqSvr);
+ static WritableMemory allocateDirect(
+ long capacityBytes,
+ MemoryRequestServer memReqSvr) {
+ return allocateDirect(capacityBytes, ByteOrder.nativeOrder(), memReqSvr);
}
/**
* Allocates and provides access to capacityBytes directly in native (off-heap) memory.
- * The allocated memory will be 8-byte aligned, but may not be page aligned.
+ * The allocated memory will be 8-byte aligned.
*
* <p><b>NOTE:</b> Native/Direct memory acquired may have garbage in it.
* It is the responsibility of the using application to clear this memory, if required,
* and to call <i>close()</i> when done.</p>
*
- * @param capacityBytes the size of the desired memory in bytes. It must be ≥ 0.
- * @param byteOrder the given byte order. It must be non-null.
+ * @param capacityBytes the size of the desired memory in bytes.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
* @param memReqSvr A user-specified MemoryRequestServer, which may be null.
* This is a callback mechanism for a user client of direct memory to request more memory.
- * @return WritableMemory for this off-heap resource.
+ * @return a WritableMemory for this off-heap resource.
*/
- static WritableMemory allocateDirect(long capacityBytes, ByteOrder byteOrder, MemoryRequestServer memReqSvr) {
- Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
- negativeCheck(capacityBytes, "capacityBytes");
+ static WritableMemory allocateDirect(
+ long capacityBytes,
+ ByteOrder byteOrder,
+ MemoryRequestServer memReqSvr) {
return BaseWritableMemoryImpl.wrapDirect(capacityBytes, byteOrder, memReqSvr);
}
@@ -160,12 +163,14 @@ public interface WritableMemory extends Memory {
* <li>Returned object's capacity = <i>capacityBytes</i></li>
* </ul>
*
- * @param regionOffsetBytes the starting offset with respect to this object. It must be ≥ 0.
+ * @param offsetBytes the starting offset with respect to this object. It must be ≥ 0.
* @param capacityBytes the capacity of the returned object in bytes. It must be ≥ 0.
* @return a new <i>WritableMemory</i> representing the defined writable region.
*/
- default WritableMemory writableRegion(long regionOffsetBytes, long capacityBytes) {
- return writableRegion(regionOffsetBytes, capacityBytes, getByteOrder());
+ default WritableMemory writableRegion(
+ long offsetBytes,
+ long capacityBytes) {
+ return writableRegion(offsetBytes, capacityBytes, getTypeByteOrder());
}
/**
@@ -178,12 +183,15 @@ public interface WritableMemory extends Memory {
* <li>Returned object's byte order = <i>byteOrder</i></li>
* </ul>
*
- * @param offsetBytes the starting offset with respect to this object. It must be ≥ 0.
- * @param capacityBytes the capacity of the returned object in bytes. It must be ≥ 0.
- * @param byteOrder the given byte order. It must be non-null.
+ * @param offsetBytes the starting offset with respect to this object.
+ * @param capacityBytes the capacity of the returned object in bytes.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
* @return a new <i>WritableMemory</i> representing the defined writable region.
*/
- WritableMemory writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+ WritableMemory writableRegion(
+ long offsetBytes,
+ long capacityBytes,
+ ByteOrder byteOrder);
//AS WRITABLE BUFFER
/**
@@ -199,7 +207,7 @@ public interface WritableMemory extends Memory {
* @return a new <i>WritableBuffer</i> with a view of this WritableMemory
*/
default WritableBuffer asWritableBuffer() {
- return asWritableBuffer(getByteOrder());
+ return asWritableBuffer(getTypeByteOrder());
}
/**
@@ -213,46 +221,52 @@ public interface WritableMemory extends Memory {
* <li>Returned object's <i>capacity</i> = this object's capacity</li>
* <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
* </ul>
- * @param byteOrder the given byte order
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
* @return a new <i>WritableBuffer</i> with a view of this WritableMemory
*/
WritableBuffer asWritableBuffer(ByteOrder byteOrder);
- //ALLOCATE HEAP VIA AUTOMATIC BYTE ARRAY
+ //ALLOCATE HEAP BYTE ARRAYS
+
/**
* Creates on-heap WritableMemory with the given capacity and the native byte order.
- * @param capacityBytes the given capacity in bytes. It must be ≥ 0.
+ * @param capacityBytes the given capacity in bytes.
* @return a new WritableMemory for write operations on a new byte array.
*/
static WritableMemory allocate(int capacityBytes) {
- return allocate(capacityBytes, ByteOrder.nativeOrder(), defaultMemReqSvr);
+ return allocate(capacityBytes, ByteOrder.nativeOrder(), null);
}
/**
* Creates on-heap WritableMemory with the given capacity and the given byte order.
- * @param capacityBytes the given capacity in bytes. It must be ≥ 0.
- * @param byteOrder the given byte order to allocate new Memory object with. It must be non-null.
+ * @param capacityBytes the given capacity in bytes.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
* @return a new WritableMemory for write operations on a new byte array.
*/
- static WritableMemory allocate(int capacityBytes, ByteOrder byteOrder) {
- return allocate(capacityBytes, byteOrder, defaultMemReqSvr);
+ static WritableMemory allocate(
+ int capacityBytes,
+ ByteOrder byteOrder) {
+ return allocate(capacityBytes, byteOrder, null);
}
/**
* Creates on-heap WritableMemory with the given capacity and the given byte order.
- * @param capacityBytes the given capacity in bytes. It must be ≥ 0.
- * @param byteOrder the given byte order to allocate new Memory object with. It must be non-null.
+ * @param capacityBytes the given capacity in bytes.
+ * @param byteOrder the given <i>ByteOrder</i>. It must be non-null.
* @param memReqSvr A user-specified <i>MemoryRequestServer</i>, which may be null.
* This is a callback mechanism for a user client to request a larger <i>WritableMemory</i>.
* @return a new WritableMemory for write operations on a new byte array.
*/
- static WritableMemory allocate(int capacityBytes, ByteOrder byteOrder, MemoryRequestServer memReqSvr) {
+ static WritableMemory allocate(
+ int capacityBytes,
+ ByteOrder byteOrder,
+ MemoryRequestServer memReqSvr) {
final byte[] arr = new byte[capacityBytes];
negativeCheck(capacityBytes, "capacityBytes");
return writableWrap(arr, 0, capacityBytes, byteOrder, memReqSvr);
}
- //ACCESS PRIMITIVE HEAP ARRAYS for WRITE
+ //WRITABLE WRAP - ACCESS PRIMITIVE HEAP ARRAYS for WRITE
/**
* Wraps the given primitive array for write operations assuming native byte order.
@@ -263,7 +277,7 @@ public interface WritableMemory extends Memory {
* @return a new WritableMemory for write operations on the given primitive array.
*/
static WritableMemory writableWrap(byte[] array) {
- return writableWrap(array, 0, array.length, ByteOrder.nativeOrder(), defaultMemReqSvr);
+ return writableWrap(array, 0, array.length, ByteOrder.nativeOrder(), null);
}
/**
@@ -275,8 +289,10 @@ public interface WritableMemory extends Memory {
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(byte[] array, ByteOrder byteOrder) {
- return writableWrap(array, 0, array.length, byteOrder, defaultMemReqSvr);
+ static WritableMemory writableWrap(
+ byte[] array,
+ ByteOrder byteOrder) {
+ return writableWrap(array, 0, array.length, byteOrder, null);
}
/**
@@ -285,13 +301,17 @@ public interface WritableMemory extends Memory {
* <p><b>Note:</b> Always qualify this method with the class name, e.g.,
* <i>WritableMemory.wrap(...)</i>.
* @param array the given primitive array. It must be non-null.
- * @param offsetBytes the byte offset into the given array. It must be ≥ 0.
- * @param lengthBytes the number of bytes to include from the given array. It must be ≥ 0.
+ * @param offsetBytes the byte offset into the given array.
+ * @param lengthBytes the number of bytes to include from the given array.
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(byte[] array, int offsetBytes, int lengthBytes, ByteOrder byteOrder) {
- return writableWrap(array, offsetBytes, lengthBytes, byteOrder, defaultMemReqSvr);
+ static WritableMemory writableWrap(
+ byte[] array,
+ int offsetBytes,
+ int lengthBytes,
+ ByteOrder byteOrder) {
+ return writableWrap(array, offsetBytes, lengthBytes, byteOrder, null);
}
/**
@@ -303,18 +323,19 @@ public interface WritableMemory extends Memory {
* <i>WritableMemory.wrap(...)</i>.
* @param array the given primitive array. It must be non-null.
* @param offsetBytes the byte offset into the given array. It must be ≥ 0.
- * @param lengthBytes the number of bytes to include from the given array. It must be ≥ 0.
+ * @param lengthBytes the number of bytes to include from the given array. It must be ≥ 0.
* @param byteOrder the byte order to be used. It must be non-null.
* @param memReqSvr A user-specified <i>MemoryRequestServer</i>, which may be null.
* This is a callback mechanism for a user client to request a larger <i>WritableMemory</i>.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(byte[] array, int offsetBytes, int lengthBytes, ByteOrder byteOrder,
+ static WritableMemory writableWrap(
+ byte[] array,
+ int offsetBytes,
+ int lengthBytes,
+ ByteOrder byteOrder,
MemoryRequestServer memReqSvr) {
Objects.requireNonNull(array, "array must be non-null");
- Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
- negativeCheck(offsetBytes, "offsetBytes");
- negativeCheck(lengthBytes, "lengthBytes");
ResourceImpl.checkBounds(offsetBytes, lengthBytes, array.length);
return BaseWritableMemoryImpl.wrapHeapArray(array, offsetBytes, lengthBytes, false, byteOrder, memReqSvr);
}
@@ -324,109 +345,87 @@ public interface WritableMemory extends Memory {
* @param array the given primitive array. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- static WritableMemory writableWrap(boolean[] array) {
- Objects.requireNonNull(array, "array must be non-null");
- final long lengthBytes = array.length << Prim.BOOLEAN.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
- }
-
- /**
- * Wraps the given primitive array for write operations assuming native byte order.
- * @param array the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
static WritableMemory writableWrap(char[] array) {
Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.CHAR.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
+ return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for write operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
static WritableMemory writableWrap(short[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.SHORT.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
+ return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for write operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
static WritableMemory writableWrap(int[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.INT.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
+ return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for write operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
static WritableMemory writableWrap(long[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.LONG.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
+ return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for write operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
static WritableMemory writableWrap(float[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.FLOAT.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
+ return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(), null);
}
/**
* Wraps the given primitive array for write operations assuming native byte order.
- * @param array the given primitive array.
+ * @param array the given primitive array. It must be non-null.
* @return a new WritableMemory for write operations on the given primitive array.
*/
static WritableMemory writableWrap(double[] array) {
- Objects.requireNonNull(array, "arr must be non-null");
+ Objects.requireNonNull(array, "array must be non-null");
final long lengthBytes = array.length << Prim.DOUBLE.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(),
- defaultMemReqSvr);
+ return BaseWritableMemoryImpl.wrapHeapArray(array, 0L, lengthBytes, false, ByteOrder.nativeOrder(), null);
}
//END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE putX() and putXArray()
+
/**
* Puts the boolean value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putBoolean(long offsetBytes, boolean value);
-
- /**
- * Puts the boolean array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetBooleans offset in array units
- * @param lengthBooleans number of array units to transfer
- */
- void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans, int lengthBooleans);
+ void putBoolean(
+ long offsetBytes,
+ boolean value);
/**
* Puts the byte value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putByte(long offsetBytes, byte value);
+ void putByte(
+ long offsetBytes,
+ byte value);
/**
* Puts the byte array at the given offset
@@ -435,14 +434,20 @@ public interface WritableMemory extends Memory {
* @param srcOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes, int lengthBytes);
+ void putByteArray(
+ long offsetBytes,
+ byte[] srcArray,
+ int srcOffsetBytes,
+ int lengthBytes);
/**
* Puts the char value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putChar(long offsetBytes, char value);
+ void putChar(
+ long offsetBytes,
+ char value);
/**
* Puts the char array at the given offset
@@ -451,28 +456,20 @@ public interface WritableMemory extends Memory {
* @param srcOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars, int lengthChars);
-
- /**
- * Encodes characters from the given CharSequence into UTF-8 bytes and puts them into this
- * <i>WritableMemory</i> beginning at the given offsetBytes.
- * This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param src The source CharSequence to be encoded and put into this WritableMemory. It is
- * the responsibility of the caller to provide sufficient capacity in this
- * <i>WritableMemory</i> for the encoded Utf8 bytes. Characters outside the ASCII range can
- * require 2, 3 or 4 bytes per character to encode.
- * @return the number of bytes encoded
- */
- long putCharsToUtf8(long offsetBytes, CharSequence src);
+ void putCharArray(
+ long offsetBytes,
+ char[] srcArray,
+ int srcOffsetChars,
+ int lengthChars);
/**
* Puts the double value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putDouble(long offsetBytes, double value);
+ void putDouble(
+ long offsetBytes,
+ double value);
/**
* Puts the double array at the given offset
@@ -481,14 +478,20 @@ public interface WritableMemory extends Memory {
* @param srcOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- void putDoubleArray(long offsetBytes, double[] srcArray, int srcOffsetDoubles, int lengthDoubles);
+ void putDoubleArray(
+ long offsetBytes,
+ double[] srcArray,
+ int srcOffsetDoubles,
+ int lengthDoubles);
/**
* Puts the float value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putFloat(long offsetBytes, float value);
+ void putFloat(
+ long offsetBytes,
+ float value);
/**
* Puts the float array at the given offset
@@ -497,14 +500,20 @@ public interface WritableMemory extends Memory {
* @param srcOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- void putFloatArray(long offsetBytes, float[] srcArray, int srcOffsetFloats, int lengthFloats);
+ void putFloatArray(
+ long offsetBytes,
+ float[] srcArray,
+ int srcOffsetFloats,
+ int lengthFloats);
/**
* Puts the int value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putInt(long offsetBytes, int value);
+ void putInt(
+ long offsetBytes,
+ int value);
/**
* Puts the int array at the given offset
@@ -513,14 +522,20 @@ public interface WritableMemory extends Memory {
* @param srcOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- void putIntArray(long offsetBytes, int[] srcArray, int srcOffsetInts, int lengthInts);
+ void putIntArray(
+ long offsetBytes,
+ int[] srcArray,
+ int srcOffsetInts,
+ int lengthInts);
/**
* Puts the long value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putLong(long offsetBytes, long value);
+ void putLong(
+ long offsetBytes,
+ long value);
/**
* Puts the long array at the given offset
@@ -529,14 +544,20 @@ public interface WritableMemory extends Memory {
* @param srcOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- void putLongArray(long offsetBytes, long[] srcArray, int srcOffsetLongs, int lengthLongs);
+ void putLongArray(
+ long offsetBytes,
+ long[] srcArray,
+ int srcOffsetLongs,
+ int lengthLongs);
/**
* Puts the short value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- void putShort(long offsetBytes, short value);
+ void putShort(
+ long offsetBytes,
+ short value);
/**
* Puts the short array at the given offset
@@ -545,7 +566,11 @@ public interface WritableMemory extends Memory {
* @param srcOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- void putShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts);
+ void putShortArray(
+ long offsetBytes,
+ short[] srcArray,
+ int srcOffsetShorts,
+ int lengthShorts);
//OTHER WRITE METHODS
@@ -559,14 +584,18 @@ public interface WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this Memory start
* @param lengthBytes the length in bytes
*/
- void clear(long offsetBytes, long lengthBytes);
+ void clear(
+ long offsetBytes,
+ long lengthBytes);
/**
* Clears the bits defined by the bitMask
* @param offsetBytes offset bytes relative to this Memory start.
* @param bitMask the bits set to one will be cleared
*/
- void clearBits(long offsetBytes, byte bitMask);
+ void clearBits(
+ long offsetBytes,
+ byte bitMask);
/**
* Fills all bytes of this Memory region to the given byte value.
@@ -580,13 +609,18 @@ public interface WritableMemory extends Memory {
* @param lengthBytes the length in bytes
* @param value the given byte value
*/
- void fill(long offsetBytes, long lengthBytes, byte value);
+ void fill(
+ long offsetBytes,
+ long lengthBytes,
+ byte value);
/**
* Sets the bits defined by the bitMask
* @param offsetBytes offset bytes relative to this Memory start
* @param bitMask the bits set to one will be set
*/
- void setBits(long offsetBytes, byte bitMask);
+ void setBits(
+ long offsetBytes,
+ byte bitMask);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java
index d9ec5db..9be0522 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/XxHash.java
@@ -20,7 +20,6 @@
package org.apache.datasketches.memory;
import static org.apache.datasketches.memory.internal.XxHash64.hash;
-import static org.apache.datasketches.memory.internal.XxHash64.hashBooleans;
import static org.apache.datasketches.memory.internal.XxHash64.hashBytes;
import static org.apache.datasketches.memory.internal.XxHash64.hashChars;
import static org.apache.datasketches.memory.internal.XxHash64.hashDoubles;
@@ -51,20 +50,6 @@ public final class XxHash {
private XxHash() { /* singleton */ }
- /**
- * Hash the given arr starting at the given offset and continuing for the given length using the
- * given seed.
- * @param arr the given array
- * @param offsetBooleans starting at this offset
- * @param lengthBooleans continuing for this length
- * @param seed the given seed
- * @return the hash
- */
- public static long hashBooleanArr(final boolean[] arr, final long offsetBooleans,
- final long lengthBooleans, final long seed) {
- return hashBooleans(arr, offsetBooleans, lengthBooleans, seed);
- }
-
/**
* Hash the given arr starting at the given offset and continuing for the given length using the
* given seed.
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
index 74bfdab..e1cd112 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
@@ -94,6 +94,22 @@ public abstract class BaseBufferImpl extends ResourceImpl implements BaseBuffer
return this;
}
+ @Override
+ public BaseBuffer setAndCheckPosition(final long position) {
+ checkInvariants(start, position, end, capacity);
+ pos = position;
+ return this;
+ }
+
+ @Override
+ public BaseBuffer setAndCheckStartPositionEnd(final long start, final long position, final long end) {
+ checkInvariants(start, position, end, capacity);
+ this.start = start;
+ this.end = end;
+ pos = position;
+ return this;
+ }
+
@Override
public final BaseBufferImpl setPosition(final long position) {
return setStartPositionEnd(start, position, end);
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index 61b3725..87a1840 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -19,7 +19,6 @@
package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BOOLEAN_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BOOLEAN_INDEX_SCALE;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BYTE_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BYTE_INDEX_SCALE;
@@ -52,31 +51,33 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
/**
* The static constructor that chooses the correct ByteBuffer leaf node based on the byte order.
- * @param byteBuf the ByteBuffer being wrapped
+ * @param byteBuffer the ByteBuffer being wrapped
* @param localReadOnly the requested read-only state
* @param byteOrder the requested byteOrder
* @param memReqSvr the requested MemoryRequestServer, which may be null.
* @return this class constructed via the leaf node.
*/
public static WritableBuffer wrapByteBuffer(
- final ByteBuffer byteBuf, final boolean localReadOnly, final ByteOrder byteOrder,
+ final ByteBuffer byteBuffer, final boolean localReadOnly, final ByteOrder byteOrder,
final MemoryRequestServer memReqSvr) {
- final AccessByteBuffer abb = new AccessByteBuffer(byteBuf);
+ Objects.requireNonNull(byteBuffer, "byteBuffer must not be null");
+ Objects.requireNonNull(byteOrder, "byteOrder must not be null");
+ final AccessByteBuffer abb = new AccessByteBuffer(byteBuffer);
final int typeId = (abb.resourceReadOnly || localReadOnly) ? READONLY : 0;
final long cumOffsetBytes = abb.initialCumOffset;
final BaseWritableBufferImpl bwbi = Util.isNativeByteOrder(byteOrder)
? new BBWritableBufferImpl(abb.unsafeObj, abb.nativeBaseOffset,
- abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuf)
+ abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuffer)
: new BBNonNativeWritableBufferImpl(abb.unsafeObj, abb.nativeBaseOffset,
- abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuf);
- bwbi.setStartPositionEnd(0, byteBuf.position(), byteBuf.limit());
+ abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuffer);
+ bwbi.setStartPositionEnd(0, byteBuffer.position(), byteBuffer.limit());
return bwbi;
}
//REGIONS
@Override
public Buffer region() {
- return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getByteOrder());
+ return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getTypeByteOrder());
}
@Override
@@ -88,7 +89,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public WritableBuffer writableRegion() {
- return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getByteOrder());
+ return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getTypeByteOrder());
}
@Override
@@ -116,7 +117,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
//DUPLICATES
@Override
public Buffer duplicate() {
- return writableDuplicateImpl(true, getByteOrder());
+ return writableDuplicateImpl(true, getTypeByteOrder());
}
@Override
@@ -126,7 +127,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public WritableBuffer writableDuplicate() {
- return writableDuplicateImpl(false, getByteOrder());
+ return writableDuplicateImpl(false, getTypeByteOrder());
}
@Override
@@ -184,21 +185,6 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
return unsafe.getBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
- @Override
- public final void getBooleanArray(final boolean[] dstArray, final int dstOffsetBooleans,
- final int lengthBooleans) {
- final long pos = getPosition();
- final long copyBytes = lengthBooleans;
- incrementAndCheckPositionForRead(pos, copyBytes);
- ResourceImpl.checkBounds(dstOffsetBooleans, lengthBooleans, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(pos),
- dstArray,
- ARRAY_BOOLEAN_BASE_OFFSET + dstOffsetBooleans,
- copyBytes);
- }
-
@Override
public final byte getByte() {
final long pos = getPosition();
@@ -299,21 +285,6 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
unsafe.putBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
- @Override
- public final void putBooleanArray(final boolean[] srcArray, final int srcOffsetBooleans,
- final int lengthBooleans) {
- final long pos = getPosition();
- final long copyBytes = lengthBooleans;
- incrementAndCheckPositionForWrite(pos, copyBytes);
- ResourceImpl.checkBounds(srcOffsetBooleans, lengthBooleans, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_BOOLEAN_BASE_OFFSET + srcOffsetBooleans,
- getUnsafeObject(),
- getCumulativeOffset(pos),
- copyBytes);
- }
-
@Override
public final void putByte(final byte value) {
final long pos = getPosition();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index a65f889..84d954f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -19,7 +19,6 @@
package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BOOLEAN_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BOOLEAN_INDEX_SCALE;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BYTE_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BYTE_INDEX_SCALE;
@@ -41,7 +40,6 @@ import org.apache.datasketches.memory.Buffer;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.ReadOnlyException;
-import org.apache.datasketches.memory.Utf8CodingException;
import org.apache.datasketches.memory.WritableBuffer;
import org.apache.datasketches.memory.WritableMemory;
@@ -64,26 +62,30 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
/**
* The static constructor that chooses the correct Heap leaf node based on the byte order.
- * @param arr the primitive heap array being wrapped
- * @param offsetBytes the offset bytes into the array (independent of array type).
- * @param lengthBytes the length of the wrapped region.
+ * @param array the primitive heap array being wrapped. It must be non-null;
+ * @param offsetBytes the offset bytes into the array (independent of array type). It must be ≥ 0.
+ * @param lengthBytes the length of the wrapped region. It must be ≥ 0.
* @param localReadOnly the requested read-only status
- * @param byteOrder the requested byte order
+ * @param byteOrder the requested byte order, It must be non-null.
* @param memReqSvr the requested MemoryRequestServer, which may be null.
* @return this class constructed via the leaf node.
*/
- public static WritableMemory wrapHeapArray(final Object arr, final long offsetBytes, final long lengthBytes,
+ public static WritableMemory wrapHeapArray(final Object array, final long offsetBytes, final long lengthBytes,
final boolean localReadOnly, final ByteOrder byteOrder, final MemoryRequestServer memReqSvr) {
- final long cumOffsetBytes = UnsafeUtil.getArrayBaseOffset(arr.getClass()) + offsetBytes;
+ Objects.requireNonNull(array, "array must be non-null");
+ Util.negativeCheck(offsetBytes, "offsetBytes");
+ Util.negativeCheck(lengthBytes, "lengthBytes");
+ Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
+ final long cumOffsetBytes = UnsafeUtil.getArrayBaseOffset(array.getClass()) + offsetBytes;
final int typeId = (localReadOnly ? READONLY : 0);
return Util.isNativeByteOrder(byteOrder)
- ? new HeapWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes, memReqSvr)
- : new HeapNonNativeWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes, memReqSvr);
+ ? new HeapWritableMemoryImpl(array, offsetBytes, lengthBytes, typeId, cumOffsetBytes, memReqSvr)
+ : new HeapNonNativeWritableMemoryImpl(array, offsetBytes, lengthBytes, typeId, cumOffsetBytes, memReqSvr);
}
/**
* The static constructor that chooses the correct ByteBuffer leaf node based on the byte order.
- * @param byteBuf the ByteBuffer being wrapped
+ * @param byteBuf the ByteBuffer being wrapped,
* @param localReadOnly the requested read-only state
* @param byteOrder the requested byteOrder
* @param memReqSvr the requested MemoryRequestServer, which may be null.
@@ -92,6 +94,8 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
public static WritableMemory wrapByteBuffer(
final ByteBuffer byteBuf, final boolean localReadOnly, final ByteOrder byteOrder,
final MemoryRequestServer memReqSvr) {
+ Objects.requireNonNull(byteBuf, "byteBuf must be non-null");
+ Objects.requireNonNull(byteBuf, "byteOrder must be non-null");
final AccessByteBuffer abb = new AccessByteBuffer(byteBuf);
final int typeId = (abb.resourceReadOnly || localReadOnly) ? READONLY : 0;
final long cumOffsetBytes = abb.offsetBytes + (abb.unsafeObj == null
@@ -115,6 +119,10 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
*/
public static WritableMemory wrapMap(final File file, final long fileOffsetBytes,
final long capacityBytes, final boolean localReadOnly, final ByteOrder byteOrder) {
+ Objects.requireNonNull(file, "File must be non-null.");
+ Util.negativeCheck(capacityBytes, "fileOffsetBytes");
+ Util.negativeCheck(capacityBytes, "capacityBytes");
+ Objects.requireNonNull(byteOrder, "ByteOrder must be non-null.");
final AllocateDirectWritableMap dirWMap =
new AllocateDirectWritableMap(file, fileOffsetBytes, capacityBytes, localReadOnly);
final int typeId = (dirWMap.resourceReadOnly || localReadOnly) ? READONLY : 0;
@@ -137,13 +145,15 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
/**
* The static constructor that chooses the correct Direct leaf node based on the byte order.
- * @param capacityBytes the requested capacity for the Direct (off-heap) memory
- * @param byteOrder the requested byte order
- * @param memReqSvr the requested MemoryRequestServer, which may be null
+ * @param capacityBytes the requested capacity for the Direct (off-heap) memory. It must be ≥ 0.
+ * @param byteOrder the requested byte order. It must be non-null.
+ * @param memReqSvr the requested MemoryRequestServer, which may be null.
* @return this class constructed via the leaf node.
*/
public static WritableMemory wrapDirect(final long capacityBytes,
final ByteOrder byteOrder, final MemoryRequestServer memReqSvr) {
+ Util.negativeCheck(capacityBytes, "capacityBytes");
+ Objects.requireNonNull(byteOrder, "byteOrder must be non-null.");
final AllocateDirect direct = new AllocateDirect(capacityBytes);
final int typeId = 0; //direct is never read-only on construction
final long nativeBaseOffset = direct.getNativeBaseOffset();
@@ -167,6 +177,7 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
}
//REGIONS
+
@Override
public Memory region(final long regionOffsetBytes, final long capacityBytes, final ByteOrder byteOrder) {
return writableRegionImpl(regionOffsetBytes, capacityBytes, true, byteOrder);
@@ -195,6 +206,7 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
long regionOffsetBytes, long capacityBytes, boolean finalReadOnly, ByteOrder byteOrder);
//AS BUFFER
+
@Override
public Buffer asBuffer(final ByteOrder byteOrder) {
return asWritableBuffer(true, byteOrder);
@@ -220,26 +232,13 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
abstract WritableBuffer toWritableBuffer(boolean finalReadOnly, ByteOrder byteOrder);
//PRIMITIVE getX() and getXArray()
+
@Override
public final boolean getBoolean(final long offsetBytes) {
checkValidAndBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE);
return unsafe.getBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
- @Override
- public final void getBooleanArray(final long offsetBytes, final boolean[] dstArray,
- final int dstOffsetBooleans, final int lengthBooleans) {
- final long copyBytes = lengthBooleans;
- checkValidAndBounds(offsetBytes, copyBytes);
- ResourceImpl.checkBounds(dstOffsetBooleans, lengthBooleans, dstArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- getUnsafeObject(),
- getCumulativeOffset(offsetBytes),
- dstArray,
- ARRAY_BOOLEAN_BASE_OFFSET + dstOffsetBooleans,
- copyBytes);
- }
-
@Override
public final byte getByte(final long offsetBytes) {
checkValidAndBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
@@ -260,26 +259,6 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
copyBytes);
}
- @Override
- public final int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
- final Appendable dst) throws IOException, Utf8CodingException {
- checkValidAndBounds(offsetBytes, utf8LengthBytes);
- return Utf8.getCharsFromUtf8(offsetBytes, utf8LengthBytes, dst, getCumulativeOffset(0),
- getUnsafeObject());
- }
-
- @Override
- public final int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
- final StringBuilder dst) throws Utf8CodingException {
- try {
- // Ensure that we do at most one resize of internal StringBuilder's char array
- dst.ensureCapacity(dst.length() + utf8LengthBytes);
- return getCharsFromUtf8(offsetBytes, utf8LengthBytes, (Appendable) dst);
- } catch (final IOException e) {
- throw new RuntimeException("Should not happen", e);
- }
- }
-
//PRIMITIVE getX() Native Endian (used by both endians)
final char getNativeOrderedChar(final long offsetBytes) {
checkValidAndBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE);
@@ -338,21 +317,6 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
unsafe.putBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
- @Override
- public final void putBooleanArray(final long offsetBytes, final boolean[] srcArray,
- final int srcOffsetBooleans, final int lengthBooleans) {
- final long copyBytes = lengthBooleans;
- checkValidAndBoundsForWrite(offsetBytes, copyBytes);
- ResourceImpl.checkBounds(srcOffsetBooleans, lengthBooleans, srcArray.length);
- CompareAndCopy.copyMemoryCheckingDifferentObject(
- srcArray,
- ARRAY_BOOLEAN_BASE_OFFSET + srcOffsetBooleans,
- getUnsafeObject(),
- getCumulativeOffset(offsetBytes),
- copyBytes
- );
- }
-
@Override
public final void putByte(final long offsetBytes, final byte value) {
checkValidAndBoundsForWrite(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
@@ -374,13 +338,6 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
);
}
- @Override
- public final long putCharsToUtf8(final long offsetBytes, final CharSequence src) {
- checkValid();
- return Utf8.putCharsToUtf8(offsetBytes, src, getCapacity(), getCumulativeOffset(0),
- getUnsafeObject());
- }
-
//PRIMITIVE putX() Native Endian (used by both endians)
final void putNativeOrderedChar(final long offsetBytes, final char value) {
checkValidAndBoundsForWrite(offsetBytes, ARRAY_CHAR_INDEX_SCALE);
@@ -477,7 +434,7 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
long addr = getCumulativeOffset(offsetBytes);
// Do chunking, because it's likely that WritableByteChannel.write(ByteBuffer) in some network-
// or file-backed WritableByteChannel implementations with direct ByteBuffer argument could
- // be subject of the same safepoint problems as in Unsafe.copyMemory and Unsafe.setMemory.
+ // be subject to the same safepoint problems as in Unsafe.copyMemory and Unsafe.setMemory.
while (lengthBytes > 0) {
final int chunk = (int) Math.min(Util.UNSAFE_COPY_THRESHOLD_BYTES, lengthBytes);
final ByteBuffer bufToWrite = AccessByteBuffer.getDummyReadOnlyDirectByteBuffer(addr, chunk);
@@ -487,8 +444,7 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
}
}
- private void writeToWithExtraCopy(long offsetBytes, long lengthBytes,
- final WritableByteChannel out) throws IOException {
+ private void writeToWithExtraCopy(long offsetBytes, long lengthBytes, final WritableByteChannel out) throws IOException {
// Keep the bufLen a multiple of 8, to maybe allow getByteArray() to go a faster path.
final int bufLen = Ints.checkedCast(Math.max(8, Math.min((getCapacity() / 1024) & ~7L, 4096)));
final byte[] buf = new byte[bufLen];
@@ -503,8 +459,7 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
}
}
- private static void writeFully(final ByteBuffer bufToWrite, final WritableByteChannel out)
- throws IOException {
+ private static void writeFully(final ByteBuffer bufToWrite, final WritableByteChannel out) throws IOException {
while (bufToWrite.remaining() > 0) {
out.write(bufToWrite);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
index 2f4796b..6d81939 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
@@ -219,7 +219,7 @@ public abstract class ResourceImpl implements Resource {
}
@Override
- public final ByteOrder getByteOrder() {
+ public final ByteOrder getTypeByteOrder() {
return isNativeOrder(getTypeId()) ? NATIVE_BYTE_ORDER : NON_NATIVE_BYTE_ORDER;
}
@@ -268,7 +268,7 @@ public abstract class ResourceImpl implements Resource {
@Override
public final boolean isByteOrderCompatible(final ByteOrder byteOrder) {
- final ByteOrder typeBO = getByteOrder();
+ final ByteOrder typeBO = getTypeByteOrder();
return typeBO == ByteOrder.nativeOrder() && typeBO == byteOrder;
}
@@ -429,7 +429,7 @@ public abstract class ResourceImpl implements Resource {
sb.append("MemReq, hashCode : ").append(memReqStr).append(LS);
sb.append("Valid : ").append(state.isValid()).append(LS);
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
- sb.append("Type Byte Order : ").append(state.getByteOrder().toString()).append(LS);
+ sb.append("Type Byte Order : ").append(state.getTypeByteOrder().toString()).append(LS);
sb.append("Native Byte Order : ").append(ByteOrder.nativeOrder().toString()).append(LS);
sb.append("JDK Runtime Version : ").append(UnsafeUtil.JDK).append(LS);
//Data detail
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
deleted file mode 100644
index aee5eaf..0000000
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
+++ /dev/null
@@ -1,631 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.datasketches.memory.internal;
-
-import static java.lang.Character.isSurrogate;
-import static java.lang.Character.isSurrogatePair;
-import static java.lang.Character.toCodePoint;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
-
-import java.io.IOException;
-import java.nio.BufferOverflowException;
-import java.nio.CharBuffer;
-
-import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.Utf8CodingException;
-import org.apache.datasketches.memory.WritableMemory;
-
-/**
- * Encoding and decoding implementations of {@link WritableMemory#putCharsToUtf8} and
- * {@link Memory#getCharsFromUtf8}.
- *
- * <p>This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- *
- * <p>UTF-8 encoding/decoding is adapted from
- * https://github.com/protocolbuffers/protobuf/blob/master/java/core/src/main/java/com/google/protobuf/Utf8.java
- *
- * <p>Copyright 2008 Google Inc. All rights reserved.
- * https://developers.google.com/protocol-buffers/
- * See LICENSE.
- *
- * @author Lee Rhodes
- * @author Roman Leventov
- */
-@SuppressWarnings("restriction")
-final class Utf8 {
-
- private Utf8() { }
-
- //Decode
- static final int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
- final Appendable dst, final long cumBaseOffset, final Object unsafeObj)
- throws IOException, Utf8CodingException {
-
- if ((dst instanceof CharBuffer) && ((CharBuffer) dst).hasArray()) {
- return getCharBufferCharsFromUtf8(offsetBytes, ((CharBuffer) dst), utf8LengthBytes,
- cumBaseOffset, unsafeObj);
- }
-
- //Decode Direct CharBuffers and all other Appendables
-
- final long address = cumBaseOffset + offsetBytes;
- // Optimize for 100% ASCII (Hotspot loves small simple top-level loops like this).
- // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
- // Need to keep this loop int-indexed, because it's faster for Hotspot JIT, it doesn't insert
- // savepoint polls on each iteration.
- int i = 0;
- for (; i < utf8LengthBytes; i++) {
- final byte b = unsafe.getByte(unsafeObj, address + i);
- if (!DecodeUtil.isOneByte(b)) {
- break;
- }
- dst.append((char) b);
- }
- if (i == utf8LengthBytes) {
- return i;
- }
- return getNonAsciiCharsFromUtf8(dst, address + i, address + utf8LengthBytes, unsafeObj,
- cumBaseOffset) + i;
- }
-
- /*
- * Optimize for heap CharBuffer manually, because Hotspot JIT doesn't itself unfold this
- * abstraction well (doesn't hoist array bound checks, etc.)
- */
- private static int getCharBufferCharsFromUtf8(final long offsetBytes, final CharBuffer cbuf,
- final int utf8LengthBytes, final long cumBaseOffset, final Object unsafeObj) {
- final char[] carr = cbuf.array();
- final int startCpos = cbuf.position() + cbuf.arrayOffset();
- int cpos = startCpos;
- final int clim = cbuf.arrayOffset() + cbuf.limit();
- final long address = cumBaseOffset + offsetBytes;
- int i = 0; //byte index
-
- // Optimize for 100% ASCII (Hotspot loves small simple top-level loops like this).
- // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
- final int cbufNoCheckLimit = Math.min(utf8LengthBytes, clim - cpos);
- // Need to keep this loop int-indexed, because it's faster for Hotspot JIT, it doesn't insert
- // savepoint polls on each iteration.
- for (; i < cbufNoCheckLimit; i++) {
- final byte b = unsafe.getByte(unsafeObj, address + i);
- if (!DecodeUtil.isOneByte(b)) {
- break;
- }
- // Not checking CharBuffer bounds!
- carr[cpos++] = (char) b;
- }
-
- for (; i < utf8LengthBytes; i++) {
- final byte b = unsafe.getByte(unsafeObj, address + i);
- if (!DecodeUtil.isOneByte(b)) {
- break;
- }
- checkCharBufferPos(cbuf, cpos, clim);
- carr[cpos++] = (char) b;
- }
- if (i == utf8LengthBytes) {
- cbuf.position(cpos - cbuf.arrayOffset());
- return cpos - startCpos;
- }
-
- return getCharBufferNonAsciiCharsFromUtf8(cbuf, carr, cpos, clim, address + i,
- address + utf8LengthBytes, unsafeObj, cumBaseOffset) - cbuf.arrayOffset();
- }
-
- private static int getCharBufferNonAsciiCharsFromUtf8(final CharBuffer cbuf, final char[] carr,
- int cpos, final int clim, long address, final long addressLimit, final Object unsafeObj,
- final long cumBaseOffset) {
-
- while (address < addressLimit) {
- final byte byte1 = unsafe.getByte(unsafeObj, address++);
- if (DecodeUtil.isOneByte(byte1)) {
- checkCharBufferPos(cbuf, cpos, clim);
- carr[cpos++] = (char) byte1;
- // It's common for there to be multiple ASCII characters in a run mixed in, so add an
- // extra optimized loop to take care of these runs.
- while (address < addressLimit) {
- final byte b = unsafe.getByte(unsafeObj, address);
- if (!DecodeUtil.isOneByte(b)) {
- break;
- }
- address++;
- checkCharBufferPos(cbuf, cpos, clim);
- carr[cpos++] = (char) b;
- }
- }
- else if (DecodeUtil.isTwoBytes(byte1)) {
- if (address >= addressLimit) {
- cbuf.position(cpos - cbuf.arrayOffset());
- final long off = address - cumBaseOffset;
- final long limit = addressLimit - cumBaseOffset;
- throw Utf8CodingException.shortUtf8DecodeByteSequence(byte1, off, limit, 2);
- }
- checkCharBufferPos(cbuf, cpos, clim);
- DecodeUtil.handleTwoBytesCharBuffer(
- byte1,
- /* byte2 */ unsafe.getByte(unsafeObj, address++),
- cbuf, carr, cpos);
- cpos++;
- }
- else if (DecodeUtil.isThreeBytes(byte1)) {
- if (address >= (addressLimit - 1)) {
- cbuf.position(cpos - cbuf.arrayOffset());
- final long off = address - cumBaseOffset;
- final long limit = addressLimit - cumBaseOffset;
- throw Utf8CodingException.shortUtf8DecodeByteSequence(byte1, off, limit, 3);
- }
- checkCharBufferPos(cbuf, cpos, clim);
- DecodeUtil.handleThreeBytesCharBuffer(
- byte1,
- /* byte2 */ unsafe.getByte(unsafeObj, address++),
- /* byte3 */ unsafe.getByte(unsafeObj, address++),
- cbuf, carr, cpos);
- cpos++;
- }
- else {
- if (address >= (addressLimit - 2)) {
- cbuf.position(cpos - cbuf.arrayOffset());
- final long off = address - cumBaseOffset;
- final long limit = addressLimit - cumBaseOffset;
- throw Utf8CodingException.shortUtf8DecodeByteSequence(byte1, off, limit, 4);
- }
- if (cpos >= (clim - 1)) {
- cbuf.position(cpos - cbuf.arrayOffset());
- throw new BufferOverflowException();
- }
- DecodeUtil.handleFourBytesCharBuffer(
- byte1,
- /* byte2 */ unsafe.getByte(unsafeObj, address++),
- /* byte3 */ unsafe.getByte(unsafeObj, address++),
- /* byte4 */ unsafe.getByte(unsafeObj, address++),
- cbuf, carr, cpos);
- cpos += 2;
- }
- }
- cbuf.position(cpos - cbuf.arrayOffset());
- return cpos;
- }
-
- //Decodes into Appendable destination
- //returns num of chars decoded
- private static int getNonAsciiCharsFromUtf8(final Appendable dst, long address,
- final long addressLimit, final Object unsafeObj, final long cumBaseOffset)
- throws IOException {
- int chars = 0;
- while (address < addressLimit) {
- final byte byte1 = unsafe.getByte(unsafeObj, address++);
- if (DecodeUtil.isOneByte(byte1)) {
- dst.append((char) byte1);
- chars++;
- // It's common for there to be multiple ASCII characters in a run mixed in, so add an
- // extra optimized loop to take care of these runs.
- while (address < addressLimit) {
- final byte b = unsafe.getByte(unsafeObj, address);
- if (!DecodeUtil.isOneByte(b)) {
- break;
- }
- address++;
- dst.append((char) b);
- chars++;
- }
- }
- else if (DecodeUtil.isTwoBytes(byte1)) {
- if (address >= addressLimit) {
- final long off = address - cumBaseOffset;
- final long limit = addressLimit - cumBaseOffset;
- throw Utf8CodingException.shortUtf8DecodeByteSequence(byte1, off, limit, 2);
- }
- DecodeUtil.handleTwoBytes(
- byte1,
- /* byte2 */ unsafe.getByte(unsafeObj, address++),
- dst);
- chars++;
- }
- else if (DecodeUtil.isThreeBytes(byte1)) {
- if (address >= (addressLimit - 1)) {
- final long off = address - cumBaseOffset;
- final long limit = addressLimit - cumBaseOffset;
- throw Utf8CodingException.shortUtf8DecodeByteSequence(byte1, off, limit, 3);
- }
- DecodeUtil.handleThreeBytes(
- byte1,
- /* byte2 */ unsafe.getByte(unsafeObj, address++),
- /* byte3 */ unsafe.getByte(unsafeObj, address++),
- dst);
- chars++;
- }
- else {
- if (address >= (addressLimit - 2)) {
- final long off = address - cumBaseOffset;
- final long limit = addressLimit - cumBaseOffset;
- throw Utf8CodingException.shortUtf8DecodeByteSequence(byte1, off, limit, 4);
- }
- DecodeUtil.handleFourBytes(
- byte1,
- /* byte2 */ unsafe.getByte(unsafeObj, address++),
- /* byte3 */ unsafe.getByte(unsafeObj, address++),
- /* byte4 */ unsafe.getByte(unsafeObj, address++),
- dst);
- chars += 2;
- }
- }
- return chars;
- }
-
- private static void checkCharBufferPos(final CharBuffer cbuf, final int cpos, final int clim) {
- if (cpos == clim) {
- cbuf.position(cpos - cbuf.arrayOffset());
- throw new BufferOverflowException();
- }
- }
-
- /******************/
- //Encode
- static long putCharsToUtf8(final long offsetBytes, final CharSequence src,
- final long capacityBytes, final long cumBaseOffset, final Object unsafeObj) {
-
-
- int cIdx = 0; //src character index
- long bIdx = cumBaseOffset + offsetBytes; //byte index
- long bCnt = 0; //bytes inserted
-
- final long byteLimit = cumBaseOffset + capacityBytes; //unsafe index limit
-
- final int utf16Length = src.length();
- //Quickly dispatch an ASCII sequence
- for (char c;
- (cIdx < utf16Length) && ((cIdx + bIdx) < byteLimit) && ((c = src.charAt(cIdx)) < 0x80);
- cIdx++, bCnt++) {
- unsafe.putByte(unsafeObj, bIdx + cIdx, (byte) c);
- }
- //encountered a non-ascii character
- if (cIdx == utf16Length) { //done.
- // next relative byte index in memory is (bIdx + utf16Length) - cumBaseOffset.
- return bCnt;
- }
- bIdx += cIdx; //bytes == characters for ascii
-
- for (char c; cIdx < utf16Length; cIdx++) { //process the remaining characters
- c = src.charAt(cIdx);
-
- if ((c < 0x80) && (bIdx < byteLimit)) {
- //Encode ASCII, 0 through 0x007F.
- unsafe.putByte(unsafeObj, bIdx++, (byte) c);
- bCnt++;
- }
-
- else
- //c MUST BE >= 0x0080 || j >= byteLimit
-
- if ((c < 0x800) && (bIdx < (byteLimit - 1))) {
- //Encode 0x80 through 0x7FF.
- //This is for almost all Latin-script alphabets plus Greek, Cyrillic, Hebrew, Arabic, etc.
- //We must have target space for at least 2 Utf8 bytes.
- unsafe.putByte(unsafeObj, bIdx++, (byte) ((0xF << 6) | (c >>> 6)));
- unsafe.putByte(unsafeObj, bIdx++, (byte) (0x80 | (0x3F & c)));
- bCnt += 2;
- }
-
- else
- //c > 0x800 || j >= byteLimit - 1 || j >= byteLimit
-
- if ( !isSurrogate(c) && (bIdx < (byteLimit - 2)) ) {
- //Encode the remainder of the BMP that are not surrogates:
- // 0x0800 thru 0xD7FF; 0xE000 thru 0xFFFF, the max single-char code point
- //We must have target space for at least 3 Utf8 bytes.
- unsafe.putByte(unsafeObj, bIdx++, (byte) ((0xF << 5) | (c >>> 12)));
- unsafe.putByte(unsafeObj, bIdx++, (byte) (0x80 | (0x3F & (c >>> 6))));
- unsafe.putByte(unsafeObj, bIdx++, (byte) (0x80 | (0x3F & c)));
- bCnt += 3;
- }
-
- else {
- //c is a surrogate || j >= byteLimit - 2 || j >= byteLimit - 1 || j >= byteLimit
-
- //At this point we are either:
- // 1) Attempting to encode Code Points outside the BMP.
- //
- // The only way to properly encode code points outside the BMP into Utf8 bytes is to use
- // High/Low pairs of surrogate characters. Therefore, we must have at least 2 source
- // characters remaining, at least 4 bytes of memory space remaining, and the next 2
- // characters must be a valid surrogate pair.
- //
- // 2) There is insufficient MemoryImpl space to encode the current character from one of the
- // ifs above.
- //
- // We proceed assuming (1). If the following test fails, we move to an exception.
-
- final char low;
- if ( (cIdx <= (utf16Length - 2))
- && (bIdx <= (byteLimit - 4))
- && isSurrogatePair(c, low = src.charAt(cIdx + 1)) ) { //we are good
- cIdx++; //skip over low surrogate
- final int codePoint = toCodePoint(c, low);
- unsafe.putByte(unsafeObj, bIdx++, (byte) ((0xF << 4) | (codePoint >>> 18)));
- unsafe.putByte(unsafeObj, bIdx++, (byte) (0x80 | (0x3F & (codePoint >>> 12))));
- unsafe.putByte(unsafeObj, bIdx++, (byte) (0x80 | (0x3F & (codePoint >>> 6))));
- unsafe.putByte(unsafeObj, bIdx++, (byte) (0x80 | (0x3F & codePoint)));
- bCnt += 4;
- }
-
- else {
- //We are going to throw an exception. So we have time to figure out
- // what was wrong and hopefully throw an intelligent message!
-
- //check the BMP code point cases and their required memory limits
- if ( ((c < 0X0080) && (bIdx >= byteLimit))
- || ((c < 0x0800) && (bIdx >= (byteLimit - 1)))
- || ((c < 0xFFFF) && (bIdx >= (byteLimit - 2))) ) {
- throw Utf8CodingException.outOfMemory();
- }
-
- if (cIdx > (utf16Length - 2)) { //the last char is an unpaired surrogate
- throw Utf8CodingException.unpairedSurrogate(c);
- }
-
- if (bIdx > (byteLimit - 4)) {
- //4 MemoryImpl bytes required to encode a surrogate pair.
- final int remaining = (int) ((bIdx - byteLimit) + 4L);
- throw Utf8CodingException.shortUtf8EncodeByteLength(remaining);
- }
-
- if (!isSurrogatePair(c, src.charAt(cIdx + 1)) ) {
- //Not a surrogate pair.
- throw Utf8CodingException.illegalSurrogatePair(c, src.charAt(cIdx + 1));
- }
-
- //This should not happen :)
- throw new IllegalArgumentException("Unknown Utf8 encoding exception");
- }
- }
- }
- //final long localOffsetBytes = bIdx - cumBaseOffset;
- return bCnt;
- }
-
- /*****************/
- /**
- * Utility methods for decoding UTF-8 bytes into {@link String}. Callers are responsible for
- * extracting bytes (possibly using Unsafe methods), and checking remaining bytes. All other
- * UTF-8 validity checks and codepoint conversions happen in this class.
- *
- * @see <a href="https://en.wikipedia.org/wiki/UTF-8">Wikipedia: UTF-8</a>
- */
- private static class DecodeUtil {
-
- /**
- * Returns whether this is a single-byte UTF-8 encoding.
- * This is for ASCII.
- *
- * <p>Code Plane 0, Code Point range U+0000 to U+007F.
- *
- * <p>Bit Patterns:
- * <ul><li>Byte 1: '0xxxxxxx'<li>
- * </ul>
- * @param b the byte being tested
- * @return true if this is a single-byte UTF-8 encoding, i.e., b is ≥ 0.
- */
- static boolean isOneByte(final byte b) {
- return b >= 0;
- }
-
- /**
- * Returns whether this is the start of a two-byte UTF-8 encoding. One-byte encoding must
- * already be excluded.
- * This is for almost all Latin-script alphabets plus Greek, Cyrillic, Hebrew, Arabic, etc.
- *
- * <p>Code Plane 0, Code Point range U+0080 to U+07FF.
- *
- * <p>Bit Patterns:
- * <ul><li>Byte 1: '110xxxxx'</li>
- * <li>Byte 2: '10xxxxxx'</li>
- * </ul>
- *
- * <p>All bytes must be < 0xE0.
- *
- * @param b the byte being tested
- * @return true if this is the start of a two-byte UTF-8 encoding.
- */
- static boolean isTwoBytes(final byte b) {
- return b < (byte) 0xE0;
- }
-
- /**
- * Returns whether this is the start of a three-byte UTF-8 encoding. Two-byte encoding must
- * already be excluded.
- * This is for the rest of the BMP, which includes most common Chinese, Japanese and Korean
- * characters.
- *
- * <p>Code Plane 0, Code Point range U+0800 to U+FFFF.
- *
- * <p>Bit Patterns:
- * <ul><li>Byte 1: '1110xxxx'</li>
- * <li>Byte 2: '10xxxxxx'</li>
- * <li>Byte 3: '10xxxxxx'</li>
- * </ul>
- * All bytes must be less than 0xF0.
- *
- * @param b the byte being tested
- * @return true if this is the start of a three-byte UTF-8 encoding, i.e., b ≥ 0XF0.
- */
- static boolean isThreeBytes(final byte b) {
- return b < (byte) 0xF0;
- }
-
- /*
- * Note that if three-byte UTF-8 coding has been excluded and if the current byte is
- * ≥ 0XF0, it must be the start of a four-byte UTF-8 encoding.
- * This is for the less common CJKV characters, historic scripts, math symbols, emoji, etc.
- *
- * <p>Code Plane 1 through 16, Code Point range U+10000 to U+10FFFF.
- *
- * <p>Bit Patterns:
- * <ul><li>Byte 1: '11110xxx'</li>
- * <li>Byte 2: '10xxxxxx'</li>
- * <li>Byte 3: '10xxxxxx'</li>
- * <li>Byte 4: '10xxxxxx'</li>
- * </ul>
- */
-
- static void handleTwoBytes(
- final byte byte1, final byte byte2,
- final Appendable dst)
- throws IOException, Utf8CodingException {
- // Simultaneously checks for illegal trailing-byte in leading position (<= '11000000') and
- // overlong 2-byte, '11000001'.
- if ((byte1 < (byte) 0xC2)
- || isNotTrailingByte(byte2)) {
- final byte[] out = new byte[] {byte1, byte2};
- throw Utf8CodingException.illegalUtf8DecodeByteSequence(out);
- }
- dst.append((char) (((byte1 & 0x1F) << 6) | trailingByteValue(byte2)));
- }
-
- static void handleTwoBytesCharBuffer(
- final byte byte1, final byte byte2,
- final CharBuffer cb, final char[] ca, final int cp)
- throws Utf8CodingException {
- // Simultaneously checks for illegal trailing-byte in leading position (<= '11000000') and
- // overlong 2-byte, '11000001'.
- if ((byte1 < (byte) 0xC2)
- || isNotTrailingByte(byte2)) {
- final byte[] out = new byte[] {byte1, byte2};
- cb.position(cp - cb.arrayOffset());
- throw Utf8CodingException.illegalUtf8DecodeByteSequence(out);
- }
- ca[cp] = (char) (((byte1 & 0x1F) << 6) | trailingByteValue(byte2));
- }
-
- static void handleThreeBytes(
- final byte byte1, final byte byte2, final byte byte3,
- final Appendable dst)
- throws IOException, Utf8CodingException {
- if (isNotTrailingByte(byte2)
- // overlong? 5 most significant bits must not all be zero
- || ((byte1 == (byte) 0xE0) && (byte2 < (byte) 0xA0))
- // check for illegal surrogate codepoints
- || ((byte1 == (byte) 0xED) && (byte2 >= (byte) 0xA0))
- || isNotTrailingByte(byte3)) {
- final byte[] out = new byte[] {byte1, byte2, byte3};
- throw Utf8CodingException.illegalUtf8DecodeByteSequence(out);
- }
- dst.append((char)
- (((byte1 & 0x0F) << 12) | (trailingByteValue(byte2) << 6) | trailingByteValue(byte3)));
- }
-
- static void handleThreeBytesCharBuffer(
- final byte byte1, final byte byte2, final byte byte3,
- final CharBuffer cb, final char[] ca, final int cp)
- throws Utf8CodingException {
- if (isNotTrailingByte(byte2)
- // overlong? 5 most significant bits must not all be zero
- || ((byte1 == (byte) 0xE0) && (byte2 < (byte) 0xA0))
- // check for illegal surrogate codepoints
- || ((byte1 == (byte) 0xED) && (byte2 >= (byte) 0xA0))
- || isNotTrailingByte(byte3)) {
- cb.position(cp - cb.arrayOffset());
- final byte[] out = new byte[] {byte1, byte2, byte3};
- throw Utf8CodingException.illegalUtf8DecodeByteSequence(out);
- }
- ca[cp] = (char)
- (((byte1 & 0x0F) << 12) | (trailingByteValue(byte2) << 6) | trailingByteValue(byte3));
- }
-
- static void handleFourBytes(
- final byte byte1, final byte byte2, final byte byte3, final byte byte4,
- final Appendable dst)
- throws IOException, Utf8CodingException {
- if (isNotTrailingByte(byte2)
- // Check that 1 <= plane <= 16. Tricky optimized form of:
- // valid 4-byte leading byte?
- // if (byte1 > (byte) 0xF4 ||
- // overlong? 4 most significant bits must not all be zero
- // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
- // codepoint larger than the highest code point (U+10FFFF)?
- // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
- || ((((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0)
- || isNotTrailingByte(byte3)
- || isNotTrailingByte(byte4)) {
- final byte[] out = new byte[] { byte1, byte2, byte3, byte4 };
- throw Utf8CodingException.illegalUtf8DecodeByteSequence(out);
- }
- final int codepoint = ((byte1 & 0x07) << 18)
- | (trailingByteValue(byte2) << 12)
- | (trailingByteValue(byte3) << 6)
- | trailingByteValue(byte4);
- dst.append(DecodeUtil.highSurrogate(codepoint));
- dst.append(DecodeUtil.lowSurrogate(codepoint));
- }
-
- static void handleFourBytesCharBuffer(
- final byte byte1, final byte byte2, final byte byte3, final byte byte4,
- final CharBuffer cb, final char[] ca, final int cp)
- throws Utf8CodingException {
- if (isNotTrailingByte(byte2)
- // Check that 1 <= plane <= 16. Tricky optimized form of:
- // valid 4-byte leading byte?
- // if (byte1 > (byte) 0xF4 ||
- // overlong? 4 most significant bits must not all be zero
- // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
- // codepoint larger than the highest code point (U+10FFFF)?
- // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
- || ((((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0)
- || isNotTrailingByte(byte3)
- || isNotTrailingByte(byte4)) {
- cb.position(cp - cb.arrayOffset());
- final byte[] out = new byte[] { byte1, byte2, byte3, byte4 };
- throw Utf8CodingException.illegalUtf8DecodeByteSequence(out);
- }
- final int codepoint = ((byte1 & 0x07) << 18)
- | (trailingByteValue(byte2) << 12)
- | (trailingByteValue(byte3) << 6)
- | trailingByteValue(byte4);
- ca[cp] = DecodeUtil.highSurrogate(codepoint);
- ca[cp + 1] = DecodeUtil.lowSurrogate(codepoint);
- }
-
- /*
- * Returns whether the byte is not a valid continuation of the form '10XXXXXX'.
- */
- private static boolean isNotTrailingByte(final byte b) {
- return b > (byte) 0xBF;
- }
-
- /*
- * Returns the actual value of the trailing byte (removes the prefix '10') for composition.
- */
- private static int trailingByteValue(final byte b) {
- return b & 0x3F;
- }
-
- private static char highSurrogate(final int codePoint) {
- return (char)
- ((Character.MIN_HIGH_SURROGATE
- - (Character.MIN_SUPPLEMENTARY_CODE_POINT >>> 10))
- + (codePoint >>> 10));
- }
-
- private static char lowSurrogate(final int codePoint) {
- return (char) (Character.MIN_LOW_SURROGATE + (codePoint & 0x3ff));
- }
- }
-
-}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
index f5eb8cf..c4c8afb 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
@@ -19,7 +19,6 @@
package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BOOLEAN_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_BYTE_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_CHAR_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_DOUBLE_BASE_OFFSET;
@@ -199,20 +198,6 @@ public class XxHash64 {
return hash;
}
- /**
- * Hash the given arr starting at the given offset and continuing for the given length using the
- * given seed.
- * @param arr the given array
- * @param offsetBooleans starting at this offset
- * @param lengthBooleans continuing for this length
- * @param seed the given seed
- * @return the hash
- */
- public static long hashBooleans(final boolean[] arr, final long offsetBooleans,
- final long lengthBooleans, final long seed) {
- return hash(arr, ARRAY_BOOLEAN_BASE_OFFSET + offsetBooleans, lengthBooleans, seed);
- }
-
/**
* Hash the given arr starting at the given offset and continuing for the given length using the
* given seed.
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 423e59a..799da75 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -29,7 +29,9 @@ import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
+import java.io.IOException;
import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
import org.apache.datasketches.memory.Memory;
import org.testng.annotations.BeforeClass;
@@ -44,7 +46,7 @@ public class AllocateDirectMapMemoryTest {
}
@Test(expectedExceptions = IllegalStateException.class)
- public void simpleMap() {
+ public void simpleMap() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
assertTrue(AllocateDirectWritableMap.isFileReadOnly(file));
try (Memory mem = Memory.map(file)) {
@@ -53,32 +55,37 @@ public class AllocateDirectMapMemoryTest {
}
@Test
- public void printGettysbergAddress() {
+ public void printGettysbergAddress() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
try (Memory mem = Memory.map(file))
{
- println("Mem Cap: " + mem.getCapacity());
+ int len1 = (int)mem.getCapacity();
+ println("Mem Cap: " + len1);
println("Total Offset: " + mem.getTotalOffset());
println("Cum Offset: " + ((ResourceImpl)mem).getCumulativeOffset(0));
println("Total Offset: " + mem.getTotalOffset());
- StringBuilder sb = new StringBuilder();
- mem.getCharsFromUtf8(43, 176, sb);
- println(sb.toString());
+ byte[] bArr = new byte[len1];
+ mem.getByteArray(0, bArr, 0, len1);
+ String s = new String(bArr, StandardCharsets.UTF_8);
+ println(s);
println("");
- Memory mem2 = mem.region(43 + 76, 20);
- println("Mem Cap: " + mem2.getCapacity());
+ Memory mem2 = mem.region(43 + 76, 34);
+ int len2 = (int)mem2.getCapacity();
+ println("Mem Cap: " + len2);
println("Offset: " + mem.getTotalOffset());
println("Cum Offset: " + ((ResourceImpl)mem2).getCumulativeOffset(0));
println("Total Offset: " + mem2.getTotalOffset());
- StringBuilder sb2 = new StringBuilder();
- mem2.getCharsFromUtf8(0, 12, sb2);
- println(sb2.toString());
+ byte[] bArr2 = new byte[len2];
+ mem2.getByteArray(0, bArr2, 0, len2);
+ String s2 = new String(bArr2,StandardCharsets.UTF_8);
+ println(s2);
+ assertEquals(s2,"a new nation, conceived in Liberty");
}
}
@Test
- public void testIllegalArguments() {
+ public void testIllegalArguments() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
try (Memory mem = Memory.map(file, -1, Integer.MAX_VALUE, ByteOrder.nativeOrder())) {
fail("Failed: Position was negative.");
@@ -94,7 +101,7 @@ public class AllocateDirectMapMemoryTest {
}
@Test(expectedExceptions = IllegalStateException.class)
- public void testAccessAfterClose() {
+ public void testAccessAfterClose() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
try (Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
@@ -106,7 +113,7 @@ public class AllocateDirectMapMemoryTest {
}
@Test(expectedExceptions = IllegalStateException.class)
- public void testReadFailAfterClose() {
+ public void testReadFailAfterClose() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder());
@@ -115,7 +122,7 @@ public class AllocateDirectMapMemoryTest {
}
@Test
- public void testLoad() {
+ public void testLoad() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
try (Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
index c259fda..65fe97a 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
@@ -34,7 +34,7 @@ public class AllocateDirectMemoryTest {
@Test(expectedExceptions = IllegalStateException.class)
public void simpleAllocateDirect() {
int longs = 32;
- try (WritableMemory wMem = WritableMemory.allocateDirect(longs << 3)) {
+ try (WritableMemory wMem = WritableMemory.allocateDirect(longs << 3, null)) {
for (int i = 0; i < longs; i++) {
wMem.putLong(i << 3, i);
assertEquals(wMem.getLong(i << 3), i);
@@ -49,7 +49,7 @@ public class AllocateDirectMemoryTest {
public void checkDefaultMemoryRequestServer() {
int longs1 = 32;
int bytes1 = longs1 << 3;
- try (WritableMemory origWmem = WritableMemory.allocateDirect(bytes1)) {
+ try (WritableMemory origWmem = WritableMemory.allocateDirect(bytes1, null)) {
for (int i = 0; i < longs1; i++) { //puts data in wMem1
origWmem.putLong(i << 3, i);
assertEquals(origWmem.getLong(i << 3), i);
@@ -87,7 +87,7 @@ public class AllocateDirectMemoryTest {
@Test
public void checkExplicitClose() {
final long cap = 128;
- WritableMemory wMem = WritableMemory.allocateDirect(cap);
+ WritableMemory wMem = WritableMemory.allocateDirect(cap, null);
assertTrue(wMem.isValid());
wMem.close();
assertFalse(wMem.isValid());
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
index 98d3c2a..8f0e7cf 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
@@ -87,7 +87,7 @@ public class AllocateDirectWritableMapMemoryTest {
try (
WritableMemory dstMem = WritableMemory.writableMap(file, 0, bytes, ByteOrder.nativeOrder());
- WritableMemory srcMem = WritableMemory.allocateDirect(bytes)) {
+ WritableMemory srcMem = WritableMemory.allocateDirect(bytes, null)) {
for (long i = 0; i < longs; i++) {
srcMem.putLong(i << 3, i); //load source with consecutive longs
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
index 759fdd5..88c9859 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
@@ -77,7 +77,7 @@ public class BaseBufferTest {
public void checkCheckValid() {
Buffer buf;
- try (WritableMemory wmem = WritableMemory.allocateDirect(100)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(100, null)) {
buf = wmem.asBuffer();
}
@SuppressWarnings("unused")
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
index d40ce05..bf8f683 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
@@ -222,30 +222,6 @@ public class Buffer2Test {
assertEquals(doubleArray, copyDoubleArray);
}
- @Test
- public void testWrapBooleanArray() {
- boolean[] booleanArray = new boolean[64];
-
- for (int i = 0; i < 64; i++) {
- if ((i % 3) == 0) {
- booleanArray[i] = true;
- }
- }
-
- Buffer buffer = Memory.wrap(booleanArray).asBuffer();
- int i = 0;
- while (buffer.hasRemaining()) {
- assertEquals(booleanArray[i++], buffer.getBoolean());
- }
-
- buffer.setPosition(0);
- boolean[] copyBooleanArray = new boolean[64];
- buffer.getBooleanArray(copyBooleanArray, 0, 64);
- for (int j = 0; j < copyBooleanArray.length; j++) {
- assertEquals(booleanArray[j], copyBooleanArray[j]);
- }
- }
-
@Test
public void testByteBufferPositionPreservation() {
ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
@@ -353,7 +329,7 @@ public class Buffer2Test {
for (int i = 0; i < n; i++) { arr[i] = i; }
Memory mem = Memory.wrap(arr);
Buffer buf = mem.asBuffer();
- Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getByteOrder()); //top half
+ Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getTypeByteOrder()); //top half
for (int i = 0; i < n2; i++) {
long v = reg.getLong(i * 8);
long e = i + n2;
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
index acc7f79..c54ca5c 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
@@ -161,7 +161,7 @@ public class BufferInvariantsTest {
@Test
public void checkLimitsDirect() throws Exception {
- try (WritableMemory wmem = WritableMemory.allocateDirect(100)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(100, null)) {
Buffer buf = wmem.asBuffer();
buf.setStartPositionEnd(40, 45, 50);
buf.setStartPositionEnd(0, 0, 100);
@@ -231,7 +231,7 @@ public class BufferInvariantsTest {
@Test
public void testBufDirect() throws Exception {
int n = 25;
- try (WritableMemory wmem = WritableMemory.allocateDirect(n)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(n, null)) {
WritableBuffer buf = wmem.asWritableBuffer();
for (byte i = 0; i < n; i++) { buf.putByte(i); }
buf.setPosition(0);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
index 73a9da2..a1c21c0 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
@@ -118,11 +118,6 @@ public class BufferReadWriteSafetyTest {
buf.putByteArray(new byte[] {1}, 0, 1);
}
- @Test(expectedExceptions = ReadOnlyException.class)
- public void testPutBooleanArray() {
- buf.putBooleanArray(new boolean[] {true}, 0, 1);
- }
-
@Test(expectedExceptions = ReadOnlyException.class)
public void testPutShortArray() {
buf.putShortArray(new short[] {1}, 0, 1);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
index 529eb5e..232f4ec 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
@@ -38,7 +38,7 @@ public class BufferTest {
@Test
public void checkDirectRoundTrip() throws Exception {
int n = 1024; //longs
- try (WritableMemory wmem = WritableMemory.allocateDirect(n * 8)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(n * 8, null)) {
WritableBuffer wbuf = wmem.asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
@@ -93,7 +93,6 @@ public class BufferTest {
buffersToCheck.add(WritableMemory.allocate(0).asBuffer());
buffersToCheck.add(WritableBuffer.writableWrap(ByteBuffer.allocate(0)));
buffersToCheck.add(Buffer.wrap(ByteBuffer.allocate(0)));
- buffersToCheck.add(Memory.wrap(new boolean[0]).asBuffer());
buffersToCheck.add(Memory.wrap(new byte[0]).asBuffer());
buffersToCheck.add(Memory.wrap(new char[0]).asBuffer());
buffersToCheck.add(Memory.wrap(new short[0]).asBuffer());
@@ -202,7 +201,7 @@ public class BufferTest {
ByteBuffer bb = ByteBuffer.allocate(n * 8);
bb.order(ByteOrder.BIG_ENDIAN);
Buffer buf = Buffer.wrap(bb);
- assertEquals(buf.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertEquals(buf.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@Test
@@ -282,7 +281,7 @@ public class BufferTest {
@Test(expectedExceptions = IllegalStateException.class)
public void checkParentUseAfterFree() throws Exception {
int bytes = 64 * 8;
- WritableMemory wmem = WritableMemory.allocateDirect(bytes);
+ WritableMemory wmem = WritableMemory.allocateDirect(bytes, null);
WritableBuffer wbuf = wmem.asWritableBuffer();
wmem.close();
wbuf.getLong();
@@ -291,7 +290,7 @@ public class BufferTest {
@Test(expectedExceptions = IllegalStateException.class)
public void checkRegionUseAfterFree() throws Exception {
int bytes = 64;
- WritableMemory wmem = WritableMemory.allocateDirect(bytes);
+ WritableMemory wmem = WritableMemory.allocateDirect(bytes, null);
Buffer reg = wmem.asBuffer().region();
wmem.close();
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
index 3cbe87d..4248ec2 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
@@ -30,7 +30,7 @@ public class CommonBufferTest {
@Test
public void checkSetGet() throws Exception {
int memCapacity = 60; //must be at least 60
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetTests(buf);
@@ -131,7 +131,7 @@ public class CommonBufferTest {
@Test
public void checkSetGetArrays() throws Exception {
int memCapacity = 32;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetArraysTests(buf);
@@ -141,18 +141,6 @@ public class CommonBufferTest {
public static void setGetArraysTests(WritableBuffer buf) {
int words = 4;
- boolean[] srcArray1 = {true, false, true, false};
- boolean[] dstArray1 = new boolean[words];
- buf.resetPosition();
- buf.fill((byte)127);
- buf.resetPosition();
- buf.putBooleanArray(srcArray1, 0, words);
- buf.resetPosition();
- buf.getBooleanArray(dstArray1, 0, words);
- for (int i = 0; i < words; i++) {
- assertEquals(dstArray1[i], srcArray1[i]);
- }
-
byte[] srcArray2 = { 1, -2, 3, -4 };
byte[] dstArray2 = new byte[4];
buf.resetPosition();
@@ -227,7 +215,7 @@ public class CommonBufferTest {
@Test
public void checkSetGetPartialArraysWithOffset() throws Exception {
int memCapacity = 32;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetPartialArraysWithOffsetTests(buf);
@@ -236,15 +224,6 @@ public class CommonBufferTest {
public static void setGetPartialArraysWithOffsetTests(WritableBuffer buf) {
int items = 4;
- boolean[] srcArray1 = {true, false, true, false};
- boolean[] dstArray1 = new boolean[items];
- buf.resetPosition();
- buf.putBooleanArray(srcArray1, 2, items / 2);
- buf.resetPosition();
- buf.getBooleanArray(dstArray1, 2, items / 2);
- for (int i = 2; i < items; i++) {
- assertEquals(dstArray1[i], srcArray1[i]);
- }
byte[] srcArray2 = { 1, -2, 3, -4 };
byte[] dstArray2 = new byte[items];
@@ -320,7 +299,7 @@ public class CommonBufferTest {
@Test
public void checkSetClearMemoryRegions() throws Exception {
int memCapacity = 64; //must be 64
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setClearMemoryRegionsTests(buf); //requires println enabled to visually check
@@ -407,7 +386,7 @@ public class CommonBufferTest {
@Test
public void checkToHexStringAllMem() throws Exception {
int memCapacity = 48; //must be 48
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
toHexStringAllMemTests(buf); //requires println enabled to visually check
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
index b617ccc..22318b4 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
@@ -35,7 +35,7 @@ public class CommonMemoryTest {
@Test
public void checkSetGet() throws Exception {
int memCapacity = 16; //must be at least 8
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
assertEquals(mem.getCapacity(), memCapacity);
setGetTests(mem);
}
@@ -86,7 +86,7 @@ public class CommonMemoryTest {
@Test
public void checkSetGetArrays() throws Exception {
int memCapacity = 32;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
assertEquals(memCapacity, mem.getCapacity());
setGetArraysTests(mem);
}
@@ -96,14 +96,6 @@ public class CommonMemoryTest {
int accessCapacity = (int)mem.getCapacity();
int words = 4;
- boolean[] srcArray1 = {true, false, true, false};
- boolean[] dstArray1 = new boolean[words];
- mem.fill(0, accessCapacity, (byte)127);
- mem.putBooleanArray(0, srcArray1, 0, words);
- mem.getBooleanArray(0, dstArray1, 0, words);
- for (int i = 0; i < words; i++) {
- assertEquals(dstArray1[i], srcArray1[i]);
- }
byte[] srcArray2 = { 1, -2, 3, -4 };
byte[] dstArray2 = new byte[4];
@@ -165,7 +157,7 @@ public class CommonMemoryTest {
@Test
public void checkSetGetPartialArraysWithOffset() throws Exception {
int memCapacity = 32;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
assertEquals(memCapacity, mem.getCapacity());
setGetPartialArraysWithOffsetTests(mem);
}
@@ -173,13 +165,6 @@ public class CommonMemoryTest {
public static void setGetPartialArraysWithOffsetTests(WritableMemory mem) {
int items = 4;
- boolean[] srcArray1 = {true, false, true, false};
- boolean[] dstArray1 = new boolean[items];
- mem.putBooleanArray(0, srcArray1, 2, items / 2);
- mem.getBooleanArray(0, dstArray1, 2, items / 2);
- for (int i = 2; i < items; i++) {
- assertEquals(dstArray1[i], srcArray1[i]);
- }
byte[] srcArray2 = { 1, -2, 3, -4 };
byte[] dstArray2 = new byte[items];
@@ -241,7 +226,7 @@ public class CommonMemoryTest {
@Test
public void checkSetClearIsBits() throws Exception {
int memCapacity = 8;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
assertEquals(memCapacity, mem.getCapacity());
mem.clear();
setClearIsBitsTests(mem);
@@ -281,7 +266,7 @@ public class CommonMemoryTest {
@Test
public void checkSetClearMemoryRegions() throws Exception {
int memCapacity = 64; //must be 64
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
setClearMemoryRegionsTests(mem); //requires println enabled to visually check
for (int i = 0; i < memCapacity; i++) {
assertEquals(mem.getByte(i), 0);
@@ -350,7 +335,7 @@ public class CommonMemoryTest {
@Test
public void checkToHexStringAllMem() throws Exception {
int memCapacity = 48; //must be 48
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
toHexStringAllMemTests(mem); //requires println enabled to visually check
}
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
index 9529c1a..259c3e2 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
@@ -91,7 +91,7 @@ public class CopyMemoryOverlapTest {
println("CopyUp : " + copyUp);
println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
- try (WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes)) {
+ try (WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, null)) {
fill(backingMem); //fill mem with 0 thru copyLongs -1
//listMem(backingMem, "Original");
backingMem.copyTo(fromOffsetBytes, backingMem, toOffsetBytes, copyBytes);
@@ -130,7 +130,7 @@ public class CopyMemoryOverlapTest {
println("CopyUp : " + copyUp);
println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
- try (WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes)) {
+ try (WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, null)) {
fill(backingMem); //fill mem with 0 thru copyLongs -1
//listMem(backingMem, "Original");
WritableMemory reg1 = backingMem.writableRegion(fromOffsetBytes, copyBytes);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
index 3de76d7..f9957ed 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
@@ -147,7 +147,7 @@ public class CopyMemoryTest {
}
private static WritableMemory genWRH(int longs, boolean empty) {
- WritableMemory mem = WritableMemory.allocateDirect(longs << 3);
+ WritableMemory mem = WritableMemory.allocateDirect(longs << 3, null);
if (empty) {
mem.clear();
} else {
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
index 842cab2..0813f52 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/IgnoredArrayOverflowTest.java
@@ -31,7 +31,7 @@ public class IgnoredArrayOverflowTest {
@BeforeClass
public void allocate() {
- memory = WritableMemory.allocateDirect(MAX_SIZE);
+ memory = WritableMemory.allocateDirect(MAX_SIZE, null);
}
@AfterClass
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
index 7951492..0561b8f 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
@@ -85,7 +85,7 @@ public class LeafImplTest {
WritableMemory mem = WritableMemory.writableWrap(bb, NBO, dummyMemReqSvr);
assertEquals(bb.isDirect(), mem.isDirectResource());
assertNotNull(((ResourceImpl)mem).getUnsafeObject());
- checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getByteOrder(), true, true);
+ checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getTypeByteOrder(), true, true);
//BB off heap, native order, has ByteBuffer, has MemReqSvr
ByteBuffer dbb = ByteBuffer.allocateDirect((int)cap);
@@ -94,7 +94,7 @@ public class LeafImplTest {
mem = WritableMemory.writableWrap(dbb, NBO, dummyMemReqSvr);
assertEquals(dbb.isDirect(), mem.isDirectResource());
assertNull(((ResourceImpl)mem).getUnsafeObject());
- checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getByteOrder(), true, true);
+ checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getTypeByteOrder(), true, true);
//BB on heap, non native order, has ByteBuffer, has MemReqSvr
bb = ByteBuffer.allocate((int)cap);
@@ -103,7 +103,7 @@ public class LeafImplTest {
mem = WritableMemory.writableWrap(bb, NNBO, dummyMemReqSvr);
assertEquals(bb.isDirect(), mem.isDirectResource());
assertNotNull(((ResourceImpl)mem).getUnsafeObject());
- checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getByteOrder(), true, true);
+ checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getTypeByteOrder(), true, true);
//BB off heap, non native order, has ByteBuffer, has MemReqSvr
dbb = ByteBuffer.allocateDirect((int)cap);
@@ -112,7 +112,7 @@ public class LeafImplTest {
mem = WritableMemory.writableWrap(dbb, NNBO, dummyMemReqSvr);
assertEquals(dbb.isDirect(), mem.isDirectResource());
assertNull(((ResourceImpl)mem).getUnsafeObject());
- checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getByteOrder(), true, true);
+ checkCombinations(mem, off, cap, mem.isDirectResource(), mem.getTypeByteOrder(), true, true);
}
@Test
@@ -178,7 +178,7 @@ public class LeafImplTest {
ByteBuffer bb = ((ResourceImpl)mem).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
- assertTrue(mem.getByteOrder() == bo);
+ assertTrue(mem.getTypeByteOrder() == bo);
if (hasMemReqSvr) { assertTrue(mem.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
else { assertNull(mem.getMemoryRequestServer()); }
@@ -207,7 +207,7 @@ public class LeafImplTest {
bb = ((ResourceImpl)buf).getByteBuffer();
assertTrue(hasByteBuffer ? bb != null : bb == null);
- assertTrue(buf.getByteOrder() == bo);
+ assertTrue(buf.getTypeByteOrder() == bo);
if (hasMemReqSvr) { assertTrue(buf.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
else { assertNull(buf.getMemoryRequestServer()); }
@@ -235,7 +235,7 @@ public class LeafImplTest {
bb = ((ResourceImpl)nnMem).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
- assertTrue(nnMem.getByteOrder() == oo);
+ assertTrue(nnMem.getTypeByteOrder() == oo);
if (hasMemReqSvr) { assertTrue(nnMem.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
@@ -262,7 +262,7 @@ public class LeafImplTest {
bb = ((ResourceImpl)nnBuf).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
- assertTrue(nnBuf.getByteOrder() == oo);
+ assertTrue(nnBuf.getTypeByteOrder() == oo);
if (hasMemReqSvr) { assertTrue(nnBuf.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
index 1a2ae5d..b76d03c 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
@@ -82,11 +82,6 @@ public class MemoryReadWriteSafetyTest {
mem.putByteArray(0, new byte[] {1}, 0, 1);
}
- @Test(expectedExceptions = ReadOnlyException.class)
- public void testPutBooleanArray() {
- mem.putBooleanArray(0, new boolean[] {true}, 0, 1);
- }
-
@Test(expectedExceptions = ReadOnlyException.class)
public void testPutShortArray() {
mem.putShortArray(0, new short[] {1}, 0, 1);
@@ -143,12 +138,6 @@ public class MemoryReadWriteSafetyTest {
mem1.putInt(0, 1);
}
- @Test(expectedExceptions = ReadOnlyException.class)
- public void testBooleanArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new boolean[8]);
- mem1.putInt(0, 1);
- }
-
@Test(expectedExceptions = ReadOnlyException.class)
public void testShortArrayWrap() {
WritableMemory mem1 = (WritableMemory) Memory.wrap(new short[8]);
@@ -206,7 +195,7 @@ public class MemoryReadWriteSafetyTest {
}
@Test(expectedExceptions = ReadOnlyException.class)
- public void testWritableMapWithROFile() {
+ public void testWritableMapWithROFile() throws IOException {
File tempFile;
try {
tempFile = File.createTempFile("test", ".tmp", null);
@@ -220,7 +209,7 @@ public class MemoryReadWriteSafetyTest {
}
@Test(expectedExceptions = ReadOnlyException.class)
- public void testMapFileWithOffsetsAndBO() {
+ public void testMapFileWithOffsetsAndBO() throws IOException {
File tempFile;
try {
tempFile = File.createTempFile("test", ".tmp", null);
@@ -234,7 +223,7 @@ public class MemoryReadWriteSafetyTest {
}
@Test(expectedExceptions = IllegalArgumentException.class)
- public void testMapFileBeyondTheFileSize() {
+ public void testMapFileBeyondTheFileSize() throws IOException {
File tempFile;
try {
tempFile = File.createTempFile("test", ".tmp", null);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index a211db6..7259942 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -23,6 +23,7 @@
package org.apache.datasketches.memory.internal;
+import static org.apache.datasketches.memory.Resource.defaultMemReqSvr;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
@@ -54,7 +55,7 @@ public class MemoryTest {
@Test
public void checkDirectRoundTrip() throws Exception {
int n = 1024; //longs
- try (WritableMemory mem = WritableMemory.allocateDirect(n * 8)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(n * 8, defaultMemReqSvr)) {
for (int i = 0; i < n; i++) {
mem.putLong(i * 8, i);
}
@@ -96,7 +97,7 @@ public class MemoryTest {
assertEquals(v, i);
}
// check 0 length array wraps
- Memory memZeroLengthArrayBoolean = WritableMemory.writableWrap(new boolean[0]);
+ //Memory memZeroLengthArrayBoolean = WritableMemory.writableWrap(new boolean[0]);
Memory memZeroLengthArrayByte = WritableMemory.writableWrap(new byte[0]);
Memory memZeroLengthArrayChar = WritableMemory.writableWrap(new char[0]);
Memory memZeroLengthArrayShort = WritableMemory.writableWrap(new short[0]);
@@ -104,7 +105,7 @@ public class MemoryTest {
Memory memZeroLengthArrayLong = WritableMemory.writableWrap(new long[0]);
Memory memZeroLengthArrayFloat = WritableMemory.writableWrap(new float[0]);
Memory memZeroLengthArrayDouble = WritableMemory.writableWrap(new double[0]);
- assertEquals(memZeroLengthArrayBoolean.getCapacity(), 0);
+ //assertEquals(memZeroLengthArrayBoolean.getCapacity(), 0);
assertEquals(memZeroLengthArrayByte.getCapacity(), 0);
assertEquals(memZeroLengthArrayChar.getCapacity(), 0);
assertEquals(memZeroLengthArrayShort.getCapacity(), 0);
@@ -117,7 +118,7 @@ public class MemoryTest {
List<Memory> memoryToCheck = Lists.newArrayList();
memoryToCheck.add(WritableMemory.allocate(0));
memoryToCheck.add(WritableMemory.writableWrap(ByteBuffer.allocate(0)));
- memoryToCheck.add(WritableMemory.writableWrap(new boolean[0]));
+ //memoryToCheck.add(WritableMemory.writableWrap(new boolean[0]));
memoryToCheck.add(WritableMemory.writableWrap(new byte[0]));
memoryToCheck.add(WritableMemory.writableWrap(new char[0]));
memoryToCheck.add(WritableMemory.writableWrap(new short[0]));
@@ -126,7 +127,7 @@ public class MemoryTest {
memoryToCheck.add(WritableMemory.writableWrap(new float[0]));
memoryToCheck.add(WritableMemory.writableWrap(new double[0]));
memoryToCheck.add(Memory.wrap(ByteBuffer.allocate(0)));
- memoryToCheck.add(Memory.wrap(new boolean[0]));
+ //memoryToCheck.add(Memory.wrap(new boolean[0]));
memoryToCheck.add(Memory.wrap(new byte[0]));
memoryToCheck.add(Memory.wrap(new char[0]));
memoryToCheck.add(Memory.wrap(new short[0]));
@@ -207,8 +208,8 @@ public class MemoryTest {
ByteBuffer bb = ByteBuffer.allocate(n * 8);
bb.order(ByteOrder.BIG_ENDIAN);
Memory mem = Memory.wrap(bb);
- assertFalse(mem.getByteOrder() == ByteOrder.nativeOrder());
- assertEquals(mem.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertFalse(mem.getTypeByteOrder() == ByteOrder.nativeOrder());
+ assertEquals(mem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@Test
@@ -319,7 +320,7 @@ public class MemoryTest {
@Test(expectedExceptions = IllegalStateException.class)
public void checkParentUseAfterFree() throws Exception {
int bytes = 64 * 8;
- WritableMemory wmem = WritableMemory.allocateDirect(bytes);
+ WritableMemory wmem = WritableMemory.allocateDirect(bytes, defaultMemReqSvr);
wmem.close();
wmem.getLong(0);
}
@@ -327,7 +328,7 @@ public class MemoryTest {
@Test(expectedExceptions = IllegalStateException.class)
public void checkRegionUseAfterFree() throws Exception {
int bytes = 64;
- Memory mem = WritableMemory.allocateDirect(bytes);
+ Memory mem = WritableMemory.allocateDirect(bytes, defaultMemReqSvr);
Memory region = mem.region(0L, bytes);
mem.close();
region.getByte(0);
@@ -344,7 +345,7 @@ public class MemoryTest {
wbuf = wmem.asWritableBuffer();
assertNull(wbuf.getMemoryRequestServer());
//OFF HEAP
- try (WritableMemory wmem2 = WritableMemory.allocateDirect(16)) { //OFF HEAP
+ try (WritableMemory wmem2 = WritableMemory.allocateDirect(16, defaultMemReqSvr)) { //OFF HEAP
assertNull(wmem2.getMemoryRequestServer());
wbuf = wmem2.asWritableBuffer();
assertNull(wbuf.getMemoryRequestServer());
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
index 5483036..fd2f4fe 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
@@ -57,7 +57,7 @@ public class MemoryWriteToTest {
@Test
public void testOffHeap() throws Exception {
try (WritableMemory mem =
- WritableMemory.allocateDirect((UNSAFE_COPY_THRESHOLD_BYTES * 5) + 10)) {
+ WritableMemory.allocateDirect((UNSAFE_COPY_THRESHOLD_BYTES * 5) + 10, null)) {
testWriteTo(mem.region(0, 0));
testOffHeap(mem, 7);
testOffHeap(mem, 1023);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
index 7a60d11..b846e36 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
@@ -43,7 +43,7 @@ public class NativeWritableBufferImplTest {
@Test
public void checkNativeCapacityAndClose() {
int memCapacity = 64;
- WritableMemory wmem = WritableMemory.allocateDirect(memCapacity);
+ WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, null);
WritableBuffer wbuf = wmem.asWritableBuffer();
assertEquals(wbuf.getCapacity(), memCapacity);
@@ -53,25 +53,6 @@ public class NativeWritableBufferImplTest {
//Simple Heap arrays
- @Test
- public void checkBooleanArray() {
- boolean[] srcArray = { true, false, true, false, false, true, true, false };
- boolean[] dstArray = new boolean[8];
-
- Buffer buf = Memory.wrap(srcArray).asBuffer();
- buf.getBooleanArray(dstArray, 0, 8);
- for (int i = 0; i < 8; i++) {
- assertEquals(dstArray[i], srcArray[i]);
- }
-
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
- wbuf.getBooleanArray(dstArray, 0, 8);
- for (int i = 0; i < 8; i++) {
- assertEquals(dstArray[i], srcArray[i]);
- }
- assertTrue(buf.isHeapResource());
- }
-
@Test
public void checkByteArray() {
byte[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
@@ -201,7 +182,7 @@ public class NativeWritableBufferImplTest {
@Test
public void checkNativeBaseBound() {
int memCapacity = 64;
- try (WritableMemory wmem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer wbuf = wmem.asWritableBuffer();
wbuf.toHexString("Bounds Exception", memCapacity, 8); //Bounds Exception
fail("Should have thrown MemoryBoundsException");
@@ -213,7 +194,7 @@ public class NativeWritableBufferImplTest {
@Test
public void checkNativeSrcArrayBound() {
long memCapacity = 64;
- try (WritableMemory wmem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer wbuf = wmem.asWritableBuffer();
byte[] srcArray = { 1, -2, 3, -4 };
wbuf.putByteArray(srcArray, 0, 5); //should be 4!
@@ -226,9 +207,9 @@ public class NativeWritableBufferImplTest {
@Test(expectedExceptions = MemoryBoundsException.class)
public void checkRegionBounds() {
int memCapacity = 64;
- try (WritableMemory wmem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer wbuf = wmem.asWritableBuffer();
- wbuf.writableRegion(1, 64, wbuf.getByteOrder()); //off by one
+ wbuf.writableRegion(1, 64, wbuf.getTypeByteOrder()); //off by one
}
}
@@ -340,7 +321,7 @@ public class NativeWritableBufferImplTest {
int memCapacity = 64;
WritableBuffer mem = WritableMemory.allocate(memCapacity).asWritableBuffer();
assertFalse(mem.isDirectResource());
- try (WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, null)) {
WritableBuffer wbuf = mem2.asWritableBuffer();
assertTrue(wbuf.isDirectResource());
}
@@ -395,9 +376,9 @@ public class NativeWritableBufferImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- try (WritableMemory mem1 = WritableMemory.allocateDirect(4);
- WritableMemory mem2 = WritableMemory.allocateDirect(4);
- WritableMemory mem3 = WritableMemory.allocateDirect(5))
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(4, null);
+ WritableMemory mem2 = WritableMemory.allocateDirect(4, null);
+ WritableMemory mem3 = WritableMemory.allocateDirect(5, null))
{
mem1.putByteArray(0, arr1, 0, 4);
mem2.putByteArray(0, arr2, 0, 4);
@@ -542,13 +523,13 @@ public class NativeWritableBufferImplTest {
ByteBuffer bb = ByteBuffer.allocate(64);
WritableBuffer wbuf = WritableBuffer.writableWrap(bb);
@SuppressWarnings("unused")
- WritableBuffer wreg = wbuf.writableRegion(0, 1, wbuf.getByteOrder());
+ WritableBuffer wreg = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
try {
Buffer buf = Buffer.wrap(bb);
wbuf = (WritableBuffer) buf;
@SuppressWarnings("unused")
- WritableBuffer wreg2 = wbuf.writableRegion(0, 1, wbuf.getByteOrder());
+ WritableBuffer wreg2 = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
fail("Should have thrown exception");
} catch (ReadOnlyException expected) {
// ignore
@@ -559,7 +540,7 @@ public class NativeWritableBufferImplTest {
public void checkZeroBuffer() {
WritableMemory wmem = WritableMemory.allocate(8);
WritableBuffer wbuf = wmem.asWritableBuffer();
- WritableBuffer reg = wbuf.writableRegion(0, 0, wbuf.getByteOrder());
+ WritableBuffer reg = wbuf.writableRegion(0, 0, wbuf.getTypeByteOrder());
assertEquals(reg.getCapacity(), 0);
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
index f8a07e6..fcbcede 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
@@ -42,7 +42,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkNativeCapacityAndClose() {
int memCapacity = 64;
- WritableMemory mem = WritableMemory.allocateDirect(memCapacity);
+ WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null);
assertEquals(memCapacity, mem.getCapacity());
mem.close(); //intentional
@@ -51,25 +51,6 @@ public class NativeWritableMemoryImplTest {
//Simple Native arrays
- @Test
- public void checkBooleanArray() {
- boolean[] srcArray = { true, false, true, false, false, true, true, false };
- boolean[] dstArray = new boolean[8];
-
- Memory mem = Memory.wrap(srcArray);
- mem.getBooleanArray(0, dstArray, 0, 8);
- for (int i = 0; i < 8; i++) {
- assertEquals(dstArray[i], srcArray[i]);
- }
-
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
- wmem.getBooleanArray(0, dstArray, 0, 8);
- for (int i = 0; i < 8; i++) {
- assertEquals(dstArray[i], srcArray[i]);
- }
- assertTrue(mem.isHeapResource());
- }
-
@Test
public void checkByteArray() {
byte[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
@@ -199,7 +180,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkNativeBaseBound() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.toHexString("Force Assertion Error", memCapacity, 8);
fail("Should have thrown MemoryBoundsException");
} catch (MemoryBoundsException e) { //bounds exception
@@ -210,7 +191,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkNativeSrcArrayBound() {
long memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
byte[] srcArray = { 1, -2, 3, -4 };
mem.putByteArray(0L, srcArray, 0, 5);
fail("Should have thrown MemoryBoundsException");
@@ -231,7 +212,7 @@ public class NativeWritableMemoryImplTest {
public void checkCopyWithinNativeSmall() {
int memCapacity = 64;
int half = memCapacity / 2;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.clear();
for (int i = 0; i < half; i++) { //fill first half
@@ -252,7 +233,7 @@ public class NativeWritableMemoryImplTest {
int memCapLongs = memCapacity / 8;
int halfBytes = memCapacity / 2;
int halfLongs = memCapLongs / 2;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.clear();
for (int i = 0; i < halfLongs; i++) {
@@ -270,7 +251,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkCopyWithinNativeSrcBound() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.copyTo(32, mem, 32, 33); //hit source bound check
fail("Should have thrown MemoryBoundsException");
}
@@ -282,7 +263,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkCopyWithinNativeDstBound() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.copyTo(0, mem, 32, 33); //hit dst bound check
fail("Should have thrown MemoryBoundsException");
}
@@ -295,8 +276,8 @@ public class NativeWritableMemoryImplTest {
public void checkCopyCrossNativeSmall() {
int memCapacity = 64;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity);
- WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity))
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null);
+ WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, null))
{
for (int i = 0; i < memCapacity; i++) {
mem1.putByte(i, (byte) i);
@@ -315,8 +296,8 @@ public class NativeWritableMemoryImplTest {
int memCapacity = (2 << 20) + 64;
int memCapLongs = memCapacity / 8;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity);
- WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity))
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null);
+ WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, null))
{
for (int i = 0; i < memCapLongs; i++) {
mem1.putLong(i * 8, i);
@@ -334,7 +315,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkCopyCrossNativeAndByteArray() {
int memCapacity = 64;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
@@ -353,7 +334,7 @@ public class NativeWritableMemoryImplTest {
public void checkCopyCrossRegionsSameNative() {
int memCapacity = 128;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
@@ -378,7 +359,7 @@ public class NativeWritableMemoryImplTest {
@Test
public void checkCopyCrossNativeArrayAndHierarchicalRegions() {
int memCapacity = 64;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < mem1.getCapacity(); i++) { //fill with numbers
mem1.putByte(i, (byte) i);
@@ -406,7 +387,7 @@ public class NativeWritableMemoryImplTest {
@Test(expectedExceptions = MemoryBoundsException.class)
public void checkRegionBounds() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.writableRegion(1, 64);
}
}
@@ -517,7 +498,7 @@ public class NativeWritableMemoryImplTest {
int memCapacity = 64;
WritableMemory mem = WritableMemory.allocate(memCapacity);
assertFalse(mem.isDirectResource());
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
assertTrue(mem1.isDirectResource());
}
}
@@ -577,9 +558,9 @@ public class NativeWritableMemoryImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- try (WritableMemory mem1 = WritableMemory.allocateDirect(4);
- WritableMemory mem2 = WritableMemory.allocateDirect(4);
- WritableMemory mem3 = WritableMemory.allocateDirect(5))
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(4, null);
+ WritableMemory mem2 = WritableMemory.allocateDirect(4, null);
+ WritableMemory mem3 = WritableMemory.allocateDirect(5, null))
{
mem1.putByteArray(0, arr1, 0, 4);
mem2.putByteArray(0, arr2, 0, 4);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java
index d7f0421..f0c0ec3 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java
@@ -239,10 +239,10 @@ public class NonNativeWritableBufferImplTest {
WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
WritableBuffer wdup = wbuf.writableDuplicate();
- assertEquals(wdup.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertEquals(wdup.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
WritableBuffer wreg = wbuf.writableRegion();
- assertEquals(wreg.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertEquals(wreg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@Test
@@ -251,10 +251,10 @@ public class NonNativeWritableBufferImplTest {
WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
Buffer buf = wmem.asBuffer();
Buffer dup = buf.duplicate();
- assertEquals(dup.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
+ assertEquals(dup.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
Buffer reg = buf.region();
- assertEquals(reg.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
+ assertEquals(reg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
index 26f101d..863231f 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
@@ -169,7 +169,7 @@ public class NonNativeWritableMemoryImplTest {
@Test
public void checkRegion() {
WritableMemory wreg = wmem.writableRegion(0, wmem.getCapacity());
- assertEquals(wreg.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertEquals(wreg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@Test
@@ -177,7 +177,7 @@ public class NonNativeWritableMemoryImplTest {
byte[] bArr1 = new byte[0];
WritableMemory wmem1 = WritableMemory.writableWrap(bArr1, ByteOrder.BIG_ENDIAN);
Memory reg = wmem1.region(0, wmem1.getCapacity());
- assertEquals(reg.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
+ assertEquals(reg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
index 250d0a5..2df41ae 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
@@ -67,7 +67,7 @@ public class SpecificLeafTest {
@Test
public void checkDirectLeaves() {
int bytes = 128;
- try (WritableMemory wmem = WritableMemory.allocateDirect(bytes)) {
+ try (WritableMemory wmem = WritableMemory.allocateDirect(bytes, null)) {
assertTrue(((ResourceImpl)wmem).isDirectResource());
assertFalse(wmem.isReadOnly());
checkCrossLeafTypeIds(wmem);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java
index 89852bd..66aa838 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ThreadTest.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
+import java.io.IOException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
@@ -38,18 +39,18 @@ public class ThreadTest {
Thread altThread;
@BeforeClass
- public void prepareFileAndMemory() {
+ public void prepareFileAndMemory() throws IOException {
UtilTest.setGettysburgAddressFileToReadOnly();
file = getResourceFile("GettysburgAddress.txt");
assertTrue(AllocateDirectWritableMap.isFileReadOnly(file));
}
- void initMap() {
+ void initMap() throws IOException {
mem = Memory.map(file); assertTrue(mem.isValid());
}
void initDirectMem() {
- wmem = WritableMemory.allocateDirect(1024); assertTrue(wmem.isValid());
+ wmem = WritableMemory.allocateDirect(1024, null); assertTrue(wmem.isValid());
}
Runnable tryMapClose = () -> {
@@ -63,7 +64,7 @@ public class ThreadTest {
};
@Test
- public void runTests() {
+ public void runTests() throws IOException {
initMap();
altThread = new Thread(tryMapClose, "altThread"); altThread.start();
mem.close();
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java
deleted file mode 100644
index e59a6ac..0000000
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.datasketches.memory.internal;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
-
-import java.io.IOException;
-import java.nio.CharBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.MemoryBoundsException;
-import org.apache.datasketches.memory.Utf8CodingException;
-import org.apache.datasketches.memory.WritableMemory;
-import org.apache.datasketches.memory.internal.Util.RandomCodePoints;
-import org.testng.annotations.Test;
-
-import com.google.protobuf.ByteString;
-
-/**
- * Adapted version of
- * https://github.com/protocolbuffers/protobuf/blob/master/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java
- *
- * <pre>Copyright 2008 Google Inc. All rights reserved.
- * https://developers.google.com/protocol-buffers/
- * See LICENSE.</pre>
- */
-public class Utf8Test {
-
- @Test
- public void testRoundTripAllValidCodePoints() throws IOException { //the non-surrogate code pts
- for (int cp = Character.MIN_CODE_POINT; cp < Character.MAX_CODE_POINT; cp++) {
- if (!isSurrogateCodePoint(cp)) {
- String refStr = new String(Character.toChars(cp));
- assertRoundTrips(refStr);
- }
- }
- }
-
- @Test
- public void testPutInvalidChars() { //The surrogates must be a pair, thus invalid alone
- WritableMemory mem = WritableMemory.allocate(10);
- WritableMemory emptyMem = WritableMemory.allocate(0);
- for (int c = Character.MIN_SURROGATE; c <= Character.MAX_SURROGATE; c++) {
- assertSurrogate(mem, (char) c);
- assertSurrogate(emptyMem, (char) c);
- }
- }
-
- private static void assertSurrogate(WritableMemory mem, char c) {
- try {
- mem.putCharsToUtf8(0, new String(new char[] {c}));
- fail();
- } catch (Utf8CodingException e) {
- // Expected.
- }
- }
-
- @Test
- public void testPutInvaidSurrogatePairs() {
- WritableMemory mem = WritableMemory.allocate(4);
- StringBuilder sb = new StringBuilder();
- sb.append(Character.MIN_HIGH_SURROGATE);
- sb.append(Character.MAX_HIGH_SURROGATE);
- try {
- mem.putCharsToUtf8(0, sb);
- } catch (Utf8CodingException e) {
- //Expected;
- }
- }
-
- @Test
- public void testPutHighBMP() {
- WritableMemory mem = WritableMemory.allocate(2);
- StringBuilder sb = new StringBuilder();
- sb.append("\uE000");
- try {
- mem.putCharsToUtf8(0, sb);
- } catch (Utf8CodingException e) {
- //Expected;
- }
- }
-
- @Test
- public void testPutExtendedAscii() {
- WritableMemory mem = WritableMemory.allocate(1);
- StringBuilder sb = new StringBuilder();
- sb.append("\u07FF");
- try {
- mem.putCharsToUtf8(0, sb);
- } catch (Utf8CodingException e) {
- //Expected;
- }
- }
-
- @Test
- public void testPutOneAsciiToEmpty() {
- WritableMemory mem = WritableMemory.allocate(0);
- StringBuilder sb = new StringBuilder();
- sb.append("a");
- try {
- mem.putCharsToUtf8(0, sb);
- } catch (Utf8CodingException e) {
- //Expected;
- }
- }
-
- @Test
- public void testPutValidSurrogatePair() {
- WritableMemory mem = WritableMemory.allocate(4);
- StringBuilder sb = new StringBuilder();
- sb.append(Character.MIN_HIGH_SURROGATE);
- sb.append(Character.MIN_LOW_SURROGATE);
- mem.putCharsToUtf8(0, sb);
- }
-
- // Test all 1, 2, 3 invalid byte combinations. Valid ones would have been covered above.
-
- @Test
- public void testOneByte() {
- int valid = 0;
- for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
- ByteString bs = ByteString.copyFrom(new byte[] {(byte) i });
- if (!bs.isValidUtf8()) { //from -128 to -1
- checkInvalidBytes(bs.toByteArray());
- } else {
- valid++; //from 0 to 127
- }
- }
- assertEquals(IsValidUtf8TestUtil.EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, valid);
- }
-
- @Test
- public void testTwoBytes() {
- int valid = 0;
- for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
- for (int j = Byte.MIN_VALUE; j <= Byte.MAX_VALUE; j++) {
- ByteString bs = ByteString.copyFrom(new byte[]{(byte) i, (byte) j});
- if (!bs.isValidUtf8()) {
- checkInvalidBytes(bs.toByteArray());
- } else {
- valid++;
- }
- }
- }
- assertEquals(IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT, valid);
- }
-
- //@Test
- //This test is very long, and doesn't cover the 4-byte combinations.
- // This is replaced by the test following which does cover some 4-byte combinations.
- public void testThreeBytes() {
- // Travis' OOM killer doesn't like this test
- if (System.getenv("TRAVIS") == null) {
- int count = 0;
- int valid = 0;
- for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
- for (int j = Byte.MIN_VALUE; j <= Byte.MAX_VALUE; j++) {
- for (int k = Byte.MIN_VALUE; k <= Byte.MAX_VALUE; k++) {
- byte[] bytes = new byte[]{(byte) i, (byte) j, (byte) k};
- ByteString bs = ByteString.copyFrom(bytes);
- if (!bs.isValidUtf8()) {
- checkInvalidBytes(bytes);
- } else {
- valid++;
- }
- count++;
- if ((count % 1000000L) == 0) {
- println("Processed " + (count / 1000000L) + " million characters");
- }
- }
- }
- }
- assertEquals(IsValidUtf8TestUtil.EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT, valid);
- }
- }
-
- /* These code points can be used by the following test to customize different regions of the
- * Code Point space. This randomized test can replace the exhaustive
- * combinatorially explosive previous test, which doesn't cover the 4 byte combinations.
- */
- static final int min1ByteCP = 0; //ASCII
- static final int min2ByteCP = 0X000080;
- static final int min3ByteCP = 0X000800;
- static final int min4ByteCP = Character.MIN_SUPPLEMENTARY_CODE_POINT; //0X010000;
- static final int minPlane2CP = 0X020000;
- static final int maxCodePoint = Character.MAX_CODE_POINT; //0X10FFFF
- static final int minSurr = Character.MIN_SURROGATE; //0X00D800;
- static final int maxSurr = Character.MAX_SURROGATE; //0X00E000;
-
- @Test
- //randomly selects CP from a range that include 1, 2, 3 and 4 byte encodings.
- // with 50% coming from plane 0 and 50% coming from plane 1.
- public void checkRandomValidCodePoints() {
- RandomCodePoints rcp = new RandomCodePoints(true);
- int numCP = 1000;
- int[] cpArr = new int[numCP];
- rcp.fillCodePointArray(cpArr, 0, minPlane2CP);
- String rcpStr = new String(cpArr, 0, numCP);
- //println(rcpStr);
- WritableMemory wmem = WritableMemory.allocate(4 * numCP);
- int utf8Bytes = (int) wmem.putCharsToUtf8(0, rcpStr);
-
- StringBuilder sb = new StringBuilder();
- try {
- wmem.getCharsFromUtf8(0L, utf8Bytes, (Appendable) sb);
- } catch (IOException | Utf8CodingException e) {
- throw new RuntimeException(e);
- }
- checkStrings(sb.toString(), rcpStr);
-
- CharBuffer cb = CharBuffer.allocate(rcpStr.length());
- try {
- wmem.getCharsFromUtf8(0L, utf8Bytes, cb);
- } catch (IOException | Utf8CodingException e) {
- throw new RuntimeException(e);
- }
- String cbStr = sb.toString();
- assertEquals(cbStr.length(), rcpStr.length());
- checkStrings(cbStr, rcpStr);
- }
-
- @Test
- public void checkRandomValidCodePoints2() {
- //checks the non-deterministic constructor
- @SuppressWarnings("unused")
- RandomCodePoints rcp = new RandomCodePoints(false);
- }
-
-
- /**
- * Tests that round tripping of a sample of four byte permutations work.
- */
- @Test
- public void testInvalid_4BytesSamples() {
- // Bad trailing bytes
- checkInvalidInts(0xF0, 0xA4, 0xAD, 0x7F);
- checkInvalidInts(0xF0, 0xA4, 0xAD, 0xC0);
-
- // Special cases for byte2
- checkInvalidInts(0xF0, 0x8F, 0xAD, 0xA2);
- checkInvalidInts(0xF4, 0x90, 0xAD, 0xA2);
- }
-
- @Test
- public void testRealStrings() throws IOException {
- // English
- assertRoundTrips("The quick brown fox jumps over the lazy dog");
- // German
- assertRoundTrips("Quizdeltagerne spiste jordb\u00e6r med fl\u00f8de, mens cirkusklovnen");
- // Japanese
- assertRoundTrips(
- "\u3044\u308d\u306f\u306b\u307b\u3078\u3068\u3061\u308a\u306c\u308b\u3092");
- // Hebrew
- assertRoundTrips(
- "\u05d3\u05d2 \u05e1\u05e7\u05e8\u05df \u05e9\u05d8 \u05d1\u05d9\u05dd "
- + "\u05de\u05d0\u05d5\u05db\u05d6\u05d1 \u05d5\u05dc\u05e4\u05ea\u05e2"
- + " \u05de\u05e6\u05d0 \u05dc\u05d5 \u05d7\u05d1\u05e8\u05d4 "
- + "\u05d0\u05d9\u05da \u05d4\u05e7\u05dc\u05d9\u05d8\u05d4");
- // Thai
- assertRoundTrips(
- " \u0e08\u0e07\u0e1d\u0e48\u0e32\u0e1f\u0e31\u0e19\u0e1e\u0e31\u0e12"
- + "\u0e19\u0e32\u0e27\u0e34\u0e0a\u0e32\u0e01\u0e32\u0e23");
- // Chinese
- assertRoundTrips(
- "\u8fd4\u56de\u94fe\u4e2d\u7684\u4e0b\u4e00\u4e2a\u4ee3\u7406\u9879\u9009\u62e9\u5668");
- // Chinese with 4-byte chars
- assertRoundTrips("\uD841\uDF0E\uD841\uDF31\uD841\uDF79\uD843\uDC53\uD843\uDC78"
- + "\uD843\uDC96\uD843\uDCCF\uD843\uDCD5\uD843\uDD15\uD843\uDD7C\uD843\uDD7F"
- + "\uD843\uDE0E\uD843\uDE0F\uD843\uDE77\uD843\uDE9D\uD843\uDEA2");
- // Mixed
- assertRoundTrips(
- "The quick brown \u3044\u308d\u306f\u306b\u307b\u3078\u8fd4\u56de\u94fe"
- + "\u4e2d\u7684\u4e0b\u4e00");
- }
-
- @Test
- public void checkNonEmptyDestinationForDecode() {
- StringBuilder sb = new StringBuilder();
- sb.append("abc"); //current contents of destination
- int startChars = sb.toString().toCharArray().length;
- String refStr = "Quizdeltagerne spiste jordb\u00e6r med fl\u00f8de, mens cirkusklovnen";
- byte[] refByteArr = refStr.getBytes(UTF_8);
- int addBytes = refByteArr.length;
- WritableMemory refMem = WritableMemory.writableWrap(refByteArr);
- int decodedChars = refMem.getCharsFromUtf8(0, addBytes, sb);
- String finalStr = sb.toString();
- int finalChars = finalStr.toCharArray().length;
- assertEquals(decodedChars + startChars, finalChars);
- println("Decoded chars: " + decodedChars);
- println("Final chars: " + finalChars);
- println(sb.toString());
- }
-
- @Test
- public void checkNonEmptyDestinationForEncode() {
- String refStr = "Quizdeltagerne spiste jordb\u00e6r med fl\u00f8de, mens cirkusklovnen";
- byte[] refByteArr = refStr.getBytes(UTF_8);
- int refBytes = refByteArr.length;
- int offset = 100;
- WritableMemory tgtMem = WritableMemory.allocate(refBytes + offset);
- long bytesEncoded = tgtMem.putCharsToUtf8(offset, refStr);
- assertEquals(bytesEncoded, refBytes);
- }
-
- @Test
- public void testOverlong() {
- checkInvalidInts(0xc0, 0xaf);
- checkInvalidInts(0xe0, 0x80, 0xaf);
- checkInvalidInts(0xf0, 0x80, 0x80, 0xaf);
-
- // Max overlong
- checkInvalidInts(0xc1, 0xbf);
- checkInvalidInts(0xe0, 0x9f, 0xbf);
- checkInvalidInts(0xf0 ,0x8f, 0xbf, 0xbf);
-
- // null overlong
- checkInvalidInts(0xc0, 0x80);
- checkInvalidInts(0xe0, 0x80, 0x80);
- checkInvalidInts(0xf0, 0x80, 0x80, 0x80);
- }
-
- @Test
- public void testIllegalCodepoints() {
- // Single surrogate
- checkInvalidInts(0xed, 0xa0, 0x80);
- checkInvalidInts(0xed, 0xad, 0xbf);
- checkInvalidInts(0xed, 0xae, 0x80);
- checkInvalidInts(0xed, 0xaf, 0xbf);
- checkInvalidInts(0xed, 0xb0, 0x80);
- checkInvalidInts(0xed, 0xbe, 0x80);
- checkInvalidInts(0xed, 0xbf, 0xbf);
-
- // Paired surrogates
- checkInvalidInts(0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80);
- checkInvalidInts(0xed, 0xa0, 0x80, 0xed, 0xbf, 0xbf);
- checkInvalidInts(0xed, 0xad, 0xbf, 0xed, 0xb0, 0x80);
- checkInvalidInts(0xed, 0xad, 0xbf, 0xed, 0xbf, 0xbf);
- checkInvalidInts(0xed, 0xae, 0x80, 0xed, 0xb0, 0x80);
- checkInvalidInts(0xed, 0xae, 0x80, 0xed, 0xbf, 0xbf);
- checkInvalidInts(0xed, 0xaf, 0xbf, 0xed, 0xb0, 0x80);
- checkInvalidInts(0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf);
- }
-
- @Test
- public void testBufferSlice() throws IOException {
- String str = "The quick brown fox jumps over the lazy dog";
- assertRoundTrips(str, 4, 10, 4);
- assertRoundTrips(str, 0, str.length(), 0);
- }
-
- @Test
- public void testInvalidBufferSlice() { //these are pure Memory bounds violations
- byte[] bytes = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
- checkInvalidSlice(bytes, bytes.length - 3, 4);
- checkInvalidSlice(bytes, bytes.length, 1);
- checkInvalidSlice(bytes, bytes.length + 1, 0);
- checkInvalidSlice(bytes, 0, bytes.length + 1);
- }
-
- private static void checkInvalidInts(int... bytesAsInt) { //invalid byte sequences
- byte[] bytes = new byte[bytesAsInt.length];
- for (int i = 0; i < bytesAsInt.length; i++) {
- bytes[i] = (byte) bytesAsInt[i];
- }
- checkInvalidBytes(bytes);
- }
-
- private static void checkInvalidBytes(byte[] bytes) {
- int bytesLen = bytes.length;
- try {
- Memory.wrap(bytes).getCharsFromUtf8(0, bytesLen, new StringBuilder());
- fail();
- } catch (Utf8CodingException e) {
- // Expected.
- }
- try {
- CharBuffer cb = CharBuffer.allocate(bytesLen);
- Memory.wrap(bytes).getCharsFromUtf8(0, bytesLen, cb);
- fail();
- } catch (Utf8CodingException | IOException e) {
- // Expected.
- }
- }
-
- private static void checkInvalidSlice(byte[] bytes, int index, int size) {
- try {
- Memory mem = Memory.wrap(bytes);
- mem.getCharsFromUtf8(index, size, new StringBuilder());
- fail();
- } catch (MemoryBoundsException e) { //Pure bounds violation
- // Expected.
- }
- }
-
- /**
- * Performs round-trip test using the given reference string
- * @param refStr the reference string
- * @throws IOException when IOException occurs
- */
- private static void assertRoundTrips(String refStr) throws IOException {
- assertRoundTrips(refStr, refStr.toCharArray().length, 0, -1);
- }
-
- /**
- * Performs round-trip test using the given reference string
- * @param refStr the reference string
- * @param refSubCharLen the number of characters expected to be decoded
- * @param offsetBytes starting utf8 byte offset
- * @param utf8LengthBytes length of utf8 bytes
- * @throws IOException when IOException occurs
- */
- private static void assertRoundTrips(String refStr, int refSubCharLen, int offsetBytes,
- int utf8LengthBytes) throws IOException {
- byte[] refByteArr = refStr.getBytes(UTF_8);
- if (utf8LengthBytes == -1) {
- utf8LengthBytes = refByteArr.length;
- }
- Memory refMem = Memory.wrap(refByteArr);
-
- byte[] refByteArr2 = new byte[refByteArr.length + 1];
- System.arraycopy(refByteArr, 0, refByteArr2, 1, refByteArr.length);
- Memory refReg = Memory.wrap(refByteArr2).region(1, refByteArr.length);
-
- WritableMemory dstMem = WritableMemory.allocate(refByteArr.length);
- WritableMemory dstMem2 =
- WritableMemory.allocate(refByteArr.length + 1).writableRegion(1, refByteArr.length);
-
- // Test with Memory objects, where base offset != 0
- assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refMem, dstMem);
- assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refMem, dstMem2);
- assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refReg, dstMem);
- assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refReg, dstMem2);
- }
-
- private static void assertRoundTrips(String refStr, int refSubCharLen, int offsetBytes,
- int utf8LengthBytes, byte[] refByteArr, Memory refMem, WritableMemory dstMem)
- throws IOException {
- StringBuilder sb = new StringBuilder();
-
- int charPos = refMem.getCharsFromUtf8(offsetBytes, utf8LengthBytes, sb);
- checkStrings(sb.toString(), new String(refByteArr, offsetBytes, utf8LengthBytes, UTF_8));
- assertEquals(charPos, refSubCharLen);
-
- CharBuffer cb = CharBuffer.allocate(refByteArr.length + 1);
- cb.position(1);
- // Make CharBuffer 1-based, to check correct offset handling
- cb = cb.slice();
- refMem.getCharsFromUtf8(offsetBytes, utf8LengthBytes, cb);
- cb.flip();
- checkStrings(cb.toString(), new String(refByteArr, offsetBytes, utf8LengthBytes, UTF_8));
-
- long encodedUtf8Bytes = dstMem.putCharsToUtf8(0, refStr); //encodes entire refStr
- assertEquals(encodedUtf8Bytes, refByteArr.length); //compares bytes length
- //compare the actual bytes encoded
- assertEquals(0, dstMem.compareTo(0, refByteArr.length, refMem, 0, refByteArr.length));
-
- // Test write overflow
- WritableMemory writeMem2 = WritableMemory.allocate(refByteArr.length - 1);
- try {
- writeMem2.putCharsToUtf8(0, refStr);
- fail();
- } catch (Utf8CodingException e) {
- // Expected.
- }
- }
-
- private static boolean isSurrogateCodePoint(final int cp) {
- return (cp >= Character.MIN_SURROGATE) && (cp <= Character.MAX_SURROGATE);
- }
-
- private static void checkStrings(String actual, String expected) {
- if (!expected.equals(actual)) {
- fail("Failure: Expected (" + codepoints(expected) + ") Actual (" + codepoints(actual) + ")");
- }
- }
-
- private static List<String> codepoints(String str) {
- List<String> codepoints = new ArrayList<>();
- for (int i = 0; i < str.length(); i++) {
- codepoints.add(Long.toHexString(str.charAt(i)));
- }
- return codepoints;
- }
-
- @Test
- public void printlnTest() {
- println("PRINTING: " + this.getClass().getName());
- }
-
- /**
- * @param s value to print
- */
- static void println(String s) {
- //System.out.println(s); //disable here
- }
-}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
index 37519a4..a788f39 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
@@ -38,7 +38,7 @@ public class WritableDirectCopyTest {
public void checkCopyWithinNativeSmall() {
int memCapacity = 64;
int half = memCapacity / 2;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.clear();
for (int i = 0; i < half; i++) { //fill first half
@@ -59,7 +59,7 @@ public class WritableDirectCopyTest {
int memCapLongs = memCapacity / 8;
int halfBytes = memCapacity / 2;
int halfLongs = memCapLongs / 2;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.clear();
for (int i = 0; i < halfLongs; i++) {
@@ -77,7 +77,7 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyWithinNativeOverlap() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.clear();
//println(mem.toHexString("Clear 64", 0, memCapacity));
@@ -92,7 +92,7 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyWithinNativeSrcBound() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.copyTo(32, mem, 32, 33); //hit source bound check
fail("Did Not Catch Assertion Error: source bound");
} catch (MemoryBoundsException e) {
@@ -103,7 +103,7 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyWithinNativeDstBound() {
int memCapacity = 64;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity, null)) {
mem.copyTo(0, mem, 32, 33); //hit dst bound check
fail("Did Not Catch Assertion Error: dst bound");
} catch (MemoryBoundsException e) {
@@ -115,8 +115,8 @@ public class WritableDirectCopyTest {
public void checkCopyCrossNativeSmall() {
int memCapacity = 64;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity);
- WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null);
+ WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < memCapacity; i++) {
mem1.putByte(i, (byte) i);
@@ -135,8 +135,8 @@ public class WritableDirectCopyTest {
int memCapacity = (2 << 20) + 64;
int memCapLongs = memCapacity / 8;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity);
- WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null);
+ WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < memCapLongs; i++) {
mem1.putLong(i * 8, i);
}
@@ -153,7 +153,7 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyCrossNativeAndByteArray() {
int memCapacity = 64;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
@@ -171,7 +171,7 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyCrossRegionsSameNative() {
int memCapacity = 128;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
@@ -195,7 +195,7 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyCrossNativeArrayAndHierarchicalRegions() {
int memCapacity = 64;
- try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, null)) {
for (int i = 0; i < mem1.getCapacity(); i++) { //fill with numbers
mem1.putByte(i, (byte) i);
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
index 91f1089..6ed5bdf 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
@@ -36,29 +36,29 @@ public class WritableMemoryTest {
@Test
public void wrapBigEndian() {
- ByteBuffer bb = ByteBuffer.allocate(64); //big endian
+ ByteBuffer bb = ByteBuffer.allocate(64); //default big endian
WritableMemory wmem = WritableMemory.writableWrap(bb);
- assertEquals(wmem.getByteOrder(), ByteOrder.BIG_ENDIAN);
- wmem = WritableMemory.writableWrap(bb, ByteOrder.nativeOrder());
- assertEquals(wmem.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
+ assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+ wmem = WritableMemory.writableWrap(bb, ByteOrder.LITTLE_ENDIAN, null); //assume LE
+ assertEquals(wmem.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
}
@Test
public void wrapBigEndianAsLittle() {
- ByteBuffer bb = ByteBuffer.allocate(64);
- bb.putChar(0, (char)1); //as NNO
+ ByteBuffer bb = ByteBuffer.allocate(64); //default big endian
+ bb.putChar(0, (char)1); //written as BE
WritableMemory wmem = WritableMemory.writableWrap(bb, ByteOrder.LITTLE_ENDIAN, null);
- assertEquals(wmem.getChar(0), 256);
+ assertEquals(wmem.getChar(0), 256); //read as LE
}
@Test
public void allocateWithByteOrder() {
WritableMemory wmem = WritableMemory.allocate(64, ByteOrder.BIG_ENDIAN);
- assertEquals(wmem.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
wmem = WritableMemory.allocate(64, ByteOrder.LITTLE_ENDIAN);
- assertEquals(wmem.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
+ assertEquals(wmem.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
wmem = WritableMemory.writableWrap(new byte[64], 32, 32, ByteOrder.BIG_ENDIAN);
- assertEquals(wmem.getByteOrder(), ByteOrder.BIG_ENDIAN);
+ assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@Test
@@ -163,11 +163,11 @@ public class WritableMemoryTest {
@Test
public void checkWrapWithBO() {
WritableMemory wmem = WritableMemory.writableWrap(new byte[0], ByteOrder.BIG_ENDIAN);
- boolean nativeBO = wmem.getByteOrder() == ByteOrder.nativeOrder();
+ boolean nativeBO = wmem.getTypeByteOrder() == ByteOrder.nativeOrder();
assertFalse(nativeBO);
println("" + nativeBO);
wmem = WritableMemory.writableWrap(new byte[8], ByteOrder.BIG_ENDIAN);
- nativeBO = wmem.getByteOrder() == ByteOrder.nativeOrder();
+ nativeBO = wmem.getTypeByteOrder() == ByteOrder.nativeOrder();
assertFalse(nativeBO);
println("" + nativeBO);
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/XxHash64Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/XxHash64Test.java
index 9c51eb6..973b1e1 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/XxHash64Test.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/XxHash64Test.java
@@ -19,7 +19,6 @@
package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.XxHash.hashBooleanArr;
import static org.apache.datasketches.memory.XxHash.hashByteArr;
import static org.apache.datasketches.memory.XxHash.hashCharArr;
import static org.apache.datasketches.memory.XxHash.hashDoubleArr;
@@ -173,11 +172,6 @@ public class XxHash64Test {
wmem.getDoubleArray(0, darr, 0, 2);
hash1 = hashDoubleArr(darr, 1, 1, 0);
assertEquals(hash1, hash0);
-
- boolean[] blarr = new boolean[16];
- wmem.getBooleanArray(0, blarr, 0, 16); //any byte != 0 is true
- hash1 = hashBooleanArr(blarr, 8, 8, 0);
- assertEquals(hash1, hash0);
}
@Test
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
index fa500db..6e05b52 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
@@ -43,7 +43,7 @@ public class ZeroCapacityTest {
Memory.wrap(ByteBuffer.allocate(0));
Memory mem3 = Memory.wrap(ByteBuffer.allocateDirect(0));
mem3.region(0, 0);
- WritableMemory mem = WritableMemory.allocateDirect(0);
+ WritableMemory mem = WritableMemory.allocateDirect(0, null);
mem.close();
}
diff --git a/tools/MemoryCheckstyle.xml b/tools/MemoryCheckstyle.xml
index 95c0988..e5f0b85 100644
--- a/tools/MemoryCheckstyle.xml
+++ b/tools/MemoryCheckstyle.xml
@@ -60,7 +60,7 @@ under the License.
<!-- Size Violations -->
<module name="LineLength">
<property name="severity" value="warning"/>
- <property name="max" value="120"/>
+ <property name="max" value="140"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
<!-- <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/> -->
</module>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org