This is an automated email from the ASF dual-hosted git repository. aadamchik pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push: new dd57bcb cleanup - moving Base64Codec out of the core and into XMPP dd57bcb is described below commit dd57bcbac5af95262bb5115573b9bfd446d6dfe5 Author: Andrus Adamchik <and...@objectstyle.com> AuthorDate: Thu Jul 23 17:24:53 2020 +0300 cleanup - moving Base64Codec out of the core and into XMPP ... and even there it is not really needed, as Java 8 already has a Base64 encoder/decoder --- .../java/org/apache/cayenne/event/XMPPBridge.java | 2 +- .../apache/cayenne/event}/util/Base64Codec.java | 48 ++++++++++------------ .../cayenne/event}/util/Base64CodecTest.java | 2 +- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java b/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java index 0563ffd..103baaa 100644 --- a/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java +++ b/cayenne-xmpp/src/main/java/org/apache/cayenne/event/XMPPBridge.java @@ -20,7 +20,7 @@ package org.apache.cayenne.event; import org.apache.cayenne.CayenneRuntimeException; -import org.apache.cayenne.util.Base64Codec; +import org.apache.cayenne.event.util.Base64Codec; import org.apache.cayenne.util.Util; import org.jivesoftware.smack.GroupChat; import org.jivesoftware.smack.PacketListener; diff --git a/cayenne-server/src/main/java/org/apache/cayenne/util/Base64Codec.java b/cayenne-xmpp/src/main/java/org/apache/cayenne/event/util/Base64Codec.java similarity index 96% rename from cayenne-server/src/main/java/org/apache/cayenne/util/Base64Codec.java rename to cayenne-xmpp/src/main/java/org/apache/cayenne/event/util/Base64Codec.java index 5d4ba9f..b82abf6 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/util/Base64Codec.java +++ b/cayenne-xmpp/src/main/java/org/apache/cayenne/event/util/Base64Codec.java @@ -17,7 +17,7 @@ * under the License. ****************************************************************/ -package org.apache.cayenne.util; +package org.apache.cayenne.event.util; /** * Provides Base64 encoding and decoding as defined by RFC 2045. @@ -25,9 +25,11 @@ package org.apache.cayenne.util; * <i>This codec is based on Apache commons.codec implementation, copyright The Apache * Software Foundation.</i> * </p> - * + * * @since 1.2 + * @deprecated since 4.2. Java 8 has a built-in Base64 class. */ +@Deprecated public class Base64Codec { /** @@ -36,14 +38,14 @@ public class Base64Codec { * The {@value} character limit does not count the trailing CRLF, but counts all other * characters, including any equal signs. * </p> - * + * * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 6.8</a> */ static final int CHUNK_SIZE = 76; /** * Chunk separator per RFC 2045 section 2.1. - * + * * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a> */ static final byte[] CHUNK_SEPARATOR = "\r\n".getBytes(); @@ -130,11 +132,9 @@ public class Base64Codec { private static boolean isBase64(byte octect) { if (octect == PAD) { return true; - } - else if (base64Alphabet[octect] == -1) { + } else if (base64Alphabet[octect] == -1) { return false; - } - else { + } else { return true; } } @@ -142,10 +142,10 @@ public class Base64Codec { /** * Tests a given byte array to see if it contains only valid characters within the * Base64 alphabet. - * + * * @param arrayOctect byte array to test * @return true if all bytes are valid characters in the Base64 alphabet or if the - * byte array is empty; false, otherwise + * byte array is empty; false, otherwise */ public static boolean isArrayByteBase64(byte[] arrayOctect) { @@ -167,7 +167,7 @@ public class Base64Codec { /** * Encodes binary data using the base64 algorithm but does not chunk the output. - * + * * @param binaryData binary data to encode * @return Base64 characters */ @@ -178,7 +178,7 @@ public class Base64Codec { /** * Encodes binary data using the base64 algorithm and chunks the encoded output into * 76 character blocks - * + * * @param binaryData binary data to encode * @return Base64 characters chunked in 76 character blocks */ @@ -189,10 +189,10 @@ public class Base64Codec { /** * Encodes binary data using the base64 algorithm, optionally chunking the output into * 76 character blocks. - * + * * @param binaryData Array containing binary data to encode. - * @param isChunked if isChunked is true this encoder will chunk the base64 output - * into 76 character blocks + * @param isChunked if isChunked is true this encoder will chunk the base64 output + * into 76 character blocks * @return Base64-encoded data. */ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) { @@ -206,8 +206,7 @@ public class Base64Codec { if (fewerThan24bits != 0) { // data not divisible by 24 bit encodedDataLength = (numberTriplets + 1) * 4; - } - else { + } else { // 16 or 8 bit encodedDataLength = numberTriplets * 4; } @@ -289,8 +288,7 @@ public class Base64Codec { encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4]; encodedData[encodedIndex + 2] = PAD; encodedData[encodedIndex + 3] = PAD; - } - else if (fewerThan24bits == SIXTEENBIT) { + } else if (fewerThan24bits == SIXTEENBIT) { b1 = binaryData[dataIndex]; b2 = binaryData[dataIndex + 1]; @@ -319,7 +317,7 @@ public class Base64Codec { /** * Decodes Base64 data into octects - * + * * @param base64Data Byte array containing Base64 data * @return Array containing decoded data. */ @@ -368,12 +366,10 @@ public class Base64Codec { decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex + 1] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex + 2] = (byte) (b3 << 6 | b4); - } - else if (marker0 == PAD) { + } else if (marker0 == PAD) { // Two PAD e.g. 3c[Pad][Pad] decodedData[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); - } - else if (marker1 == PAD) { + } else if (marker1 == PAD) { // One PAD e.g. 3cQ[Pad] b3 = base64Alphabet[marker0]; @@ -387,7 +383,7 @@ public class Base64Codec { /** * Discards any whitespace from a base-64 encoded block. - * + * * @param data The base-64 encoded data to discard the whitespace from. * @return The data, less whitespace (see RFC 2045). */ @@ -418,7 +414,7 @@ public class Base64Codec { * Discards any characters outside of the base64 alphabet, per the requirements on * page 25 of RFC 2045 - "Any characters outside of the base64 alphabet are to be * ignored in base64 encoded data." - * + * * @param data The base-64 encoded data to groom * @return The data, less non-base64 characters (see RFC 2045). */ diff --git a/cayenne-server/src/test/java/org/apache/cayenne/util/Base64CodecTest.java b/cayenne-xmpp/src/test/java/org/apache/cayenne/event/util/Base64CodecTest.java similarity index 99% rename from cayenne-server/src/test/java/org/apache/cayenne/util/Base64CodecTest.java rename to cayenne-xmpp/src/test/java/org/apache/cayenne/event/util/Base64CodecTest.java index 0ae1a82..e3ffc2b 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/util/Base64CodecTest.java +++ b/cayenne-xmpp/src/test/java/org/apache/cayenne/event/util/Base64CodecTest.java @@ -17,7 +17,7 @@ * under the License. ****************************************************************/ -package org.apache.cayenne.util; +package org.apache.cayenne.event.util; import org.junit.Test;