DomGarguilo commented on code in PR #3285: URL: https://github.com/apache/accumulo/pull/3285#discussion_r1160846550
########## core/src/test/java/org/apache/accumulo/core/util/ByteArrayToBase64TypeAdapterTest.java: ########## @@ -0,0 +1,61 @@ +/* + * 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 + * + * https://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.core.util; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.apache.hadoop.io.Text; +import org.junit.jupiter.api.Test; + +import com.google.gson.Gson; + +public class ByteArrayToBase64TypeAdapterTest { + + private static final Gson gson = ByteArrayToBase64TypeAdapter.createBase64Gson(); + + @Test + public void testSerializeText() throws IOException { + final Text original = new Text("This is a test"); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + original.write(new DataOutputStream(baos)); + + final String encoded = gson.toJson(baos.toByteArray()); + final Text decoded = new Text(); + decoded.readFields( + new DataInputStream(new ByteArrayInputStream(gson.fromJson(encoded, byte[].class)))); Review Comment: ```suggestion String encoded; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos)) { original.write(dos); encoded = gson.toJson(baos.toByteArray()); } final Text decoded = new Text(); try (ByteArrayInputStream bais = new ByteArrayInputStream(gson.fromJson(encoded, byte[].class)); DataInputStream dis = new DataInputStream(bais)) { decoded.readFields(dis); } ``` Minor suggestion to add resources to try-with-resources blocks. -- 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]
