ACCUMULO-4304 Replace Guava use w/built-ins Replace functional guava stuff, some predicates, optional, and base-64 classes with Java 8 built-in stuff.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/84f70731 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/84f70731 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/84f70731 Branch: refs/heads/master Commit: 84f7073131c08754877ce4c3b470ed54a4a9aa2a Parents: 04c2984 Author: Christopher Tubbs <ctubb...@apache.org> Authored: Thu May 5 20:05:49 2016 -0400 Committer: Christopher Tubbs <ctubb...@apache.org> Committed: Thu May 5 23:59:03 2016 -0400 ---------------------------------------------------------------------- .../apache/accumulo/core/cli/ClientOpts.java | 6 +- .../core/client/MutationsRejectedException.java | 8 +-- .../core/client/impl/ClientContext.java | 9 ++- .../accumulo/core/client/impl/Credentials.java | 14 ++-- .../accumulo/core/client/impl/Namespaces.java | 6 +- .../core/client/mapreduce/RangeInputSplit.java | 6 +- .../mapreduce/lib/impl/ConfiguratorBase.java | 8 +-- .../mapreduce/lib/impl/InputConfigurator.java | 26 +++---- .../lib/partition/RangePartitioner.java | 4 +- .../core/client/mock/MockConfiguration.java | 22 +----- .../core/conf/AccumuloConfiguration.java | 27 ++------ .../accumulo/core/conf/ConfigurationCopy.java | 5 +- .../core/conf/DefaultConfiguration.java | 5 +- .../apache/accumulo/core/conf/PropertyType.java | 69 +++++++----------- .../accumulo/core/conf/SiteConfiguration.java | 7 +- .../accumulo/core/data/impl/TabletIdImpl.java | 4 +- .../impl/SeekableByteArrayInputStream.java | 8 +-- .../core/file/rfile/MultiLevelIndex.java | 10 +-- .../iterators/user/IntersectingIterator.java | 10 +-- .../accumulo/core/security/Authorizations.java | 6 +- .../org/apache/accumulo/core/util/Base64.java | 73 -------------------- .../apache/accumulo/core/util/CreateToken.java | 3 +- .../org/apache/accumulo/core/util/Encoding.java | 9 ++- .../apache/accumulo/core/util/Validator.java | 20 +++--- .../core/util/format/DateFormatSupplier.java | 3 +- .../core/util/format/FormatterConfig.java | 3 +- .../core/client/impl/ClientContextTest.java | 6 +- .../client/mapred/AccumuloInputFormatTest.java | 5 +- .../mapreduce/AccumuloInputFormatTest.java | 5 +- .../lib/impl/ConfiguratorBaseTest.java | 7 +- .../core/conf/DefaultConfigurationTest.java | 6 +- .../core/conf/ObservableConfigurationTest.java | 3 +- .../accumulo/core/conf/PropertyTypeTest.java | 42 ++++------- .../core/conf/SiteConfigurationTest.java | 6 +- .../accumulo/core/util/ValidatorTest.java | 22 +++--- .../examples/simple/mapreduce/RowHash.java | 4 +- .../mapreduce/bulk/BulkIngestExample.java | 6 +- maven-plugin/pom.xml | 6 ++ .../impl/MiniAccumuloClusterImpl.java | 11 +-- .../server/conf/NamespaceConfiguration.java | 7 +- .../server/conf/TableConfiguration.java | 3 +- .../server/conf/ZooCachePropertyAccessor.java | 5 +- .../accumulo/server/conf/ZooConfiguration.java | 5 +- .../server/fs/PreferredVolumeChooser.java | 10 +-- .../server/fs/VolumeChooserEnvironment.java | 2 +- .../accumulo/server/fs/VolumeManager.java | 3 +- .../accumulo/server/fs/VolumeManagerImpl.java | 2 +- .../apache/accumulo/server/fs/VolumeUtil.java | 4 +- .../apache/accumulo/server/init/Initialize.java | 12 ++-- .../server/master/balancer/GroupBalancer.java | 5 +- .../master/balancer/RegexGroupBalancer.java | 3 +- .../master/state/TabletStateChangeIterator.java | 10 +-- .../server/security/SystemCredentials.java | 4 +- .../security/handler/KerberosAuthenticator.java | 12 ++-- .../security/handler/KerberosAuthorizor.java | 14 ++-- .../handler/KerberosPermissionHandler.java | 33 ++++----- .../accumulo/server/util/DumpZookeeper.java | 4 +- .../apache/accumulo/server/util/FileUtil.java | 5 +- .../accumulo/server/util/MetadataTableUtil.java | 2 +- .../accumulo/server/util/RandomizeVolumes.java | 3 +- .../accumulo/server/util/RestoreZookeeper.java | 4 +- .../server/conf/NamespaceConfigurationTest.java | 6 +- .../server/conf/TableConfigurationTest.java | 6 +- .../conf/ZooCachePropertyAccessorTest.java | 9 ++- .../server/fs/VolumeManagerImplTest.java | 3 +- .../BaseHostRegexTableLoadBalancerTest.java | 7 +- .../master/balancer/GroupBalancerTest.java | 11 +-- .../HostRegexTableLoadBalancerTest.java | 7 +- ...redentialsUpdatingInvocationHandlerTest.java | 3 +- .../server/security/UserImpersonationTest.java | 2 +- .../accumulo/server/util/FileUtilTest.java | 3 +- .../accumulo/gc/SimpleGarbageCollector.java | 42 ++++------- .../accumulo/master/FateServiceHandler.java | 2 +- .../java/org/apache/accumulo/master/Master.java | 2 +- .../accumulo/master/TabletGroupWatcher.java | 2 +- .../accumulo/master/tableOps/ChooseDir.java | 4 +- .../master/tableOps/PopulateMetadataTable.java | 3 +- .../apache/accumulo/master/tableOps/Utils.java | 6 +- .../accumulo/master/util/TableValidators.java | 12 ++-- .../master/tableOps/ImportTableTest.java | 4 +- .../monitor/servlets/TServersServlet.java | 6 +- .../apache/accumulo/tserver/InMemoryMap.java | 8 +-- .../apache/accumulo/tserver/log/DfsLogger.java | 4 +- .../apache/accumulo/tserver/tablet/Tablet.java | 6 +- .../tserver/LargestFirstMemoryManagerTest.java | 10 +-- .../tserver/TabletServerSyncCheckTest.java | 2 +- .../org/apache/accumulo/shell/ShellUtil.java | 6 +- .../accumulo/shell/commands/FateCommand.java | 9 +-- .../shell/commands/GetSplitsCommand.java | 9 ++- .../accumulo/shell/commands/HiddenCommand.java | 9 +-- .../accumulo/shell/commands/HistoryCommand.java | 13 +--- .../shell/commands/NamespacesCommand.java | 23 +++--- .../accumulo/shell/commands/TablesCommand.java | 31 +++------ .../apache/accumulo/shell/ShellUtilTest.java | 9 ++- .../accumulo/test/functional/MapReduceIT.java | 4 +- .../functional/TabletStateChangeIteratorIT.java | 8 +-- .../test/randomwalk/shard/BulkInsert.java | 7 +- .../test/replication/ReplicationIT.java | 11 +-- .../apache/accumulo/test/util/CertUtils.java | 4 +- .../accumulo/test/util/SerializationUtil.java | 18 ++--- .../test/TraceRepoDeserializationTest.java | 5 +- .../test/iterator/AgeOffFilterTest.java | 13 +--- .../test/iterator/CfCqSliceFilterTest.java | 17 ++--- 103 files changed, 377 insertions(+), 641 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java index 71ee6d1..cf9a79a 100644 --- a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java +++ b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java @@ -24,6 +24,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import java.util.function.Predicate; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; @@ -56,7 +57,6 @@ import org.apache.log4j.Logger; import com.beust.jcommander.DynamicParameter; import com.beust.jcommander.IStringConverter; import com.beust.jcommander.Parameter; -import com.google.common.base.Predicate; public class ClientOpts extends Help { @@ -344,10 +344,10 @@ public class ClientOpts extends Help { @Override public void getProperties(Map<String,String> props, Predicate<String> filter) { for (Entry<String,String> prop : DefaultConfiguration.getInstance()) - if (filter.apply(prop.getKey())) + if (filter.test(prop.getKey())) props.put(prop.getKey(), prop.getValue()); for (Entry<String,String> prop : xml) - if (filter.apply(prop.getKey())) + if (filter.test(prop.getKey())) props.put(prop.getKey(), prop.getValue()); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java index e8f675b..2eea041 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java +++ b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java @@ -16,7 +16,6 @@ */ package org.apache.accumulo.core.client; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -24,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; import org.apache.accumulo.core.client.impl.Tables; import org.apache.accumulo.core.client.security.SecurityErrorCode; @@ -31,9 +32,6 @@ import org.apache.accumulo.core.data.ConstraintViolationSummary; import org.apache.accumulo.core.data.TabletId; import org.apache.accumulo.core.data.impl.TabletIdImpl; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; - /** * Communicate the failed mutations of a BatchWriter back to the client. * @@ -153,7 +151,7 @@ public class MutationsRejectedException extends AccumuloException { */ @Deprecated public List<org.apache.accumulo.core.data.KeyExtent> getAuthorizationFailures() { - return new ArrayList<org.apache.accumulo.core.data.KeyExtent>(Collections2.transform(af.keySet(), TabletIdImpl.TID_2_KE_OLD)); + return af.keySet().stream().map(TabletIdImpl.TID_2_KE_OLD).collect(Collectors.toList()); } /** http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java index 6828174..b4c2f47 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ClientContext.java @@ -22,6 +22,7 @@ import static java.util.Objects.requireNonNull; import java.io.IOException; import java.util.Iterator; import java.util.Map; +import java.util.function.Predicate; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -41,8 +42,6 @@ import org.apache.commons.configuration.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Predicate; - /** * This class represents any essential configuration and credentials needed to initiate RPC operations throughout the code. It is intended to represent a shared * object that contains these things from when the client was first constructed. It is not public API, and is only an internal representation of the context in @@ -219,7 +218,7 @@ public class ClientContext { Iterator<?> keyIter = config.getKeys(); while (keyIter.hasNext()) { String key = keyIter.next().toString(); - if (filter.apply(key)) + if (filter.test(key)) props.put(key, config.getString(key)); } @@ -227,7 +226,7 @@ public class ClientContext { // Automatically reconstruct the server property when converting a client config. if (props.containsKey(ClientProperty.KERBEROS_SERVER_PRIMARY.getKey())) { final String serverPrimary = props.remove(ClientProperty.KERBEROS_SERVER_PRIMARY.getKey()); - if (filter.apply(Property.GENERAL_KERBEROS_PRINCIPAL.getKey())) { + if (filter.test(Property.GENERAL_KERBEROS_PRINCIPAL.getKey())) { // Use the _HOST expansion. It should be unnecessary in "client land". props.put(Property.GENERAL_KERBEROS_PRINCIPAL.getKey(), serverPrimary + "/_HOST@" + SaslConnectionParams.getDefaultRealm()); } @@ -242,7 +241,7 @@ public class ClientContext { continue; } - if (filter.apply(key)) { + if (filter.test(key)) { char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf, key); if (null != value) { props.put(key, new String(value)); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/impl/Credentials.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Credentials.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Credentials.java index 28a704a..13b2463 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Credentials.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Credentials.java @@ -19,6 +19,7 @@ package org.apache.accumulo.core.client.impl; import static java.nio.charset.StandardCharsets.UTF_8; import java.nio.ByteBuffer; +import java.util.Base64; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -27,7 +28,6 @@ import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer; import org.apache.accumulo.core.security.thrift.TCredentials; -import org.apache.accumulo.core.util.Base64; /** * A wrapper for internal use. This class carries the instance, principal, and authentication token for use in the public API, in a non-serialized form. This is @@ -109,9 +109,9 @@ public class Credentials { * @return serialized form of these credentials */ public final String serialize() { - return (getPrincipal() == null ? "-" : Base64.encodeBase64String(getPrincipal().getBytes(UTF_8))) + ":" - + (getToken() == null ? "-" : Base64.encodeBase64String(getToken().getClass().getName().getBytes(UTF_8))) + ":" - + (getToken() == null ? "-" : Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(getToken()))); + return (getPrincipal() == null ? "-" : new String(Base64.getEncoder().encode(getPrincipal().getBytes(UTF_8)), UTF_8)) + ":" + + (getToken() == null ? "-" : new String(Base64.getEncoder().encode(getToken().getClass().getName().getBytes(UTF_8)), UTF_8)) + ":" + + (getToken() == null ? "-" : new String(Base64.getEncoder().encode(AuthenticationTokenSerializer.serialize(getToken())), UTF_8)); } /** @@ -123,11 +123,11 @@ public class Credentials { */ public static final Credentials deserialize(String serializedForm) { String[] split = serializedForm.split(":", 3); - String principal = split[0].equals("-") ? null : new String(Base64.decodeBase64(split[0]), UTF_8); - String tokenType = split[1].equals("-") ? null : new String(Base64.decodeBase64(split[1]), UTF_8); + String principal = split[0].equals("-") ? null : new String(Base64.getDecoder().decode(split[0].getBytes(UTF_8)), UTF_8); + String tokenType = split[1].equals("-") ? null : new String(Base64.getDecoder().decode(split[1].getBytes(UTF_8)), UTF_8); AuthenticationToken token = null; if (!split[2].equals("-")) { - byte[] tokenBytes = Base64.decodeBase64(split[2]); + byte[] tokenBytes = Base64.getDecoder().decode(split[2].getBytes(UTF_8)); token = AuthenticationTokenSerializer.deserialize(tokenType, tokenBytes); } return new Credentials(principal, token); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java index 433b020..9df9abb 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java @@ -37,7 +37,7 @@ public class Namespaces { public static final String VALID_NAME_REGEX = "^\\w*$"; public static final Validator<String> VALID_NAME = new Validator<String>() { @Override - public boolean apply(String namespace) { + public boolean test(String namespace) { return namespace != null && namespace.matches(VALID_NAME_REGEX); } @@ -51,7 +51,7 @@ public class Namespaces { public static final Validator<String> NOT_DEFAULT = new Validator<String>() { @Override - public boolean apply(String namespace) { + public boolean test(String namespace) { return !Namespaces.DEFAULT_NAMESPACE.equals(namespace); } @@ -63,7 +63,7 @@ public class Namespaces { public static final Validator<String> NOT_ACCUMULO = new Validator<String>() { @Override - public boolean apply(String namespace) { + public boolean test(String namespace) { return !Namespaces.ACCUMULO_NAMESPACE.equals(namespace); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java index b4f9dca..46498de 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java @@ -23,6 +23,7 @@ import java.io.DataOutput; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -44,7 +45,6 @@ import org.apache.accumulo.core.data.PartialKey; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl; import org.apache.accumulo.core.security.Authorizations; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.DeprecationUtil; import org.apache.accumulo.core.util.Pair; import org.apache.hadoop.io.Text; @@ -185,7 +185,7 @@ public class RangeInputSplit extends InputSplit implements Writable { case INLINE: String tokenClass = in.readUTF(); byte[] base64TokenBytes = in.readUTF().getBytes(UTF_8); - byte[] tokenBytes = Base64.decodeBase64(base64TokenBytes); + byte[] tokenBytes = Base64.getDecoder().decode(base64TokenBytes); this.token = AuthenticationTokenSerializer.deserialize(tokenClass, tokenBytes); break; @@ -280,7 +280,7 @@ public class RangeInputSplit extends InputSplit implements Writable { throw new IOException("Cannot use both inline AuthenticationToken and file-based AuthenticationToken"); } else if (null != token) { out.writeUTF(token.getClass().getName()); - out.writeUTF(Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(token))); + out.writeUTF(new String(Base64.getEncoder().encode(AuthenticationTokenSerializer.serialize(token)), UTF_8)); } else { out.writeUTF(tokenFile); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java index 67fe2f4..a74425b 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java @@ -25,6 +25,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.util.Base64; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -37,7 +38,6 @@ import org.apache.accumulo.core.client.impl.DelegationTokenImpl; import org.apache.accumulo.core.client.mapreduce.impl.DelegationTokenStub; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.DeprecationUtil; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; @@ -155,8 +155,8 @@ public class ConfiguratorBase { conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), TokenSource.JOB.prefix() + token.getClass().getName() + ":" + delToken.getServiceName().toString()); } else { - conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), - TokenSource.INLINE.prefix() + token.getClass().getName() + ":" + Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(token))); + conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), TokenSource.INLINE.prefix() + token.getClass().getName() + ":" + + new String(Base64.getEncoder().encode(AuthenticationTokenSerializer.serialize(token)), UTF_8)); } } @@ -244,7 +244,7 @@ public class ConfiguratorBase { if (token.startsWith(TokenSource.INLINE.prefix())) { String[] args = token.substring(TokenSource.INLINE.prefix().length()).split(":", 2); if (args.length == 2) - return AuthenticationTokenSerializer.deserialize(args[0], Base64.decodeBase64(args[1].getBytes(UTF_8))); + return AuthenticationTokenSerializer.deserialize(args[0], Base64.getDecoder().decode(args[1].getBytes(UTF_8))); } else if (token.startsWith(TokenSource.FILE.prefix())) { String tokenFileName = token.substring(TokenSource.FILE.prefix().length()); return getTokenFromFile(conf, getPrincipal(implementingClass, conf), tokenFileName); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java index 4cc3055..06bf930 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java @@ -26,6 +26,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Base64; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -67,7 +68,6 @@ import org.apache.accumulo.core.metadata.schema.MetadataSchema; import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl; import org.apache.accumulo.core.security.Authorizations; import org.apache.accumulo.core.security.TablePermission; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.DeprecationUtil; import org.apache.accumulo.core.util.Pair; import org.apache.accumulo.core.util.TextUtil; @@ -214,7 +214,7 @@ public class InputConfigurator extends ConfiguratorBase { for (Range r : ranges) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); r.write(new DataOutputStream(baos)); - rangeStrings.add(Base64.encodeBase64String(baos.toByteArray())); + rangeStrings.add(new String(Base64.getEncoder().encode(baos.toByteArray()), UTF_8)); } conf.setStrings(enumToConfKey(implementingClass, ScanOpts.RANGES), rangeStrings.toArray(new String[0])); } catch (IOException ex) { @@ -240,7 +240,7 @@ public class InputConfigurator extends ConfiguratorBase { Collection<String> encodedRanges = conf.getStringCollection(enumToConfKey(implementingClass, ScanOpts.RANGES)); List<Range> ranges = new ArrayList<Range>(); for (String rangeString : encodedRanges) { - ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(rangeString.getBytes(UTF_8))); + ByteArrayInputStream bais = new ByteArrayInputStream(Base64.getDecoder().decode(rangeString.getBytes(UTF_8))); Range range = new Range(); range.readFields(new DataInputStream(bais)); ranges.add(range); @@ -272,7 +272,7 @@ public class InputConfigurator extends ConfiguratorBase { try { while (tokens.hasMoreTokens()) { String itstring = tokens.nextToken(); - ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(itstring.getBytes(UTF_8))); + ByteArrayInputStream bais = new ByteArrayInputStream(Base64.getDecoder().decode(itstring.getBytes(UTF_8))); list.add(new IteratorSetting(new DataInputStream(bais))); bais.close(); } @@ -310,9 +310,9 @@ public class InputConfigurator extends ConfiguratorBase { if (column.getFirst() == null) throw new IllegalArgumentException("Column family can not be null"); - String col = Base64.encodeBase64String(TextUtil.getBytes(column.getFirst())); + String col = new String(Base64.getEncoder().encode(TextUtil.getBytes(column.getFirst())), UTF_8); if (column.getSecond() != null) - col += ":" + Base64.encodeBase64String(TextUtil.getBytes(column.getSecond())); + col += ":" + new String(Base64.getEncoder().encode(TextUtil.getBytes(column.getSecond())), UTF_8); columnStrings.add(col); } @@ -352,8 +352,8 @@ public class InputConfigurator extends ConfiguratorBase { for (String col : serialized) { int idx = col.indexOf(":"); - Text cf = new Text(idx < 0 ? Base64.decodeBase64(col.getBytes(UTF_8)) : Base64.decodeBase64(col.substring(0, idx).getBytes(UTF_8))); - Text cq = idx < 0 ? null : new Text(Base64.decodeBase64(col.substring(idx + 1).getBytes(UTF_8))); + Text cf = new Text(idx < 0 ? Base64.getDecoder().decode(col.getBytes(UTF_8)) : Base64.getDecoder().decode(col.substring(0, idx).getBytes(UTF_8))); + Text cq = idx < 0 ? null : new Text(Base64.getDecoder().decode(col.substring(idx + 1).getBytes(UTF_8))); columns.add(new Pair<Text,Text>(cf, cq)); } return columns; @@ -377,7 +377,7 @@ public class InputConfigurator extends ConfiguratorBase { String newIter; try { cfg.write(new DataOutputStream(baos)); - newIter = Base64.encodeBase64String(baos.toByteArray()); + newIter = new String(Base64.getEncoder().encode(baos.toByteArray()), UTF_8); baos.close(); } catch (IOException e) { throw new IllegalArgumentException("unable to serialize IteratorSetting"); @@ -608,7 +608,7 @@ public class InputConfigurator extends ConfiguratorBase { } String confKey = enumToConfKey(implementingClass, ScanOpts.TABLE_CONFIGS); - conf.set(confKey, Base64.encodeBase64String(baos.toByteArray())); + conf.set(confKey, new String(Base64.getEncoder().encode(baos.toByteArray()), UTF_8)); } /** @@ -630,7 +630,7 @@ public class InputConfigurator extends ConfiguratorBase { MapWritable mapWritable = new MapWritable(); if (configString != null) { try { - byte[] bytes = Base64.decodeBase64(configString.getBytes(UTF_8)); + byte[] bytes = Base64.getDecoder().decode(configString.getBytes(UTF_8)); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); mapWritable.readFields(new DataInputStream(bais)); bais.close(); @@ -950,11 +950,11 @@ public class InputConfigurator extends ConfiguratorBase { throw new RuntimeException(e); } - return Base64.encodeBase64String(baos.toByteArray()); + return new String(Base64.getEncoder().encode(baos.toByteArray()), UTF_8); } private static <T extends Writable> T fromBase64(T writable, String enc) { - ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(enc)); + ByteArrayInputStream bais = new ByteArrayInputStream(Base64.getDecoder().decode(enc.getBytes(UTF_8))); DataInputStream dis = new DataInputStream(bais); try { writable.readFields(dis); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java index c0c0097..eb2b1aa 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java @@ -25,11 +25,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import java.util.Arrays; +import java.util.Base64; import java.util.Scanner; import java.util.TreeSet; import org.apache.accumulo.core.client.mapreduce.lib.impl.DistributedCacheHelper; -import org.apache.accumulo.core.util.Base64; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; @@ -93,7 +93,7 @@ public class RangePartitioner extends Partitioner<Text,Writable> implements Conf Scanner in = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(path.toString()), UTF_8))); try { while (in.hasNextLine()) - cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes(UTF_8)))); + cutPoints.add(new Text(Base64.getDecoder().decode(in.nextLine().getBytes(UTF_8)))); } finally { in.close(); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java index 244d6f8..38ed1df 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java @@ -18,12 +18,11 @@ package org.apache.accumulo.core.client.mock; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; -import com.google.common.base.Predicate; - /** * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead. */ @@ -44,27 +43,10 @@ class MockConfiguration extends AccumuloConfiguration { return map.get(property.getKey()); } - /** - * Don't use this method. It has been deprecated. Its parameters are not public API and subject to change. - * - * @deprecated since 1.7.0; use {@link #getProperties(Map, Predicate)} instead. - */ - @Deprecated - public void getProperties(Map<String,String> props, final PropertyFilter filter) { - // convert PropertyFilter to Predicate - getProperties(props, new Predicate<String>() { - - @Override - public boolean apply(String input) { - return filter.accept(input); - } - }); - } - @Override public void getProperties(Map<String,String> props, Predicate<String> filter) { for (Entry<String,String> entry : map.entrySet()) { - if (filter.apply(entry.getKey())) { + if (filter.test(entry.getKey())) { props.put(entry.getKey(), entry.getValue()); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java index e74e71b..f3c37db 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java @@ -23,6 +23,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.TreeMap; import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; @@ -33,32 +34,12 @@ import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - /** * A configuration object. */ public abstract class AccumuloConfiguration implements Iterable<Entry<String,String>> { /** - * A filter for properties, based on key. - * - * @deprecated since 1.7.0; use {@link Predicate} instead. - */ - @Deprecated - public interface PropertyFilter { - /** - * Determines whether to accept a property based on its key. - * - * @param key - * property key - * @return true to accept property (pass filter) - */ - boolean accept(String key); - } - - /** * A filter that accepts properties whose keys are an exact match. */ public static class MatchFilter implements Predicate<String> { @@ -76,7 +57,7 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str } @Override - public boolean apply(String key) { + public boolean test(String key) { return Objects.equals(match, key); } } @@ -99,7 +80,7 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str } @Override - public boolean apply(String key) { + public boolean test(String key) { return key.startsWith(prefix); } } @@ -149,7 +130,7 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str */ @Override public Iterator<Entry<String,String>> iterator() { - Predicate<String> all = Predicates.alwaysTrue(); + Predicate<String> all = x -> true; TreeMap<String,String> entries = new TreeMap<String,String>(); getProperties(entries, all); return entries.entrySet().iterator(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java b/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java index 28b188f..cf3eb92 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationCopy.java @@ -20,8 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; - -import com.google.common.base.Predicate; +import java.util.function.Predicate; /** * An {@link AccumuloConfiguration} which holds a flat copy of properties defined in another configuration @@ -66,7 +65,7 @@ public class ConfigurationCopy extends AccumuloConfiguration { @Override public void getProperties(Map<String,String> props, Predicate<String> filter) { for (Entry<String,String> entry : copy.entrySet()) { - if (filter.apply(entry.getKey())) { + if (filter.test(entry.getKey())) { props.put(entry.getKey(), entry.getValue()); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java index 34d7fd2..272a11d 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java @@ -20,8 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; - -import com.google.common.base.Predicate; +import java.util.function.Predicate; /** * An {@link AccumuloConfiguration} that contains only default values for properties. This class is a singleton. @@ -55,7 +54,7 @@ public class DefaultConfiguration extends AccumuloConfiguration { @Override public void getProperties(Map<String,String> props, Predicate<String> filter) { for (Entry<String,String> entry : resolvedProps.entrySet()) - if (filter.apply(entry.getKey())) + if (filter.test(entry.getKey())) props.put(entry.getKey(), entry.getValue()); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java b/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java index a0d0f68..bd80700 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java @@ -19,23 +19,19 @@ package org.apache.accumulo.core.conf; import static java.util.Objects.requireNonNull; import java.util.Arrays; -import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.accumulo.core.Constants; import org.apache.hadoop.fs.Path; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; - /** * Types of {@link Property} values. Each type has a short name, a description, and a regex which valid values match. All of these fields are optional. */ public enum PropertyType { - PREFIX(null, Predicates.<String> alwaysFalse(), null), + PREFIX(null, x -> false, null), TIMEDURATION("duration", boundedUnits(0, Long.MAX_VALUE, true, "", "ms", "s", "m", "h", "d"), "A non-negative integer optionally followed by a unit of time (whitespace disallowed), as in 30s.\n" @@ -56,7 +52,7 @@ public enum PropertyType { + "Examples of valid host lists are 'localhost:2000,www.example.com,10.10.1.1:500' and 'localhost'.\n" + "Examples of invalid host lists are '', ':1000', and 'localhost:80000'"), - PORT("port", Predicates.or(new Bounds(1024, 65535), in(true, "0")), + PORT("port", new Bounds(1024, 65535).or(in(true, "0")), "An positive integer in the range 1024-65535, not already in use or specified elsewhere in the configuration"), COUNT("count", new Bounds(0, Integer.MAX_VALUE), "A non-negative integer in the range of 0-" + Integer.MAX_VALUE), @@ -66,16 +62,12 @@ public enum PropertyType { + "Examples of valid fractions/percentages are '10', '1000%', '0.05', '5%', '0.2%', '0.0005'.\n" + "Examples of invalid fractions/percentages are '', '10 percent', 'Hulk Hogan'"), - PATH("path", Predicates.<String> alwaysTrue(), + PATH("path", x -> true, "A string that represents a filesystem path, which can be either relative or absolute to some directory. The filesystem depends on the property. The " + "following environment variables will be substituted: " + Constants.PATH_PROPERTY_ENV_VARS), - ABSOLUTEPATH("absolute path", new Predicate<String>() { - @Override - public boolean apply(final String input) { - return input == null || input.trim().isEmpty() || new Path(input.trim()).isAbsolute(); - } - }, "An absolute filesystem path. The filesystem depends on the property. This is the same as path, but enforces that its root is explicitly specified."), + ABSOLUTEPATH("absolute path", x -> x == null || x.trim().isEmpty() || new Path(x.trim()).isAbsolute(), + "An absolute filesystem path. The filesystem depends on the property. This is the same as path, but enforces that its root is explicitly specified."), CLASSNAME("java class", new Matches("[\\w$.]*"), "A fully qualified java class name representing a class on the classpath.\n" + "An example is 'java.lang.String', rather than 'String'"), @@ -85,12 +77,12 @@ public enum PropertyType { DURABILITY("durability", in(true, null, "none", "log", "flush", "sync"), "One of 'none', 'log', 'flush' or 'sync'."), - STRING("string", Predicates.<String> alwaysTrue(), + STRING("string", x -> true, "An arbitrary string of characters whose format is unspecified and interpreted based on the context of the property to which it applies."), BOOLEAN("boolean", in(false, null, "true", "false"), "Has a value of either 'true' or 'false' (case-insensitive)"), - URI("uri", Predicates.<String> alwaysTrue(), "A valid URI"); + URI("uri", x -> true, "A valid URI"); private String shortname, format; private Predicate<String> predicate; @@ -121,38 +113,25 @@ public enum PropertyType { * @return true if value is valid or null, or if this type has no regex */ public boolean isValidFormat(String value) { - return predicate.apply(value); + return predicate.test(value); } - private static Predicate<String> in(final boolean caseSensitive, final String... strings) { - List<String> allowedSet = Arrays.asList(strings); + private static Predicate<String> in(final boolean caseSensitive, final String... allowedSet) { if (caseSensitive) { - return Predicates.in(allowedSet); + return x -> Arrays.stream(allowedSet).anyMatch(y -> (x == null && y == null) || (x != null && x.equals(y))); } else { - Function<String,String> toLower = new Function<String,String>() { - @Override - public String apply(final String input) { - return input == null ? null : input.toLowerCase(); - } - }; - return Predicates.compose(Predicates.in(Collections2.transform(allowedSet, toLower)), toLower); + Function<String,String> toLower = x -> x == null ? null : x.toLowerCase(); + return x -> Arrays.stream(allowedSet).map(toLower).anyMatch(y -> (x == null && y == null) || (x != null && toLower.apply(x).equals(y))); } } private static Predicate<String> boundedUnits(final long lowerBound, final long upperBound, final boolean caseSensitive, final String... suffixes) { - return Predicates.or(Predicates.isNull(), - Predicates.and(new HasSuffix(caseSensitive, suffixes), Predicates.compose(new Bounds(lowerBound, upperBound), new StripUnits()))); + Predicate<String> suffixCheck = new HasSuffix(caseSensitive, suffixes); + return x -> x == null || (suffixCheck.test(x) && new Bounds(lowerBound, upperBound).test(stripUnits.apply(x))); } - private static class StripUnits implements Function<String,String> { - private static Pattern SUFFIX_REGEX = Pattern.compile("[^\\d]*$"); - - @Override - public String apply(final String input) { - requireNonNull(input); - return SUFFIX_REGEX.matcher(input.trim()).replaceAll(""); - } - } + private static final Pattern SUFFIX_REGEX = Pattern.compile("[^\\d]*$"); + private static final Function<String,String> stripUnits = x -> x == null ? null : SUFFIX_REGEX.matcher(x.trim()).replaceAll(""); private static class HasSuffix implements Predicate<String> { @@ -163,14 +142,14 @@ public enum PropertyType { } @Override - public boolean apply(final String input) { + public boolean test(final String input) { requireNonNull(input); - Matcher m = StripUnits.SUFFIX_REGEX.matcher(input); + Matcher m = SUFFIX_REGEX.matcher(input); if (m.find()) { if (m.groupCount() != 0) { throw new AssertionError(m.groupCount()); } - return p.apply(m.group()); + return p.test(m.group()); } else { return true; } @@ -179,7 +158,7 @@ public enum PropertyType { private static class FractionPredicate implements Predicate<String> { @Override - public boolean apply(final String input) { + public boolean test(final String input) { if (input == null) { return true; } @@ -214,7 +193,7 @@ public enum PropertyType { } @Override - public boolean apply(final String input) { + public boolean test(final String input) { if (input == null) { return true; } @@ -253,7 +232,7 @@ public enum PropertyType { } @Override - public boolean apply(final String input) { + public boolean test(final String input) { // TODO when the input is null, it just means that the property wasn't set // we can add checks for not null for required properties with Predicates.and(Predicates.notNull(), ...), // or we can stop assuming that null is always okay for a Matches predicate, and do that explicitly with Predicates.or(Predicates.isNull(), ...) http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java index b2f5a18..e5e78d0 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java @@ -19,14 +19,13 @@ package org.apache.accumulo.core.conf; import java.io.IOException; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; import org.apache.accumulo.core.util.CachedConfiguration; import org.apache.hadoop.conf.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Predicate; - /** * An {@link AccumuloConfiguration} which loads properties from an XML file, usually accumulo-site.xml. This implementation supports defaulting undefined * property values to a parent configuration's definitions. @@ -121,7 +120,7 @@ public class SiteConfiguration extends AccumuloConfiguration { parent.getProperties(props, filter); for (Entry<String,String> entry : getXmlConfig()) - if (filter.apply(entry.getKey())) + if (filter.test(entry.getKey())) props.put(entry.getKey(), entry.getValue()); // CredentialProvider should take precedence over site @@ -133,7 +132,7 @@ public class SiteConfiguration extends AccumuloConfiguration { continue; } - if (filter.apply(key)) { + if (filter.test(key)) { char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf, key); if (null != value) { props.put(key, new String(value)); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java b/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java index 24a7141..d28a1ee 100644 --- a/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java @@ -17,12 +17,12 @@ package org.apache.accumulo.core.data.impl; +import java.util.function.Function; + import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.TabletId; import org.apache.hadoop.io.Text; -import com.google.common.base.Function; - public class TabletIdImpl implements TabletId { private KeyExtent ke; http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/SeekableByteArrayInputStream.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/SeekableByteArrayInputStream.java b/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/SeekableByteArrayInputStream.java index c6e7d29..4388d42 100644 --- a/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/SeekableByteArrayInputStream.java +++ b/core/src/main/java/org/apache/accumulo/core/file/blockfile/impl/SeekableByteArrayInputStream.java @@ -17,11 +17,11 @@ package org.apache.accumulo.core.file.blockfile.impl; +import static java.util.Objects.requireNonNull; + import java.io.IOException; import java.io.InputStream; -import com.google.common.base.Preconditions; - /** * This class is like byte array input stream with two differences. It supports seeking and avoids synchronization. */ @@ -112,14 +112,14 @@ public class SeekableByteArrayInputStream extends InputStream { public void close() throws IOException {} public SeekableByteArrayInputStream(byte[] buf) { - Preconditions.checkNotNull(buf, "bug argument was null"); + requireNonNull(buf, "bug argument was null"); this.buffer = buf; this.cur = 0; this.max = buf.length; } public SeekableByteArrayInputStream(byte[] buf, int maxOffset) { - Preconditions.checkNotNull(buf, "bug argument was null"); + requireNonNull(buf, "bug argument was null"); this.buffer = buf; this.cur = 0; this.max = maxOffset; http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/file/rfile/MultiLevelIndex.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/file/rfile/MultiLevelIndex.java b/core/src/main/java/org/apache/accumulo/core/file/rfile/MultiLevelIndex.java index a883f04..9ee4d13 100644 --- a/core/src/main/java/org/apache/accumulo/core/file/rfile/MultiLevelIndex.java +++ b/core/src/main/java/org/apache/accumulo/core/file/rfile/MultiLevelIndex.java @@ -16,6 +16,8 @@ */ package org.apache.accumulo.core.file.rfile; +import static java.util.Objects.requireNonNull; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInput; @@ -41,8 +43,6 @@ import org.apache.accumulo.core.file.blockfile.impl.SeekableByteArrayInputStream import org.apache.accumulo.core.file.rfile.bcfile.Utils; import org.apache.hadoop.io.WritableComparable; -import com.google.common.base.Preconditions; - public class MultiLevelIndex { public static class IndexEntry implements WritableComparable<IndexEntry> { @@ -144,8 +144,8 @@ public class MultiLevelIndex { protected int indexSize; SerializedIndexBase(int[] offsets, byte[] data) { - Preconditions.checkNotNull(offsets, "offsets argument was null"); - Preconditions.checkNotNull(data, "data argument was null"); + requireNonNull(offsets, "offsets argument was null"); + requireNonNull(data, "data argument was null"); this.offsets = offsets; this.data = data; sbais = new SeekableByteArrayInputStream(data); @@ -153,7 +153,7 @@ public class MultiLevelIndex { } SerializedIndexBase(byte[] data, int offsetsOffset, int numOffsets, int indexOffset, int indexSize) { - Preconditions.checkNotNull(data, "data argument was null"); + requireNonNull(data, "data argument was null"); sbais = new SeekableByteArrayInputStream(data, indexOffset + indexSize); dis = new DataInputStream(sbais); this.offsetsOffset = offsetsOffset; http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java index e7338f3..4e19472 100644 --- a/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java +++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java @@ -19,6 +19,7 @@ package org.apache.accumulo.core.iterators.user; import static java.nio.charset.StandardCharsets.UTF_8; import java.io.IOException; +import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -32,7 +33,6 @@ import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.iterators.IteratorEnvironment; import org.apache.accumulo.core.iterators.SortedKeyValueIterator; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.TextUtil; import org.apache.hadoop.io.Text; @@ -390,7 +390,7 @@ public class IntersectingIterator implements SortedKeyValueIterator<Key,Value> { protected static String encodeColumns(Text[] columns) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < columns.length; i++) { - sb.append(Base64.encodeBase64String(TextUtil.getBytes(columns[i]))); + sb.append(new String(Base64.getEncoder().encode(TextUtil.getBytes(columns[i])), UTF_8)); sb.append('\n'); } return sb.toString(); @@ -407,14 +407,14 @@ public class IntersectingIterator implements SortedKeyValueIterator<Key,Value> { else bytes[i] = 0; } - return Base64.encodeBase64String(bytes); + return new String(Base64.getEncoder().encode(bytes), UTF_8); } protected static Text[] decodeColumns(String columns) { String[] columnStrings = columns.split("\n"); Text[] columnTexts = new Text[columnStrings.length]; for (int i = 0; i < columnStrings.length; i++) { - columnTexts[i] = new Text(Base64.decodeBase64(columnStrings[i].getBytes(UTF_8))); + columnTexts[i] = new Text(Base64.getDecoder().decode(columnStrings[i].getBytes(UTF_8))); } return columnTexts; } @@ -427,7 +427,7 @@ public class IntersectingIterator implements SortedKeyValueIterator<Key,Value> { if (flags == null) return null; - byte[] bytes = Base64.decodeBase64(flags.getBytes(UTF_8)); + byte[] bytes = Base64.getDecoder().decode(flags.getBytes(UTF_8)); boolean[] bFlags = new boolean[bytes.length]; for (int i = 0; i < bytes.length; i++) { if (bytes[i] == 1) http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java index 001fed2..81a2784 100644 --- a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java +++ b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java @@ -22,6 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.io.Serializable; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -32,7 +33,6 @@ import java.util.TreeSet; import org.apache.accumulo.core.data.ArrayByteSequence; import org.apache.accumulo.core.data.ByteSequence; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.ByteBufferUtil; /** @@ -153,7 +153,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza authsString = authsString.substring(HEADER.length()); if (authsString.length() > 0) { for (String encAuth : authsString.split(",")) { - byte[] auth = Base64.decodeBase64(encAuth.getBytes(UTF_8)); + byte[] auth = Base64.getDecoder().decode(encAuth.getBytes(UTF_8)); auths.add(new ArrayByteSequence(auth)); } checkAuths(); @@ -340,7 +340,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza for (byte[] auth : authsList) { sb.append(sep); sep = ","; - sb.append(Base64.encodeBase64String(auth)); + sb.append(new String(Base64.getEncoder().encode(auth), UTF_8)); } return sb.toString(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/util/Base64.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/Base64.java b/core/src/main/java/org/apache/accumulo/core/util/Base64.java deleted file mode 100644 index ce54aae..0000000 --- a/core/src/main/java/org/apache/accumulo/core/util/Base64.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.core.util; - -import org.apache.commons.codec.binary.StringUtils; - -/** - * A wrapper around commons-codec's Base64 to make sure we get the non-chunked behavior that became the default in commons-codec version 1.5+ while relying on - * the commons-codec version 1.4 that Hadoop Client provides. - */ -public final class Base64 { - - /** - * Private to prevent instantiation. - */ - private Base64() {} - - /** - * Serialize to Base64 byte array, non-chunked. - */ - public static byte[] encodeBase64(byte[] data) { - return org.apache.commons.codec.binary.Base64.encodeBase64(data, false); - } - - /** - * Serialize to Base64 as a String, non-chunked. - */ - public static String encodeBase64String(byte[] data) { - /* Based on implementation of this same name function in commons-codec 1.5+. in commons-codec 1.4, the second param sets chunking to true. */ - return StringUtils.newStringUtf8(org.apache.commons.codec.binary.Base64.encodeBase64(data, false)); - } - - /** - * Serialize to Base64 as a String using the URLSafe alphabet, non-chunked. - * - * The URLSafe alphabet uses - instead of + and _ instead of /. - */ - public static String encodeBase64URLSafeString(byte[] data) { - return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(data); - } - - /** - * Decode, presuming bytes are base64. - * - * Transparently handles either the standard alphabet or the URL Safe one. - */ - public static byte[] decodeBase64(byte[] base64) { - return org.apache.commons.codec.binary.Base64.decodeBase64(base64); - } - - /** - * Decode, presuming String is base64. - * - * Transparently handles either the standard alphabet or the URL Safe one. - */ - public static byte[] decodeBase64(String base64String) { - return org.apache.commons.codec.binary.Base64.decodeBase64(base64String); - } -} http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java b/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java index 452c411..15463bf 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java +++ b/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.Base64; import jline.console.ConsoleReader; @@ -108,7 +109,7 @@ public class CreateToken implements KeywordExecutable { props.put(tp.getKey(), input); token.init(props); } - String tokenBase64 = Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(token)); + String tokenBase64 = new String(Base64.getEncoder().encode(AuthenticationTokenSerializer.serialize(token)), UTF_8); String tokenFile = opts.tokenFile; if (tokenFile == null) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/util/Encoding.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java index 524f377..f956651 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java @@ -18,12 +18,14 @@ package org.apache.accumulo.core.util; import static java.nio.charset.StandardCharsets.UTF_8; +import java.util.Base64; + import org.apache.hadoop.io.Text; public class Encoding { public static String encodeAsBase64FileName(Text data) { - String encodedRow = Base64.encodeBase64URLSafeString(TextUtil.getBytes(data)); + String encodedRow = new String(Base64.getUrlEncoder().encode(TextUtil.getBytes(data)), UTF_8); int index = encodedRow.length() - 1; while (index >= 0 && encodedRow.charAt(index) == '=') @@ -34,10 +36,7 @@ public class Encoding { } public static byte[] decodeBase64FileName(String node) { - while (node.length() % 4 != 0) - node += "="; - /* decode transparently handles URLSafe encodings */ - return Base64.decodeBase64(node.getBytes(UTF_8)); + return Base64.getUrlDecoder().decode(node.getBytes(UTF_8)); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/util/Validator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/Validator.java b/core/src/main/java/org/apache/accumulo/core/util/Validator.java index c1e3c80..06b0e2b 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/Validator.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Validator.java @@ -16,10 +16,10 @@ */ package org.apache.accumulo.core.util; -import com.google.common.base.Predicate; +import java.util.function.Predicate; /** - * A class that validates arguments of a particular type. Implementations must implement {@link #apply(Object)} and should override + * A class that validates arguments of a particular type. Implementations must implement {@link #test(Object)} and should override * {@link #invalidMessage(Object)}. */ public abstract class Validator<T> implements Predicate<T> { @@ -34,7 +34,7 @@ public abstract class Validator<T> implements Predicate<T> { * if validation fails */ public final T validate(final T argument) { - if (!apply(argument)) + if (!test(argument)) throw new IllegalArgumentException(invalidMessage(argument)); return argument; } @@ -65,13 +65,13 @@ public abstract class Validator<T> implements Predicate<T> { return new Validator<T>() { @Override - public boolean apply(T argument) { - return mine.apply(argument) && other.apply(argument); + public boolean test(T argument) { + return mine.test(argument) && other.test(argument); } @Override public String invalidMessage(T argument) { - return (mine.apply(argument) ? other : mine).invalidMessage(argument); + return (mine.test(argument) ? other : mine).invalidMessage(argument); } }; @@ -92,8 +92,8 @@ public abstract class Validator<T> implements Predicate<T> { return new Validator<T>() { @Override - public boolean apply(T argument) { - return mine.apply(argument) || other.apply(argument); + public boolean test(T argument) { + return mine.test(argument) || other.test(argument); } @Override @@ -114,8 +114,8 @@ public abstract class Validator<T> implements Predicate<T> { return new Validator<T>() { @Override - public boolean apply(T argument) { - return !mine.apply(argument); + public boolean test(T argument) { + return !mine.test(argument); } @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/util/format/DateFormatSupplier.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/format/DateFormatSupplier.java b/core/src/main/java/org/apache/accumulo/core/util/format/DateFormatSupplier.java index 9cf50e0..efe0190 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/format/DateFormatSupplier.java +++ b/core/src/main/java/org/apache/accumulo/core/util/format/DateFormatSupplier.java @@ -19,8 +19,7 @@ package org.apache.accumulo.core.util.format; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.TimeZone; - -import com.google.common.base.Supplier; +import java.util.function.Supplier; /** * DateFormatSupplier is a {@code ThreadLocal<DateFormat>} that will set the correct TimeZone when the object is retrieved by {@link #get()}. http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/main/java/org/apache/accumulo/core/util/format/FormatterConfig.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/format/FormatterConfig.java b/core/src/main/java/org/apache/accumulo/core/util/format/FormatterConfig.java index 0cd5139..65bbf8e 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/format/FormatterConfig.java +++ b/core/src/main/java/org/apache/accumulo/core/util/format/FormatterConfig.java @@ -23,8 +23,7 @@ import java.text.FieldPosition; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; - -import com.google.common.base.Supplier; +import java.util.function.Supplier; /** * Holds configuration settings for a {@link Formatter} http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/client/impl/ClientContextTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/ClientContextTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/ClientContextTest.java index ff9863c..a423057 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/impl/ClientContextTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/ClientContextTest.java @@ -29,9 +29,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - public class ClientContextTest { private static boolean isCredentialProviderAvailable = false; @@ -100,8 +97,7 @@ public class ClientContextTest { AccumuloConfiguration accClientConf = ClientContext.convertClientConfig(clientConf); Map<String,String> props = new HashMap<String,String>(); - Predicate<String> all = Predicates.alwaysTrue(); - accClientConf.getProperties(props, all); + accClientConf.getProperties(props, x -> true); // Only sensitive properties are added Assert.assertEquals(Property.GENERAL_RPC_TIMEOUT.getDefaultValue(), props.get(Property.GENERAL_RPC_TIMEOUT.getKey())); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloInputFormatTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloInputFormatTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloInputFormatTest.java index cb28958..1034f42 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloInputFormatTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloInputFormatTest.java @@ -16,18 +16,19 @@ */ package org.apache.accumulo.core.client.mapred; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Base64; import java.util.List; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.iterators.user.RegExFilter; import org.apache.accumulo.core.iterators.user.WholeRowIterator; -import org.apache.accumulo.core.util.Base64; import org.apache.hadoop.mapred.JobConf; import org.junit.Before; import org.junit.Rule; @@ -56,7 +57,7 @@ public class AccumuloInputFormatTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); is.write(new DataOutputStream(baos)); String iterators = job.get("AccumuloInputFormat.ScanOpts.Iterators"); - assertEquals(Base64.encodeBase64String(baos.toByteArray()), iterators); + assertEquals(new String(Base64.getEncoder().encode(baos.toByteArray()), UTF_8), iterators); } @Test http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java index 56c8195..f40a2c2 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java @@ -16,12 +16,14 @@ */ package org.apache.accumulo.core.client.mapreduce; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Base64; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -29,7 +31,6 @@ import java.util.Set; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.iterators.user.RegExFilter; import org.apache.accumulo.core.iterators.user.WholeRowIterator; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.Pair; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.Text; @@ -51,7 +52,7 @@ public class AccumuloInputFormatTest { ByteArrayOutputStream baos = new ByteArrayOutputStream(); is.write(new DataOutputStream(baos)); String iterators = conf.get("AccumuloInputFormat.ScanOpts.Iterators"); - assertEquals(Base64.encodeBase64String(baos.toByteArray()), iterators); + assertEquals(new String(Base64.getEncoder().encode(baos.toByteArray()), UTF_8), iterators); } @Test http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java index a7e5e0a..13b96c3 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java @@ -16,10 +16,13 @@ */ package org.apache.accumulo.core.client.mapreduce.lib.impl; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Base64; + import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.ClientConfiguration; @@ -29,7 +32,6 @@ import org.apache.accumulo.core.client.ZooKeeperInstance; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer; import org.apache.accumulo.core.client.security.tokens.PasswordToken; -import org.apache.accumulo.core.util.Base64; import org.apache.hadoop.conf.Configuration; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -63,7 +65,8 @@ public class ConfiguratorBaseTest { assertEquals(PasswordToken.class, token.getClass()); assertEquals(new PasswordToken("testPassword"), token); assertEquals( - "inline:" + PasswordToken.class.getName() + ":" + Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(new PasswordToken("testPassword"))), + "inline:" + PasswordToken.class.getName() + ":" + + new String(Base64.getEncoder().encode(AuthenticationTokenSerializer.serialize(new PasswordToken("testPassword"))), UTF_8), conf.get(ConfiguratorBase.enumToConfKey(this.getClass(), ConfiguratorBase.ConnectorInfo.TOKEN))); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/conf/DefaultConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/conf/DefaultConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/conf/DefaultConfigurationTest.java index 9566f2e..a942e15 100644 --- a/core/src/test/java/org/apache/accumulo/core/conf/DefaultConfigurationTest.java +++ b/core/src/test/java/org/apache/accumulo/core/conf/DefaultConfigurationTest.java @@ -23,9 +23,6 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - public class DefaultConfigurationTest { private DefaultConfiguration c; @@ -41,9 +38,8 @@ public class DefaultConfigurationTest { @Test public void testGetProperties() { - Predicate<String> all = Predicates.alwaysTrue(); Map<String,String> p = new java.util.HashMap<String,String>(); - c.getProperties(p, all); + c.getProperties(p, x -> true); assertEquals(Property.MASTER_CLIENTPORT.getDefaultValue(), p.get(Property.MASTER_CLIENTPORT.getKey())); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/conf/ObservableConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/conf/ObservableConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/conf/ObservableConfigurationTest.java index 8f73907..e6c7169 100644 --- a/core/src/test/java/org/apache/accumulo/core/conf/ObservableConfigurationTest.java +++ b/core/src/test/java/org/apache/accumulo/core/conf/ObservableConfigurationTest.java @@ -24,12 +24,11 @@ import static org.junit.Assert.assertTrue; import java.util.Collection; import java.util.Map; +import java.util.function.Predicate; import org.junit.Before; import org.junit.Test; -import com.google.common.base.Predicate; - public class ObservableConfigurationTest { private static class TestObservableConfig extends ObservableConfiguration { @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/conf/PropertyTypeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/conf/PropertyTypeTest.java b/core/src/test/java/org/apache/accumulo/core/conf/PropertyTypeTest.java index 9852ee8..8a01eb8 100644 --- a/core/src/test/java/org/apache/accumulo/core/conf/PropertyTypeTest.java +++ b/core/src/test/java/org/apache/accumulo/core/conf/PropertyTypeTest.java @@ -20,18 +20,17 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.lang.reflect.Method; import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; -import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; public class PropertyTypeTest { @@ -65,33 +64,16 @@ public class PropertyTypeTest { @Test public void testFullCoverage() { // This test checks the remainder of the methods in this class to ensure each property type has a corresponding test - Iterable<String> types = Iterables.transform(Arrays.asList(PropertyType.values()), new Function<PropertyType,String>() { - @Override - public String apply(final PropertyType input) { - return input.name(); - } + Stream<String> types = Arrays.stream(PropertyType.values()).map(v -> v.name()); + + List<String> typesTested = Arrays.stream(this.getClass().getMethods()).map(m -> m.getName()).filter(m -> m.startsWith("testType")).map(m -> m.substring(8)) + .collect(Collectors.toList()); + + types = types.map(t -> { + assertTrue(PropertyType.class.getSimpleName() + "." + t + " does not have a test.", typesTested.contains(t)); + return t; }); - Iterable<String> typesTested = Iterables.transform( - Iterables.filter(Iterables.transform(Arrays.asList(this.getClass().getMethods()), new Function<Method,String>() { - @Override - public String apply(final Method input) { - return input.getName(); - } - }), new Predicate<String>() { - @Override - public boolean apply(final String input) { - return input.startsWith("testType"); - } - }), new Function<String,String>() { - @Override - public String apply(final String input) { - return input.substring(8); - } - }); - for (String t : types) { - assertTrue(PropertyType.class.getSimpleName() + "." + t + " does not have a test.", Iterables.contains(typesTested, t)); - } - assertEquals(Iterables.size(types), Iterables.size(typesTested)); + assertEquals(types.count(), typesTested.size()); } private void valid(final String... args) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java index a0d48b9..7d74804 100644 --- a/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java +++ b/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java @@ -20,6 +20,7 @@ import java.io.File; import java.net.URL; import java.util.HashMap; import java.util.Map; +import java.util.function.Predicate; import org.apache.hadoop.conf.Configuration; import org.easymock.EasyMock; @@ -27,9 +28,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - public class SiteConfigurationTest { private static boolean isCredentialProviderAvailable; @@ -67,7 +65,7 @@ public class SiteConfigurationTest { EasyMock.replay(siteCfg); Map<String,String> props = new HashMap<String,String>(); - Predicate<String> all = Predicates.alwaysTrue(); + Predicate<String> all = x -> true; siteCfg.getProperties(props, all); Assert.assertEquals("mysecret", props.get(Property.INSTANCE_SECRET.getKey())); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/core/src/test/java/org/apache/accumulo/core/util/ValidatorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/util/ValidatorTest.java b/core/src/test/java/org/apache/accumulo/core/util/ValidatorTest.java index 01bad35..e6f360f 100644 --- a/core/src/test/java/org/apache/accumulo/core/util/ValidatorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/ValidatorTest.java @@ -32,7 +32,7 @@ public class ValidatorTest { } @Override - public boolean apply(String argument) { + public boolean test(String argument) { return s.equals(argument); } } @@ -45,7 +45,7 @@ public class ValidatorTest { } @Override - public boolean apply(String argument) { + public boolean test(String argument) { return (argument != null && argument.matches(ps)); } } @@ -77,24 +77,24 @@ public class ValidatorTest { @Test public void testAnd() { Validator<String> vand = v3.and(v); - assertTrue(vand.apply("correct")); - assertFalse(vand.apply("righto")); - assertFalse(vand.apply("coriander")); + assertTrue(vand.test("correct")); + assertFalse(vand.test("righto")); + assertFalse(vand.test("coriander")); } @Test public void testOr() { Validator<String> vor = v.or(v2); - assertTrue(vor.apply("correct")); - assertTrue(vor.apply("righto")); - assertFalse(vor.apply("coriander")); + assertTrue(vor.test("correct")); + assertTrue(vor.test("righto")); + assertFalse(vor.test("coriander")); } @Test public void testNot() { Validator<String> vnot = v3.not(); - assertFalse(vnot.apply("correct")); - assertFalse(vnot.apply("coriander")); - assertTrue(vnot.apply("righto")); + assertFalse(vnot.test("correct")); + assertFalse(vnot.test("coriander")); + assertTrue(vnot.test("righto")); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/RowHash.java ---------------------------------------------------------------------- diff --git a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/RowHash.java b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/RowHash.java index 9af2563..9088371 100644 --- a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/RowHash.java +++ b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/RowHash.java @@ -17,6 +17,7 @@ package org.apache.accumulo.examples.simple.mapreduce; import java.io.IOException; +import java.util.Base64; import java.util.Collections; import org.apache.accumulo.core.cli.MapReduceClientOnRequiredTable; @@ -25,7 +26,6 @@ import org.apache.accumulo.core.client.mapreduce.AccumuloOutputFormat; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.Pair; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; @@ -46,7 +46,7 @@ public class RowHash extends Configured implements Tool { @Override public void map(Key row, Value data, Context context) throws IOException, InterruptedException { Mutation m = new Mutation(row.getRow()); - m.put(new Text("cf-HASHTYPE"), new Text("cq-MD5BASE64"), new Value(Base64.encodeBase64(MD5Hash.digest(data.toString()).getDigest()))); + m.put(new Text("cf-HASHTYPE"), new Text("cq-MD5BASE64"), new Value(Base64.getEncoder().encode(MD5Hash.digest(data.toString()).getDigest()))); context.write(null, m); context.progress(); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/bulk/BulkIngestExample.java ---------------------------------------------------------------------- diff --git a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/bulk/BulkIngestExample.java b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/bulk/BulkIngestExample.java index fbe92b5..56dd9a2 100644 --- a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/bulk/BulkIngestExample.java +++ b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/bulk/BulkIngestExample.java @@ -16,9 +16,12 @@ */ package org.apache.accumulo.examples.simple.mapreduce.bulk; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.Base64; import java.util.Collection; import org.apache.accumulo.core.cli.MapReduceClientOnRequiredTable; @@ -27,7 +30,6 @@ import org.apache.accumulo.core.client.mapreduce.AccumuloFileOutputFormat; import org.apache.accumulo.core.client.mapreduce.lib.partition.RangePartitioner; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.util.Base64; import org.apache.accumulo.core.util.TextUtil; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; @@ -133,7 +135,7 @@ public class BulkIngestExample extends Configured implements Tool { Collection<Text> splits = connector.tableOperations().listSplits(opts.getTableName(), 100); for (Text split : splits) - out.println(Base64.encodeBase64String(TextUtil.getBytes(split))); + out.println(new String(Base64.getEncoder().encode(TextUtil.getBytes(split)), UTF_8)); job.setNumReduceTasks(splits.size() + 1); out.close(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/84f70731/maven-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml index 17b2591..0c9760e 100644 --- a/maven-plugin/pom.xml +++ b/maven-plugin/pom.xml @@ -46,6 +46,12 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> + <exclusions> + <exclusion> + <groupId>org.sonatype.sisu</groupId> + <artifactId>sisu-inject-bean</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.maven</groupId>