Repository: ignite Updated Branches: refs/heads/master b4ece5fb3 -> 16298aea5
IGNITE-7312 Make use of plain java.util.Base64 instead of reflective alternatives Signed-off-by: Anton Vinogradov <a...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/16298aea Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/16298aea Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/16298aea Branch: refs/heads/master Commit: 16298aea53ef921b123a60c100867b777ca4af8d Parents: b4ece5f Author: Andrey Kuznetsov <stku...@gmail.com> Authored: Wed Feb 14 19:08:46 2018 +0300 Committer: Anton Vinogradov <a...@apache.org> Committed: Wed Feb 14 19:08:46 2018 +0300 ---------------------------------------------------------------------- .../rest/JettyRestProcessorSignedSelfTest.java | 5 +-- .../rest/protocols/GridRestProtocolAdapter.java | 5 +-- .../ignite/internal/util/Base64Encoder.java | 33 -------------- .../ignite/internal/util/Base64EncoderImpl.java | 45 -------------------- .../apache/ignite/internal/util/GridUnsafe.java | 18 +------- .../internal/util/LegacyBase64Encoder.java | 42 ------------------ 6 files changed, 5 insertions(+), 143 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/16298aea/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorSignedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorSignedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorSignedSelfTest.java index 205154e..00e4c68 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorSignedSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorSignedSelfTest.java @@ -22,11 +22,10 @@ import java.net.URL; import java.net.URLConnection; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Base64; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.internal.U; -import static org.apache.ignite.internal.util.GridUnsafe.encodeBase64; - /** * */ @@ -90,7 +89,7 @@ public class JettyRestProcessorSignedSelfTest extends JettyRestProcessorAbstract md.update(s.getBytes()); - String hash = encodeBase64(md.digest()); + String hash = Base64.getEncoder().encodeToString(md.digest()); return ts + ":" + hash; } http://git-wip-us.apache.org/repos/asf/ignite/blob/16298aea/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/GridRestProtocolAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/GridRestProtocolAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/GridRestProtocolAdapter.java index e78edef..eae2745 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/GridRestProtocolAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/GridRestProtocolAdapter.java @@ -23,6 +23,7 @@ import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.StringTokenizer; @@ -36,8 +37,6 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; import org.jetbrains.annotations.Nullable; -import static org.apache.ignite.internal.util.GridUnsafe.encodeBase64; - /** * Abstract protocol adapter. */ @@ -109,7 +108,7 @@ public abstract class GridRestProtocolAdapter implements GridRestProtocol { md.update(s.getBytes(UTF_8)); - String compHash = encodeBase64(md.digest()); + String compHash = Base64.getEncoder().encodeToString(md.digest()); return hash.equalsIgnoreCase(compHash); } http://git-wip-us.apache.org/repos/asf/ignite/blob/16298aea/modules/core/src/main/java/org/apache/ignite/internal/util/Base64Encoder.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/Base64Encoder.java b/modules/core/src/main/java/org/apache/ignite/internal/util/Base64Encoder.java deleted file mode 100644 index f5e4689..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/Base64Encoder.java +++ /dev/null @@ -1,33 +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.ignite.internal.util; - -/** - * BASE64 encoder interface. - * - * @deprecated Temporary interface. Use {@code java.util.Base64} directly instead. - */ -@Deprecated -public interface Base64Encoder { - /** - * Encodes given byte array. - * - * @return Encoded string. - */ - public String encode(byte[] msg); -} http://git-wip-us.apache.org/repos/asf/ignite/blob/16298aea/modules/core/src/main/java/org/apache/ignite/internal/util/Base64EncoderImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/Base64EncoderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/util/Base64EncoderImpl.java deleted file mode 100644 index fa29b5e..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/Base64EncoderImpl.java +++ /dev/null @@ -1,45 +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.ignite.internal.util; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Implementation of {@link Base64Encoder} interface for Java 8 and later. - * - * @deprecated Use {@code java.util.Base64} directly instead. - */ -@Deprecated -public class Base64EncoderImpl implements Base64Encoder { - /** {@inheritDoc} */ - @Override public String encode(byte[] msg) { - try { - Object encoder = Class.forName("java.util.Base64").getDeclaredMethod("getEncoder").invoke(null); - - Class<?> encCls = Class.forName("java.util.Base64$Encoder"); - - Method encMtd = encCls.getDeclaredMethod("encodeToString", byte[].class); - - return (String)encMtd.invoke(encoder, (Object)msg); - } - catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - throw new RuntimeException("Failed to encode Base64 message", e); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/16298aea/modules/core/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java index 0516de7..2cc0ae3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java @@ -108,12 +108,6 @@ public abstract class GridUnsafe { ? new ReflectiveDirectBufferCleaner() : new UnsafeDirectBufferCleaner(); - /** */ - private static final Base64Encoder BASE64_ENC = - majorJavaVersion(jdkVersion()) < 8 - ? new LegacyBase64Encoder() - : new Base64EncoderImpl(); - /** JavaNioAccess object. */ private static final Object JAVA_NIO_ACCESS_OBJ = javaNioAccessObject(); @@ -1793,14 +1787,4 @@ public abstract class GridUnsafe { UNSAFE.putByte(addr, (byte)(val)); } } - - /** - * Encodes bytes into Base64 string. - * - * @param msg Message to encode. - * @return Encoded message. - */ - public static String encodeBase64(byte[] msg) { - return BASE64_ENC.encode(msg); - } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/16298aea/modules/core/src/main/java/org/apache/ignite/internal/util/LegacyBase64Encoder.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/LegacyBase64Encoder.java b/modules/core/src/main/java/org/apache/ignite/internal/util/LegacyBase64Encoder.java deleted file mode 100644 index e6e9cb5..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/LegacyBase64Encoder.java +++ /dev/null @@ -1,42 +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.ignite.internal.util; - -import java.lang.reflect.Method; - -/** - * Implementation of {@link Base64Encoder} interface for Java 7 and earlier. - * - * @deprecated Use {@code jaba.util.Base64} instead. - */ -@Deprecated -public class LegacyBase64Encoder implements Base64Encoder { - /** {@inheritDoc} */ - @Override public String encode(byte[] msg) { - try { - Class<?> encoderCls = Class.forName("sun.misc.BASE64Encoder"); - - Method mtd = encoderCls.getMethod("encode", byte[].class); - - return (String)mtd.invoke(encoderCls.newInstance(), (Object)msg); - } - catch (ReflectiveOperationException e) { - throw new RuntimeException("Failed to encode message to BASE64", e); - } - } -}