DomGarguilo commented on a change in pull request #2224:
URL: https://github.com/apache/accumulo/pull/2224#discussion_r701918682



##########
File path: 
server/base/src/main/java/org/apache/accumulo/server/conf/codec/VersionedPropCodec.java
##########
@@ -0,0 +1,284 @@
+/*
+ * 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.accumulo.server.conf.codec;
+
+import static 
org.apache.accumulo.server.conf.codec.VersionedProperties.tsFormatter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Abstract class to provide encoding / decoding of versioned properties. This 
class handles the
+ * serialization of the metadata and subclasses are required to implement
+ * {@link #encodePayload(OutputStream, VersionedProperties, EncodingOptions)} 
and
+ * {@link #decodePayload(InputStream, EncodingOptions)} to handle any specific 
implementation
+ * metadata (optional) and the property map according to the encoding scheme 
of the subclass.
+ * <p>
+ * The basic encoding format:
+ * <ul>
+ * <li>encoding metadata - specifies codec to be used</li>
+ * <li>version metadata - specifies property versioning information</li>
+ * <li>codec specific metadata (optional)</li>
+ * <li>the property map</li>
+ * </ul>
+ *
+ */
+public abstract class VersionedPropCodec {
+
+  private final EncodingOptions encodingOpts;
+
+  public VersionedPropCodec(final EncodingOptions encodingOpts) {
+    this.encodingOpts = encodingOpts;
+  }
+
+  /**
+   * The general encoding options that apply to all encodings.
+   *
+   * @return the general options.
+   */
+  public EncodingOptions getEncodingOpts() {
+    return encodingOpts;
+  }
+
+  /**
+   * Serialize the versioned properties. The version information on the 
properties is updated if the
+   * data is successfully serialized.
+   *
+   * @param vProps
+   *          the versioned properties.
+   * @return a byte array with the serialized properties.
+   */
+  public byte[] toBytes(final VersionedProperties vProps) throws IOException {
+
+    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(bos)) {
+
+      // write encoding metadata
+      encodingOpts.encode(dos);
+
+      // write version metadata
+      DataVersionInfo vMetadata =
+          new DataVersionInfo(vProps.getNextVersion(), vProps.getTimestamp());
+      vMetadata.write(dos);
+
+      // delegate property encoding to sub-class
+      encodePayload(bos, vProps, encodingOpts);
+
+      return bos.toByteArray();
+    }
+  }
+
+  /**
+   * Encode the properties and optionally any specific encoding metadata that 
is necessary to decode
+   * the payload with the scheme chosen.
+   *
+   * @param out
+   *          an output stream
+   * @param vProps
+   *          the versioned properties
+   * @param encodingOpts
+   *          the general encoding options.
+   * @throws IOException
+   *           if an error occurs writing to the underlying output stream.
+   */
+  abstract void encodePayload(final OutputStream out, final 
VersionedProperties vProps,
+      final EncodingOptions encodingOpts) throws IOException;
+
+  public VersionedProperties fromBytes(final byte[] bytes) throws IOException {
+
+    try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+        DataInputStream dis = new DataInputStream(bis)) {
+
+      EncodingOptions encodingOpts = new EncodingOptions(dis);
+
+      if (!checkCanDecodeVersion(encodingOpts)) {
+        throw new IllegalArgumentException(
+            "Invalid data version - cannot process the version read: {}");

Review comment:
       Looks to be missing an argument. Might need to do something like the 
following instead however.
   ```suggestion
           throw new IllegalArgumentException(
               "Invalid data version - cannot process the version read: " + 
encodingOpts);
   ```

##########
File path: 
server/base/src/main/java/org/apache/accumulo/server/conf/codec/VersionedPropCodec.java
##########
@@ -0,0 +1,284 @@
+/*
+ * 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.accumulo.server.conf.codec;
+
+import static 
org.apache.accumulo.server.conf.codec.VersionedProperties.tsFormatter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Abstract class to provide encoding / decoding of versioned properties. This 
class handles the
+ * serialization of the metadata and subclasses are required to implement
+ * {@link #encodePayload(OutputStream, VersionedProperties, EncodingOptions)} 
and
+ * {@link #decodePayload(InputStream, EncodingOptions)} to handle any specific 
implementation
+ * metadata (optional) and the property map according to the encoding scheme 
of the subclass.
+ * <p>
+ * The basic encoding format:
+ * <ul>
+ * <li>encoding metadata - specifies codec to be used</li>
+ * <li>version metadata - specifies property versioning information</li>
+ * <li>codec specific metadata (optional)</li>
+ * <li>the property map</li>
+ * </ul>
+ *
+ */
+public abstract class VersionedPropCodec {
+
+  private final EncodingOptions encodingOpts;
+
+  public VersionedPropCodec(final EncodingOptions encodingOpts) {
+    this.encodingOpts = encodingOpts;
+  }
+
+  /**
+   * The general encoding options that apply to all encodings.
+   *
+   * @return the general options.
+   */
+  public EncodingOptions getEncodingOpts() {
+    return encodingOpts;
+  }
+
+  /**
+   * Serialize the versioned properties. The version information on the 
properties is updated if the
+   * data is successfully serialized.
+   *
+   * @param vProps
+   *          the versioned properties.
+   * @return a byte array with the serialized properties.
+   */
+  public byte[] toBytes(final VersionedProperties vProps) throws IOException {
+
+    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(bos)) {
+
+      // write encoding metadata
+      encodingOpts.encode(dos);
+
+      // write version metadata
+      DataVersionInfo vMetadata =
+          new DataVersionInfo(vProps.getNextVersion(), vProps.getTimestamp());
+      vMetadata.write(dos);
+
+      // delegate property encoding to sub-class
+      encodePayload(bos, vProps, encodingOpts);
+
+      return bos.toByteArray();
+    }
+  }
+
+  /**
+   * Encode the properties and optionally any specific encoding metadata that 
is necessary to decode
+   * the payload with the scheme chosen.
+   *
+   * @param out
+   *          an output stream
+   * @param vProps
+   *          the versioned properties
+   * @param encodingOpts
+   *          the general encoding options.
+   * @throws IOException
+   *           if an error occurs writing to the underlying output stream.
+   */
+  abstract void encodePayload(final OutputStream out, final 
VersionedProperties vProps,
+      final EncodingOptions encodingOpts) throws IOException;
+
+  public VersionedProperties fromBytes(final byte[] bytes) throws IOException {
+
+    try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+        DataInputStream dis = new DataInputStream(bis)) {
+
+      EncodingOptions encodingOpts = new EncodingOptions(dis);
+
+      if (!checkCanDecodeVersion(encodingOpts)) {
+        throw new IllegalArgumentException(
+            "Invalid data version - cannot process the version read: {}");

Review comment:
       Looks to be missing an argument. Might need to do something like the 
following instead
   ```suggestion
           throw new IllegalArgumentException(
               "Invalid data version - cannot process the version read: " + 
encodingOpts);
   ```




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to