Skip to content

Commit

Permalink
HBASE-20884 Replace Base64 with j.u.Base64
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Purtell <apurtell@apache.org>
Signed-off-by: tedyu <yuzhihong@gmail.com>
  • Loading branch information
madrob committed Jul 13, 2018
1 parent ce82fd0 commit dbcc80c
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 1,825 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -41,7 +42,6 @@
import org.apache.hadoop.hbase.security.visibility.Authorizations;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Assert;
import org.junit.ClassRule;
Expand Down Expand Up @@ -214,9 +214,9 @@ public void testDynamicFilter() throws Exception {
assertFalse("Should be deleted: " + jarFile.getPath(), jarFile.exists());

ClientProtos.Get getProto1 =
ClientProtos.Get.parseFrom(Base64.decode(PB_GET));
ClientProtos.Get.parseFrom(Base64.getDecoder().decode(PB_GET));
ClientProtos.Get getProto2 =
ClientProtos.Get.parseFrom(Base64.decode(PB_GET_WITH_FILTER_LIST));
ClientProtos.Get.parseFrom(Base64.getDecoder().decode(PB_GET_WITH_FILTER_LIST));
try {
ProtobufUtil.toGet(getProto1);
fail("Should not be able to load the filter class");
Expand All @@ -233,7 +233,7 @@ public void testDynamicFilter() throws Exception {
instanceof DeserializationException);
}
FileOutputStream fos = new FileOutputStream(jarFile);
fos.write(Base64.decode(MOCK_FILTER_JAR));
fos.write(Base64.getDecoder().decode(MOCK_FILTER_JAR));
fos.close();

Get get1 = ProtobufUtil.toGet(getProto1);
Expand Down
1,684 changes: 0 additions & 1,684 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/util/Base64.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.charset.CharsetDecoder;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -39,7 +40,7 @@
import org.apache.hadoop.hbase.thrift.generated.Hbase;
import org.apache.hadoop.hbase.thrift.generated.TCell;
import org.apache.hadoop.hbase.thrift.generated.TRowResult;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient;
Expand Down Expand Up @@ -218,7 +219,7 @@ private String generateTicket() throws GSSException {
final byte[] outToken = context.initSecContext(new byte[0], 0, 0);
StringBuffer outputBuffer = new StringBuffer();
outputBuffer.append("Negotiate ");
outputBuffer.append(Base64.encodeBytes(outToken).replace("\n", ""));
outputBuffer.append(Bytes.toString(Base64.getEncoder().encode(outToken)));
System.out.print("Ticket is: " + outputBuffer);
return outputBuffer.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -47,7 +48,6 @@
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.io.Text;
Expand Down Expand Up @@ -471,7 +471,7 @@ protected static Job createSubmittableJob(Configuration conf, String[] args)
String actualSeparator = conf.get(SEPARATOR_CONF_KEY);
if (actualSeparator != null) {
conf.set(SEPARATOR_CONF_KEY,
Base64.encodeBytes(actualSeparator.getBytes()));
Bytes.toString(Base64.getEncoder().encode(actualSeparator.getBytes())));
}

// See if a non-default Mapper was set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
*/
package org.apache.hadoop.hbase.mapreduce;

import java.util.Base64;

import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.mapreduce.Partitioner;

Expand Down Expand Up @@ -63,11 +64,11 @@ public class SimpleTotalOrderPartitioner<VALUE> extends Partitioner<ImmutableByt
private int lastReduces = -1;

public static void setStartKey(Configuration conf, byte[] startKey) {
conf.set(START_BASE64, Base64.encodeBytes(startKey));
conf.set(START_BASE64, Bytes.toString(Base64.getEncoder().encode(startKey)));
}

public static void setEndKey(Configuration conf, byte[] endKey) {
conf.set(END_BASE64, Base64.encodeBytes(endKey));
conf.set(END_BASE64, Bytes.toString(Base64.getEncoder().encode(endKey)));
}

@SuppressWarnings("deprecation")
Expand All @@ -84,7 +85,7 @@ private static byte[] getKeyFromConf(Configuration conf,
String base64Key, String deprecatedKey) {
String encoded = conf.get(base64Key);
if (encoded != null) {
return Base64.decode(encoded);
return Base64.getDecoder().decode(encoded);
}
String oldStyleVal = conf.get(deprecatedKey);
if (oldStyleVal == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -53,7 +54,6 @@
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.security.token.TokenUtil;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.RegionSplitter;
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
Expand Down Expand Up @@ -597,7 +597,7 @@ public static void initCredentialsForCluster(Job job, Configuration conf)
*/
public static String convertScanToString(Scan scan) throws IOException {
ClientProtos.Scan proto = ProtobufUtil.toScan(scan);
return Base64.encodeBytes(proto.toByteArray());
return Bytes.toString(Base64.getEncoder().encode(proto.toByteArray()));
}

/**
Expand All @@ -608,7 +608,7 @@ public static String convertScanToString(Scan scan) throws IOException {
* @throws IOException When reading the scan instance fails.
*/
public static Scan convertStringToScan(String base64) throws IOException {
byte [] decoded = Base64.decode(base64);
byte [] decoded = Base64.getDecoder().decode(base64);
return ProtobufUtil.toScan(ClientProtos.Scan.parseFrom(decoded));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Expand All @@ -35,7 +36,6 @@
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.security.visibility.InvalidLabelException;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Counter;
Expand Down Expand Up @@ -121,7 +121,7 @@ protected void doSetup(Context context, Configuration conf) {
if (separator == null) {
separator = ImportTsv.DEFAULT_SEPARATOR;
} else {
separator = new String(Base64.decode(separator));
separator = Bytes.toString(Base64.getDecoder().decode(separator));
}

// Should never get 0 as we are setting this to a valid value in job configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
Expand All @@ -33,7 +34,6 @@
import org.apache.hadoop.hbase.mapreduce.ImportTsv.TsvParser.BadTsvLineException;
import org.apache.hadoop.hbase.security.visibility.CellVisibility;
import org.apache.hadoop.hbase.security.visibility.InvalidLabelException;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
Expand Down Expand Up @@ -127,7 +127,7 @@ protected void doSetup(Context context) {
if (separator == null) {
separator = ImportTsv.DEFAULT_SEPARATOR;
} else {
separator = new String(Base64.decode(separator));
separator = new String(Base64.getDecoder().decode(separator));
}
// Should never get 0 as we are setting this to a valid value in job
// configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
*/
package org.apache.hadoop.hbase.mapreduce;

import java.io.IOException;
import java.util.Base64;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Counter;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;

import java.io.IOException;

/**
* Write table content out to map output files.
*/
Expand Down Expand Up @@ -61,7 +61,7 @@ public void incrementBadLineCount(int count) {

/**
* Handles initializing this class with objects specific to it (i.e., the parser).
* Common initialization that might be leveraged by a subsclass is done in
* Common initialization that might be leveraged by a subclass is done in
* <code>doSetup</code>. Hence a subclass may choose to override this method
* and call <code>doSetup</code> as well before handling it's own custom params.
*
Expand Down Expand Up @@ -92,7 +92,7 @@ protected void doSetup(Context context) {
if (separator == null) {
separator = ImportTsv.DEFAULT_SEPARATOR;
} else {
separator = new String(Base64.decode(separator));
separator = new String(Base64.getDecoder().decode(separator));
}

skipBadLines = context.getConfiguration().getBoolean(ImportTsv.SKIP_LINES_CONF_KEY, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.hadoop.hbase.rest;

import java.io.IOException;
import java.util.Base64;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
Expand All @@ -40,7 +41,6 @@
import org.apache.hadoop.hbase.rest.model.CellModel;
import org.apache.hadoop.hbase.rest.model.CellSetModel;
import org.apache.hadoop.hbase.rest.model.RowModel;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.hbase.util.Bytes;

@InterfaceAudience.Private
Expand Down Expand Up @@ -171,10 +171,10 @@ public Response getBinary(final @Context UriInfo uriInfo) {
}
ResponseBuilder response = Response.ok(CellUtil.cloneValue(value));
response.cacheControl(cacheControl);
response.header("X-Row", Base64.encodeBytes(CellUtil.cloneRow(value)));
response.header("X-Column",
Base64.encodeBytes(
CellUtil.makeColumn(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value))));
response.header("X-Row", Bytes.toString(Base64.getEncoder().encode(
CellUtil.cloneRow(value))));
response.header("X-Column", Bytes.toString(Base64.getEncoder().encode(
CellUtil.makeColumn(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value)))));
response.header("X-Timestamp", value.getTimestamp());
servlet.getMetrics().incrementSucessfulGetRequests(1);
return response.build();
Expand Down
Loading

0 comments on commit dbcc80c

Please sign in to comment.