You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/01/18 01:37:41 UTC

[GitHub] [iceberg] rdsr commented on a change in pull request #2102: [Misc] Remove non-test uses of commons-lang3

rdsr commented on a change in pull request #2102:
URL: https://github.com/apache/iceberg/pull/2102#discussion_r559274994



##########
File path: core/src/main/java/org/apache/iceberg/util/SerdeUtil.java
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.iceberg.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.io.UncheckedIOException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public class SerdeUtil {
+
+  private SerdeUtil() {
+  }
+
+  /**
+   * <p>The code from `org.apache.commons:commons-lang3`
+   *
+   * <p>Serializes an {@code Object} to a byte array for
+   * storage/serialization.</p>
+   *
+   * @param obj the object to serialize to bytes
+   * @return a byte[] with the converted Serializable
+   * @throws UncheckedIOException (runtime) if the serialization fails
+   */
+  public static byte[] serialize(final Serializable obj) {
+    final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
+    serialize(obj, baos);
+    return baos.toByteArray();
+  }
+
+  /**
+   * <p>The code from `org.apache.commons:commons-lang3`, and is modified to not depends on `commons-lang3` classes.
+   *
+   * <p>Serializes an {@code Object} to the specified stream.</p>
+   *
+   * <p>The stream will be closed once the object is written.
+   * This avoids the need for a finally clause, and maybe also exception
+   * handling, in the application code.</p>
+   *
+   * <p>The stream passed in is not buffered internally within this method.
+   * This is the responsibility of your application if desired.</p>
+   *
+   * @param obj          the object to serialize to bytes, may be null
+   * @param outputStream the stream to write to, must not be null
+   * @throws IllegalArgumentException if {@code outputStream} is {@code null}
+   * @throws UncheckedIOException     (runtime) if the serialization fails
+   */
+  public static void serialize(final Serializable obj, final OutputStream outputStream) {

Review comment:
       The `iceberg-mr` module also defines these methods as part of `org.apache.iceberg.mr.SerializationUtil` class. Though changing that may require some effort, maybe we can file a ticket to investigate and remove the duplication.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org