aboutsummaryrefslogtreecommitdiff
path: root/unsafe
diff options
context:
space:
mode:
Diffstat (limited to 'unsafe')
-rw-r--r--unsafe/src/main/java/org/apache/spark/unsafe/types/ByteArray.java38
-rw-r--r--unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java15
2 files changed, 53 insertions, 0 deletions
diff --git a/unsafe/src/main/java/org/apache/spark/unsafe/types/ByteArray.java b/unsafe/src/main/java/org/apache/spark/unsafe/types/ByteArray.java
new file mode 100644
index 0000000000..69b0e206ce
--- /dev/null
+++ b/unsafe/src/main/java/org/apache/spark/unsafe/types/ByteArray.java
@@ -0,0 +1,38 @@
+/*
+ * 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.spark.unsafe.types;
+
+import org.apache.spark.unsafe.PlatformDependent;
+
+public class ByteArray {
+
+ /**
+ * Writes the content of a byte array into a memory address, identified by an object and an
+ * offset. The target memory address must already been allocated, and have enough space to
+ * hold all the bytes in this string.
+ */
+ public static void writeToMemory(byte[] src, Object target, long targetOffset) {
+ PlatformDependent.copyMemory(
+ src,
+ PlatformDependent.BYTE_ARRAY_OFFSET,
+ target,
+ targetOffset,
+ src.length
+ );
+ }
+}
diff --git a/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java b/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
index 6d8dcb1cbf..85381cf0ef 100644
--- a/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
+++ b/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
@@ -96,6 +96,21 @@ public final class UTF8String implements Comparable<UTF8String>, Serializable {
}
/**
+ * Writes the content of this string into a memory address, identified by an object and an offset.
+ * The target memory address must already been allocated, and have enough space to hold all the
+ * bytes in this string.
+ */
+ public void writeToMemory(Object target, long targetOffset) {
+ PlatformDependent.copyMemory(
+ base,
+ offset,
+ target,
+ targetOffset,
+ numBytes
+ );
+ }
+
+ /**
* Returns the number of bytes for a code point with the first byte as `b`
* @param b The first byte of a code point
*/