Return-Path:
X-Original-To: apmail-activemq-commits-archive@www.apache.org
Delivered-To: apmail-activemq-commits-archive@www.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id 3400118DEB
for ;
Mon, 10 Aug 2015 15:13:04 +0000 (UTC)
Received: (qmail 46135 invoked by uid 500); 10 Aug 2015 15:13:03 -0000
Delivered-To: apmail-activemq-commits-archive@activemq.apache.org
Received: (qmail 46044 invoked by uid 500); 10 Aug 2015 15:13:03 -0000
Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@activemq.apache.org
Delivered-To: mailing list commits@activemq.apache.org
Received: (qmail 45220 invoked by uid 99); 10 Aug 2015 15:13:02 -0000
Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org)
(140.211.11.23)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Aug 2015 15:13:02 +0000
Received: by git1-us-west.apache.org (ASF Mail Server at
git1-us-west.apache.org, from userid 33)
id 7BFF8E0501; Mon, 10 Aug 2015 15:13:02 +0000 (UTC)
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
From: clebertsuconic@apache.org
To: commits@activemq.apache.org
Date: Mon, 10 Aug 2015 15:13:44 -0000
Message-Id: <20f250aeb0a845cf99f189e85de0af33@git.apache.org>
In-Reply-To: <6d75255d38c94b2f8601b49eb76c9d59@git.apache.org>
References: <6d75255d38c94b2f8601b49eb76c9d59@git.apache.org>
X-Mailer: ASF-Git Admin Mailer
Subject: [45/53] [abbrv] [partial] activemq-artemis git commit: automatic
checkstyle change
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQComponent.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQComponent.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQComponent.java
index a842828..60dacdc 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQComponent.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQComponent.java
@@ -16,8 +16,8 @@
*/
package org.apache.activemq.artemis.core.server;
-public interface ActiveMQComponent
-{
+public interface ActiveMQComponent {
+
void start() throws Exception;
void stop() throws Exception;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilBundle.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilBundle.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilBundle.java
index ae77c5c..664470a 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilBundle.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilBundle.java
@@ -16,7 +16,6 @@
*/
package org.apache.activemq.artemis.logs;
-
import org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.Message;
@@ -31,11 +30,11 @@ import org.jboss.logging.Messages;
* so 209000 to 209999
*/
@MessageBundle(projectCode = "AMQ")
-public interface ActiveMQUtilBundle
-{
+public interface ActiveMQUtilBundle {
+
ActiveMQUtilBundle BUNDLE = Messages.getBundle(ActiveMQUtilBundle.class);
- @Message(id = 209000, value = "invalid property: {0}" , format = Message.Format.MESSAGE_FORMAT)
+ @Message(id = 209000, value = "invalid property: {0}", format = Message.Format.MESSAGE_FORMAT)
ActiveMQIllegalStateException invalidProperty(String part);
@Message(id = 209001, value = "Invalid type: {0}", format = Message.Format.MESSAGE_FORMAT)
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilLogger.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilLogger.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilLogger.java
index 6d01c5a..b26d30d 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilLogger.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/ActiveMQUtilLogger.java
@@ -37,8 +37,8 @@ import org.jboss.logging.annotations.MessageLogger;
* so an INFO message would be 201000 to 201999
*/
@MessageLogger(projectCode = "AMQ")
-public interface ActiveMQUtilLogger extends BasicLogger
-{
+public interface ActiveMQUtilLogger extends BasicLogger {
+
/**
* The default logger.
*/
@@ -46,6 +46,6 @@ public interface ActiveMQUtilLogger extends BasicLogger
@LogMessage(level = Logger.Level.WARN)
@Message(id = 202000, value = "Missing privileges to set Thread Context Class Loader on Thread Factory. Using current Thread Context Class Loader",
- format = Message.Format.MESSAGE_FORMAT)
+ format = Message.Format.MESSAGE_FORMAT)
void missingPrivsForClassloader();
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
index b366b61..e0c1215 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java
@@ -29,8 +29,7 @@ import org.jboss.logmanager.ExtLogRecord;
*
* Be careful with this use as this is intended for testing only (such as testcases)
*/
-public class AssertionLoggerHandler extends ExtHandler
-{
+public class AssertionLoggerHandler extends ExtHandler {
private static final Map messages = new ConcurrentHashMap<>();
private static boolean capture = false;
@@ -39,40 +38,32 @@ public class AssertionLoggerHandler extends ExtHandler
* {@inheritDoc}
*/
@Override
- public void flush()
- {
+ public void flush() {
}
/**
* {@inheritDoc}
*/
@Override
- public void close() throws SecurityException
- {
+ public void close() throws SecurityException {
}
@Override
- protected void doPublish(final ExtLogRecord record)
- {
- if (capture)
- {
+ protected void doPublish(final ExtLogRecord record) {
+ if (capture) {
messages.put(record.getFormattedMessage(), record);
}
}
-
/**
* is there any record matching Level?
*
* @param level
* @return
*/
- public static boolean hasLevel(Level level)
- {
- for (ExtLogRecord record : messages.values())
- {
- if (record.getLevel().equals(level))
- {
+ public static boolean hasLevel(Level level) {
+ for (ExtLogRecord record : messages.values()) {
+ if (record.getLevel().equals(level)) {
return true;
}
}
@@ -86,37 +77,29 @@ public class AssertionLoggerHandler extends ExtHandler
* @param text
* @return
*/
- public static boolean findText(final String... text)
- {
- for (Map.Entry entry : messages.entrySet())
- {
+ public static boolean findText(final String... text) {
+ for (Map.Entry entry : messages.entrySet()) {
String key = entry.getKey();
boolean found = true;
- for (String txtCheck : text)
- {
+ for (String txtCheck : text) {
found = key.contains(txtCheck);
- if (!found)
- {
+ if (!found) {
// If the main log message doesn't contain what we're looking for let's look in the message from the exception (if there is one).
Throwable throwable = entry.getValue().getThrown();
- if (throwable != null && throwable.getMessage() != null)
- {
+ if (throwable != null && throwable.getMessage() != null) {
found = throwable.getMessage().contains(txtCheck);
- if (!found)
- {
+ if (!found) {
break;
}
}
- else
- {
+ else {
break;
}
}
}
- if (found)
- {
+ if (found) {
return true;
}
}
@@ -124,19 +107,16 @@ public class AssertionLoggerHandler extends ExtHandler
return false;
}
- public static final void clear()
- {
+ public static final void clear() {
messages.clear();
}
- public static final void startCapture()
- {
+ public static final void startCapture() {
clear();
capture = true;
}
- public static final void stopCapture()
- {
+ public static final void stopCapture() {
capture = false;
clear();
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
index 00d2a73..3c59f34 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadFactory.java
@@ -22,8 +22,8 @@ import java.security.PrivilegedAction;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
-public final class ActiveMQThreadFactory implements ThreadFactory
-{
+public final class ActiveMQThreadFactory implements ThreadFactory {
+
private final ThreadGroup group;
private final AtomicInteger threadCount = new AtomicInteger(0);
@@ -36,8 +36,7 @@ public final class ActiveMQThreadFactory implements ThreadFactory
private final AccessControlContext acc;
- public ActiveMQThreadFactory(final String groupName, final boolean daemon, final ClassLoader tccl)
- {
+ public ActiveMQThreadFactory(final String groupName, final boolean daemon, final ClassLoader tccl) {
group = new ThreadGroup(groupName + "-" + System.identityHashCode(this));
this.threadPriority = Thread.NORM_PRIORITY;
@@ -49,36 +48,30 @@ public final class ActiveMQThreadFactory implements ThreadFactory
this.acc = (System.getSecurityManager() == null) ? null : AccessController.getContext();
}
- public Thread newThread(final Runnable command)
- {
+ public Thread newThread(final Runnable command) {
// create a thread in a privileged block if running with Security Manager
- if (acc != null && System.getSecurityManager() != null)
- {
+ if (acc != null && System.getSecurityManager() != null) {
return AccessController.doPrivileged(new ThreadCreateAction(command), acc);
}
- else
- {
+ else {
return createThread(command);
}
}
- private final class ThreadCreateAction implements PrivilegedAction
- {
+ private final class ThreadCreateAction implements PrivilegedAction {
+
private final Runnable target;
- private ThreadCreateAction(final Runnable target)
- {
+ private ThreadCreateAction(final Runnable target) {
this.target = target;
}
- public Thread run()
- {
+ public Thread run() {
return createThread(target);
}
}
- private Thread createThread(final Runnable command)
- {
+ private Thread createThread(final Runnable command) {
final Thread t = new Thread(group, command, "Thread-" + threadCount.getAndIncrement() + " (" + group.getName() + ")");
t.setDaemon(daemon);
t.setPriority(threadPriority);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Base64.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Base64.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Base64.java
index 9d2481a..71dbcfb 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Base64.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/Base64.java
@@ -88,8 +88,7 @@ import java.nio.charset.StandardCharsets;
* periodically to check for updates or to contribute improvements.
*
*/
-public class Base64
-{
+public class Base64 {
/* ******** P U B L I C F I E L D S ******** */
@@ -169,203 +168,33 @@ public class Base64
*/
// private final static byte[] ALPHABET;
/* Host platform me be something funny like EBCDIC, so we hardcode these values. */
- private static final byte[] _STANDARD_ALPHABET = {(byte) 'A',
- (byte) 'B',
- (byte) 'C',
- (byte) 'D',
- (byte) 'E',
- (byte) 'F',
- (byte) 'G',
- (byte) 'H',
- (byte) 'I',
- (byte) 'J',
- (byte) 'K',
- (byte) 'L',
- (byte) 'M',
- (byte) 'N',
- (byte) 'O',
- (byte) 'P',
- (byte) 'Q',
- (byte) 'R',
- (byte) 'S',
- (byte) 'T',
- (byte) 'U',
- (byte) 'V',
- (byte) 'W',
- (byte) 'X',
- (byte) 'Y',
- (byte) 'Z',
- (byte) 'a',
- (byte) 'b',
- (byte) 'c',
- (byte) 'd',
- (byte) 'e',
- (byte) 'f',
- (byte) 'g',
- (byte) 'h',
- (byte) 'i',
- (byte) 'j',
- (byte) 'k',
- (byte) 'l',
- (byte) 'm',
- (byte) 'n',
- (byte) 'o',
- (byte) 'p',
- (byte) 'q',
- (byte) 'r',
- (byte) 's',
- (byte) 't',
- (byte) 'u',
- (byte) 'v',
- (byte) 'w',
- (byte) 'x',
- (byte) 'y',
- (byte) 'z',
- (byte) '0',
- (byte) '1',
- (byte) '2',
- (byte) '3',
- (byte) '4',
- (byte) '5',
- (byte) '6',
- (byte) '7',
- (byte) '8',
- (byte) '9',
- (byte) '+',
- (byte) '/'};
+ private static final byte[] _STANDARD_ALPHABET = {(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) '+', (byte) '/'};
/**
* Translates a Base64 value to either its 6-bit reconstruction value
* or a negative number indicating some other meaning.
*/
- private static final byte[] _STANDARD_DECODABET = {
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 0 - 8
- -5,
- -5, // Whitespace: Tab and Linefeed
- -9,
- -9, // Decimal 11 - 12
+ private static final byte[] _STANDARD_DECODABET = {-9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
-5, // Whitespace: Carriage Return
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 14 - 26
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 27 - 31
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
-5, // Whitespace: Space
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 33 - 42
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
62, // Plus sign at decimal 43
- -9,
- -9,
- -9, // Decimal 44 - 46
+ -9, -9, -9, // Decimal 44 - 46
63, // Slash at decimal 47
- 52,
- 53,
- 54,
- 55,
- 56,
- 57,
- 58,
- 59,
- 60,
- 61, // Numbers zero through nine
- -9,
- -9,
- -9, // Decimal 58 - 60
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
-1, // Equals sign at decimal 61
- -9,
- -9,
- -9, // Decimal 62 - 64
- 0,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 9,
- 10,
- 11,
- 12,
- 13, // Letters 'A' through 'N'
- 14,
- 15,
- 16,
- 17,
- 18,
- 19,
- 20,
- 21,
- 22,
- 23,
- 24,
- 25, // Letters 'O' through 'Z'
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 91 - 96
- 26,
- 27,
- 28,
- 29,
- 30,
- 31,
- 32,
- 33,
- 34,
- 35,
- 36,
- 37,
- 38, // Letters 'a' through 'm'
- 39,
- 40,
- 41,
- 42,
- 43,
- 44,
- 45,
- 46,
- 47,
- 48,
- 49,
- 50,
- 51, // Letters 'n' through 'z'
- -9,
- -9,
- -9,
- -9 // Decimal 123 - 126
+ -9, -9, -9, // Decimal 62 - 64
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
+ -9, -9, -9, -9, -9, -9, // Decimal 91 - 96
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm'
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z'
+ -9, -9, -9, -9 // Decimal 123 - 126
/*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
@@ -375,8 +204,7 @@ public class Base64
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */
- };
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */};
/* ******** U R L S A F E B A S E 6 4 A L P H A B E T ******** */
@@ -385,203 +213,36 @@ public class Base64
* http://www.faqs.org/rfcs/rfc3548.html.
* Notice that the last two bytes become "hyphen" and "underscore" instead of "plus" and "slash."
*/
- private static final byte[] _URL_SAFE_ALPHABET = {
- (byte) 'A',
- (byte) 'B',
- (byte) 'C',
- (byte) 'D',
- (byte) 'E',
- (byte) 'F',
- (byte) 'G',
- (byte) 'H',
- (byte) 'I',
- (byte) 'J',
- (byte) 'K',
- (byte) 'L',
- (byte) 'M',
- (byte) 'N',
- (byte) 'O',
- (byte) 'P',
- (byte) 'Q',
- (byte) 'R',
- (byte) 'S',
- (byte) 'T',
- (byte) 'U',
- (byte) 'V',
- (byte) 'W',
- (byte) 'X',
- (byte) 'Y',
- (byte) 'Z',
- (byte) 'a',
- (byte) 'b',
- (byte) 'c',
- (byte) 'd',
- (byte) 'e',
- (byte) 'f',
- (byte) 'g',
- (byte) 'h',
- (byte) 'i',
- (byte) 'j',
- (byte) 'k',
- (byte) 'l',
- (byte) 'm',
- (byte) 'n',
- (byte) 'o',
- (byte) 'p',
- (byte) 'q',
- (byte) 'r',
- (byte) 's',
- (byte) 't',
- (byte) 'u',
- (byte) 'v',
- (byte) 'w',
- (byte) 'x',
- (byte) 'y',
- (byte) 'z',
- (byte) '0',
- (byte) '1',
- (byte) '2',
- (byte) '3',
- (byte) '4',
- (byte) '5',
- (byte) '6',
- (byte) '7',
- (byte) '8',
- (byte) '9',
- (byte) '-',
- (byte) '_'};
+ private static final byte[] _URL_SAFE_ALPHABET = {(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) '-', (byte) '_'};
/**
* Used in decoding URL- and Filename-safe dialects of Base64.
*/
- private static final byte[] _URL_SAFE_DECODABET = {
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 0 - 8
- -5,
- -5, // Whitespace: Tab and Linefeed
- -9,
- -9, // Decimal 11 - 12
+ private static final byte[] _URL_SAFE_DECODABET = {-9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
-5, // Whitespace: Carriage Return
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 14 - 26
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 27 - 31
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
-5, // Whitespace: Space
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 33 - 42
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
-9, // Plus sign at decimal 43
-9, // Decimal 44
62, // Minus sign at decimal 45
-9, // Decimal 46
-9, // Slash at decimal 47
- 52,
- 53,
- 54,
- 55,
- 56,
- 57,
- 58,
- 59,
- 60,
- 61, // Numbers zero through nine
- -9,
- -9,
- -9, // Decimal 58 - 60
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
-1, // Equals sign at decimal 61
- -9,
- -9,
- -9, // Decimal 62 - 64
- 0,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 9,
- 10,
- 11,
- 12,
- 13, // Letters 'A' through 'N'
- 14,
- 15,
- 16,
- 17,
- 18,
- 19,
- 20,
- 21,
- 22,
- 23,
- 24,
- 25, // Letters 'O' through 'Z'
- -9,
- -9,
- -9,
- -9, // Decimal 91 - 94
+ -9, -9, -9, // Decimal 62 - 64
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
+ -9, -9, -9, -9, // Decimal 91 - 94
63, // Underscore at decimal 95
-9, // Decimal 96
- 26,
- 27,
- 28,
- 29,
- 30,
- 31,
- 32,
- 33,
- 34,
- 35,
- 36,
- 37,
- 38, // Letters 'a' through 'm'
- 39,
- 40,
- 41,
- 42,
- 43,
- 44,
- 45,
- 46,
- 47,
- 48,
- 49,
- 50,
- 51, // Letters 'n' through 'z'
- -9,
- -9,
- -9,
- -9 // Decimal 123 - 126
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm'
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z'
+ -9, -9, -9, -9 // Decimal 123 - 126
/*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
@@ -591,8 +252,7 @@ public class Base64
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */
- };
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */};
/* ******** O R D E R E D B A S E 6 4 A L P H A B E T ******** */
@@ -600,203 +260,36 @@ public class Base64
* I don't get the point of this technique, but it is described here:
* http://www.faqs.org/qa/rfcc-1940.html.
*/
- private static final byte[] _ORDERED_ALPHABET = {
- (byte) '-',
- (byte) '0',
- (byte) '1',
- (byte) '2',
- (byte) '3',
- (byte) '4',
- (byte) '5',
- (byte) '6',
- (byte) '7',
- (byte) '8',
- (byte) '9',
- (byte) 'A',
- (byte) 'B',
- (byte) 'C',
- (byte) 'D',
- (byte) 'E',
- (byte) 'F',
- (byte) 'G',
- (byte) 'H',
- (byte) 'I',
- (byte) 'J',
- (byte) 'K',
- (byte) 'L',
- (byte) 'M',
- (byte) 'N',
- (byte) 'O',
- (byte) 'P',
- (byte) 'Q',
- (byte) 'R',
- (byte) 'S',
- (byte) 'T',
- (byte) 'U',
- (byte) 'V',
- (byte) 'W',
- (byte) 'X',
- (byte) 'Y',
- (byte) 'Z',
- (byte) '_',
- (byte) 'a',
- (byte) 'b',
- (byte) 'c',
- (byte) 'd',
- (byte) 'e',
- (byte) 'f',
- (byte) 'g',
- (byte) 'h',
- (byte) 'i',
- (byte) 'j',
- (byte) 'k',
- (byte) 'l',
- (byte) 'm',
- (byte) 'n',
- (byte) 'o',
- (byte) 'p',
- (byte) 'q',
- (byte) 'r',
- (byte) 's',
- (byte) 't',
- (byte) 'u',
- (byte) 'v',
- (byte) 'w',
- (byte) 'x',
- (byte) 'y',
- (byte) 'z'};
+ private static final byte[] _ORDERED_ALPHABET = {(byte) '-', (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) '_', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z'};
/**
* Used in decoding the "ordered" dialect of Base64.
*/
- private static final byte[] _ORDERED_DECODABET = {
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 0 - 8
- -5,
- -5, // Whitespace: Tab and Linefeed
- -9,
- -9, // Decimal 11 - 12
+ private static final byte[] _ORDERED_DECODABET = {-9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
-5, // Whitespace: Carriage Return
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 14 - 26
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 27 - 31
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
-5, // Whitespace: Space
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9,
- -9, // Decimal 33 - 42
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
-9, // Plus sign at decimal 43
-9, // Decimal 44
0, // Minus sign at decimal 45
-9, // Decimal 46
-9, // Slash at decimal 47
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 9,
- 10, // Numbers zero through nine
- -9,
- -9,
- -9, // Decimal 58 - 60
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
-1, // Equals sign at decimal 61
- -9,
- -9,
- -9, // Decimal 62 - 64
- 11,
- 12,
- 13,
- 14,
- 15,
- 16,
- 17,
- 18,
- 19,
- 20,
- 21,
- 22,
- 23, // Letters 'A' through 'M'
- 24,
- 25,
- 26,
- 27,
- 28,
- 29,
- 30,
- 31,
- 32,
- 33,
- 34,
- 35,
- 36, // Letters 'N' through 'Z'
- -9,
- -9,
- -9,
- -9, // Decimal 91 - 94
+ -9, -9, -9, // Decimal 62 - 64
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, // Letters 'A' through 'M'
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, // Letters 'N' through 'Z'
+ -9, -9, -9, -9, // Decimal 91 - 94
37, // Underscore at decimal 95
-9, // Decimal 96
- 38,
- 39,
- 40,
- 41,
- 42,
- 43,
- 44,
- 45,
- 46,
- 47,
- 48,
- 49,
- 50, // Letters 'a' through 'm'
- 51,
- 52,
- 53,
- 54,
- 55,
- 56,
- 57,
- 58,
- 59,
- 60,
- 61,
- 62,
- 63, // Letters 'n' through 'z'
- -9,
- -9,
- -9,
- -9 // Decimal 123 - 126
+ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, // Letters 'a' through 'm'
+ 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, // Letters 'n' through 'z'
+ -9, -9, -9, -9 // Decimal 123 - 126
/*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
@@ -806,8 +299,7 @@ public class Base64
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
- -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */
- };
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */};
/* ******** D E T E R M I N E W H I C H A L H A B E T ******** */
@@ -818,18 +310,14 @@ public class Base64
* in which case one of them will be picked, though there is
* no guarantee as to which one will be picked.
*/
- private static byte[] getAlphabet(final int options)
- {
- if ((options & Base64.URL_SAFE) == Base64.URL_SAFE)
- {
+ private static byte[] getAlphabet(final int options) {
+ if ((options & Base64.URL_SAFE) == Base64.URL_SAFE) {
return Base64._URL_SAFE_ALPHABET;
}
- else if ((options & Base64.ORDERED) == Base64.ORDERED)
- {
+ else if ((options & Base64.ORDERED) == Base64.ORDERED) {
return Base64._ORDERED_ALPHABET;
}
- else
- {
+ else {
return Base64._STANDARD_ALPHABET;
}
@@ -842,18 +330,14 @@ public class Base64
* in which case one of them will be picked, though there is
* no guarantee as to which one will be picked.
*/
- private static byte[] getDecodabet(final int options)
- {
- if ((options & Base64.URL_SAFE) == Base64.URL_SAFE)
- {
+ private static byte[] getDecodabet(final int options) {
+ if ((options & Base64.URL_SAFE) == Base64.URL_SAFE) {
return Base64._URL_SAFE_DECODABET;
}
- else if ((options & Base64.ORDERED) == Base64.ORDERED)
- {
+ else if ((options & Base64.ORDERED) == Base64.ORDERED) {
return Base64._ORDERED_DECODABET;
}
- else
- {
+ else {
return Base64._STANDARD_DECODABET;
}
@@ -862,8 +346,7 @@ public class Base64
/**
* Defeats instantiation.
*/
- private Base64()
- {
+ private Base64() {
}
/**
@@ -873,27 +356,21 @@ public class Base64
*
* @param args Input args
*/
- public static final void main(final String[] args)
- {
- if (args.length < 3)
- {
+ public static final void main(final String[] args) {
+ if (args.length < 3) {
Base64.usage("Not enough arguments.");
} // end if: args.length < 3
- else
- {
+ else {
String flag = args[0];
String infile = args[1];
String outfile = args[2];
- if (flag.equals("-e"))
- {
+ if (flag.equals("-e")) {
Base64.encodeFileToFile(infile, outfile);
} // end if: encode
- else if (flag.equals("-d"))
- {
+ else if (flag.equals("-d")) {
Base64.decodeFileToFile(infile, outfile);
} // end else if: decode
- else
- {
+ else {
Base64.usage("Unknown flag: " + flag);
} // end else
} // end else
@@ -904,8 +381,7 @@ public class Base64
*
* @param msg A message to include with usage info.
*/
- private static void usage(final String msg)
- {
+ private static void usage(final String msg) {
System.err.println(msg);
System.err.println("Usage: java Base64 -e|-d inputfile outputfile");
} // end usage
@@ -927,8 +403,10 @@ public class Base64
* @return four byte array in Base64 notation.
* @since 1.5.1
*/
- private static byte[] encode3to4(final byte[] b4, final byte[] threeBytes, final int numSigBytes, final int options)
- {
+ private static byte[] encode3to4(final byte[] b4,
+ final byte[] threeBytes,
+ final int numSigBytes,
+ final int options) {
Base64.encode3to4(threeBytes, 0, numSigBytes, b4, 0, options);
return b4;
} // end encode3to4
@@ -961,8 +439,7 @@ public class Base64
final int numSigBytes,
final byte[] destination,
final int destOffset,
- final int options)
- {
+ final int options) {
byte[] ALPHABET = Base64.getAlphabet(options);
// 1 2 3
@@ -976,12 +453,10 @@ public class Base64
// significant bytes passed in the array.
// We have to shift left 24 in order to flush out the 1's that appear
// when Java treats a value as negative that is cast from a byte to an int.
- int inBuff = (numSigBytes > 0 ? source[srcOffset] << 24 >>> 8 : 0) | (numSigBytes > 1 ? source[srcOffset + 1] << 24 >>> 16
- : 0) |
+ int inBuff = (numSigBytes > 0 ? source[srcOffset] << 24 >>> 8 : 0) | (numSigBytes > 1 ? source[srcOffset + 1] << 24 >>> 16 : 0) |
(numSigBytes > 2 ? source[srcOffset + 2] << 24 >>> 24 : 0);
- switch (numSigBytes)
- {
+ switch (numSigBytes) {
case 3:
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
destination[destOffset + 1] = ALPHABET[inBuff >>> 12 & 0x3f];
@@ -1019,8 +494,7 @@ public class Base64
* @return The Base64-encoded object
* @since 1.4
*/
- public static String encodeObject(final java.io.Serializable serializableObject)
- {
+ public static String encodeObject(final java.io.Serializable serializableObject) {
return Base64.encodeObject(serializableObject, Base64.NO_OPTIONS);
} // end encodeObject
@@ -1047,8 +521,7 @@ public class Base64
* @see Base64#DONT_BREAK_LINES
* @since 2.0
*/
- public static String encodeObject(final java.io.Serializable serializableObject, final int options)
- {
+ public static String encodeObject(final java.io.Serializable serializableObject, final int options) {
// Streams
java.io.ByteArrayOutputStream baos = null;
java.io.OutputStream b64os = null;
@@ -1058,59 +531,46 @@ public class Base64
// Isolate options
int gzip = options & Base64.GZIP;
- try
- {
+ try {
// ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
baos = new java.io.ByteArrayOutputStream();
b64os = new Base64.OutputStream(baos, Base64.ENCODE | options);
// GZip?
- if (gzip == Base64.GZIP)
- {
+ if (gzip == Base64.GZIP) {
gzos = new java.util.zip.GZIPOutputStream(b64os);
oos = new java.io.ObjectOutputStream(gzos);
} // end if: gzip
- else
- {
+ else {
oos = new java.io.ObjectOutputStream(b64os);
}
oos.writeObject(serializableObject);
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
e.printStackTrace();
return null;
} // end catch
- finally
- {
- try
- {
+ finally {
+ try {
oos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
gzos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
b64os.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
baos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1127,8 +587,7 @@ public class Base64
* @return Base64 String
* @since 1.4
*/
- public static String encodeBytes(final byte[] source)
- {
+ public static String encodeBytes(final byte[] source) {
return Base64.encodeBytes(source, 0, source.length, Base64.NO_OPTIONS);
} // end encodeBytes
@@ -1152,8 +611,7 @@ public class Base64
* @see Base64#DONT_BREAK_LINES
* @since 2.0
*/
- public static String encodeBytes(final byte[] source, final int options)
- {
+ public static String encodeBytes(final byte[] source, final int options) {
return Base64.encodeBytes(source, 0, source.length, options);
} // end encodeBytes
@@ -1167,8 +625,7 @@ public class Base64
* @return Encoded String
* @since 1.4
*/
- public static String encodeBytes(final byte[] source, final int off, final int len)
- {
+ public static String encodeBytes(final byte[] source, final int off, final int len) {
return Base64.encodeBytes(source, off, len, Base64.NO_OPTIONS);
} // end encodeBytes
@@ -1194,21 +651,18 @@ public class Base64
* @see Base64#DONT_BREAK_LINES
* @since 2.0
*/
- public static String encodeBytes(final byte[] source, final int off, final int len, final int options)
- {
+ public static String encodeBytes(final byte[] source, final int off, final int len, final int options) {
// Isolate options
int dontBreakLines = options & Base64.DONT_BREAK_LINES;
int gzip = options & Base64.GZIP;
// Compress?
- if (gzip == Base64.GZIP)
- {
+ if (gzip == Base64.GZIP) {
java.io.ByteArrayOutputStream baos = null;
java.util.zip.GZIPOutputStream gzos = null;
Base64.OutputStream b64os = null;
- try
- {
+ try {
// GZip -> Base64 -> ByteArray
baos = new java.io.ByteArrayOutputStream();
b64os = new Base64.OutputStream(baos, Base64.ENCODE | options);
@@ -1217,33 +671,25 @@ public class Base64
gzos.write(source, off, len);
gzos.close();
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
e.printStackTrace();
return null;
} // end catch
- finally
- {
- try
- {
+ finally {
+ try {
gzos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
b64os.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
baos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1252,8 +698,7 @@ public class Base64
} // end if: compress
// Else, don't compress. Better not to use streams at all then.
- else
- {
+ else {
// Convert option to boolean in way that code likes it.
boolean breakLines = dontBreakLines == 0;
@@ -1265,21 +710,18 @@ public class Base64
int e = 0;
int len2 = len - 2;
int lineLength = 0;
- for (; d < len2; d += 3, e += 4)
- {
+ for (; d < len2; d += 3, e += 4) {
Base64.encode3to4(source, d + off, 3, outBuff, e, options);
lineLength += 4;
- if (breakLines && lineLength == Base64.MAX_LINE_LENGTH)
- {
+ if (breakLines && lineLength == Base64.MAX_LINE_LENGTH) {
outBuff[e + 4] = Base64.NEW_LINE;
e++;
lineLength = 0;
} // end if: end of line
} // en dfor: each piece of array
- if (d < len)
- {
+ if (d < len) {
Base64.encode3to4(source, d + off, len - d, outBuff, e, options);
e += 4;
} // end if: some padding needed
@@ -1321,13 +763,11 @@ public class Base64
final int srcOffset,
final byte[] destination,
final int destOffset,
- final int options)
- {
+ final int options) {
byte[] DECODABET = Base64.getDecodabet(options);
// Example: Dk==
- if (source[srcOffset + 2] == Base64.EQUALS_SIGN)
- {
+ if (source[srcOffset + 2] == Base64.EQUALS_SIGN) {
// Two ways to do the same thing. Don't know which way I like best.
// int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
// | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 );
@@ -1338,8 +778,7 @@ public class Base64
}
// Example: DkL=
- else if (source[srcOffset + 3] == Base64.EQUALS_SIGN)
- {
+ else if (source[srcOffset + 3] == Base64.EQUALS_SIGN) {
// Two ways to do the same thing. Don't know which way I like best.
// int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
// | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
@@ -1353,10 +792,8 @@ public class Base64
}
// Example: DkLE
- else
- {
- try
- {
+ else {
+ try {
// Two ways to do the same thing. Don't know which way I like best.
// int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
// | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
@@ -1364,8 +801,7 @@ public class Base64
// | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 );
int outBuff = (DECODABET[source[srcOffset]] & 0xFF) << 18 | (DECODABET[source[srcOffset + 1]] & 0xFF) << 12 |
(DECODABET[source[srcOffset + 2]] & 0xFF) << 6 |
- DECODABET[source[srcOffset + 3]] &
- 0xFF;
+ DECODABET[source[srcOffset + 3]] & 0xFF;
destination[destOffset] = (byte) (outBuff >> 16);
destination[destOffset + 1] = (byte) (outBuff >> 8);
@@ -1373,8 +809,7 @@ public class Base64
return 3;
}
- catch (Exception e)
- {
+ catch (Exception e) {
System.out.println("" + source[srcOffset] + ": " + DECODABET[source[srcOffset]]);
System.out.println("" + source[srcOffset + 1] + ": " + DECODABET[source[srcOffset + 1]]);
System.out.println("" + source[srcOffset + 2] + ": " + DECODABET[source[srcOffset + 2]]);
@@ -1389,15 +824,14 @@ public class Base64
* the form of a byte array. Does not support automatically
* gunzipping or any other "fancy" features.
*
- * @param source The Base64 encoded data
- * @param off The offset of where to begin decoding
- * @param len The length of characters to decode
+ * @param source The Base64 encoded data
+ * @param off The offset of where to begin decoding
+ * @param len The length of characters to decode
* @param options Specified options
* @return decoded data
* @since 1.3
*/
- public static byte[] decode(final byte[] source, final int off, final int len, final int options)
- {
+ public static byte[] decode(final byte[] source, final int off, final int len, final int options) {
byte[] DECODABET = Base64.getDecodabet(options);
int len34 = len * 3 / 4;
@@ -1409,24 +843,20 @@ public class Base64
int i = 0;
byte sbiCrop = 0;
byte sbiDecode = 0;
- for (i = off; i < off + len; i++)
- {
+ for (i = off; i < off + len; i++) {
sbiCrop = (byte) (source[i] & 0x7f); // Only the low seven bits
sbiDecode = DECODABET[sbiCrop];
if (sbiDecode >= Base64.WHITE_SPACE_ENC) // White space, Equals sign or better
{
- if (sbiDecode >= Base64.EQUALS_SIGN_ENC)
- {
+ if (sbiDecode >= Base64.EQUALS_SIGN_ENC) {
b4[b4Posn++] = sbiCrop;
- if (b4Posn > 3)
- {
+ if (b4Posn > 3) {
outBuffPosn += Base64.decode4to3(b4, 0, outBuff, outBuffPosn, options);
b4Posn = 0;
// If that was the equals sign, break out of 'for' loop
- if (sbiCrop == Base64.EQUALS_SIGN)
- {
+ if (sbiCrop == Base64.EQUALS_SIGN) {
break;
}
} // end if: quartet built
@@ -1434,8 +864,7 @@ public class Base64
} // end if: equals sign or better
} // end if: white space, equals sign or better
- else
- {
+ else {
System.err.println("Bad Base64 input character at " + i + ": " + source[i] + "(decimal)");
return null;
} // end else:
@@ -1454,8 +883,7 @@ public class Base64
* @return the decoded data
* @since 1.4
*/
- public static byte[] decode(final String s)
- {
+ public static byte[] decode(final String s) {
return Base64.decode(s, Base64.NO_OPTIONS);
}
@@ -1468,8 +896,7 @@ public class Base64
* @return the decoded data
* @since 1.4
*/
- public static byte[] decode(final String s, final int options)
- {
+ public static byte[] decode(final String s, final int options) {
byte[] bytes = s.getBytes(Base64.PREFERRED_ENCODING);
//
@@ -1478,26 +905,22 @@ public class Base64
// Check to see if it's gzip-compressed
// GZIP Magic Two-Byte Number: 0x8b1f (35615)
- if (bytes != null && bytes.length >= 4)
- {
+ if (bytes != null && bytes.length >= 4) {
int head = bytes[0] & 0xff | bytes[1] << 8 & 0xff00;
- if (java.util.zip.GZIPInputStream.GZIP_MAGIC == head)
- {
+ if (java.util.zip.GZIPInputStream.GZIP_MAGIC == head) {
java.io.ByteArrayInputStream bais = null;
java.util.zip.GZIPInputStream gzis = null;
java.io.ByteArrayOutputStream baos = null;
byte[] buffer = new byte[2048];
int length = 0;
- try
- {
+ try {
baos = new java.io.ByteArrayOutputStream();
bais = new java.io.ByteArrayInputStream(bytes);
gzis = new java.util.zip.GZIPInputStream(bais);
- while ((length = gzis.read(buffer)) >= 0)
- {
+ while ((length = gzis.read(buffer)) >= 0) {
baos.write(buffer, 0, length);
} // end while: reading input
@@ -1505,32 +928,24 @@ public class Base64
bytes = baos.toByteArray();
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
// Just return originally-decoded bytes
} // end catch
- finally
- {
- try
- {
+ finally {
+ try {
baos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
gzis.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
bais.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1548,8 +963,7 @@ public class Base64
* @return The decoded and deserialized object
* @since 1.5
*/
- public static Object decodeToObject(final String encodedObject)
- {
+ public static Object decodeToObject(final String encodedObject) {
// Decode and gunzip if necessary
byte[] objBytes = Base64.decode(encodedObject);
@@ -1557,38 +971,30 @@ public class Base64
java.io.ObjectInputStream ois = null;
Object obj = null;
- try
- {
+ try {
bais = new java.io.ByteArrayInputStream(objBytes);
ois = new java.io.ObjectInputStream(bais);
obj = ois.readObject();
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
e.printStackTrace();
obj = null;
} // end catch
- catch (java.lang.ClassNotFoundException e)
- {
+ catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
obj = null;
} // end catch
- finally
- {
- try
- {
+ finally {
+ try {
bais.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
- try
- {
+ try {
ois.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1603,29 +1009,23 @@ public class Base64
* @return true if successful, false otherwise
* @since 2.1
*/
- public static boolean encodeToFile(final byte[] dataToEncode, final String filename)
- {
+ public static boolean encodeToFile(final byte[] dataToEncode, final String filename) {
boolean success = false;
Base64.OutputStream bos = null;
- try
- {
+ try {
bos = new Base64.OutputStream(new java.io.FileOutputStream(filename), Base64.ENCODE);
bos.write(dataToEncode);
success = true;
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
success = false;
} // end catch: IOException
- finally
- {
- try
- {
+ finally {
+ try {
bos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1640,28 +1040,22 @@ public class Base64
* @return true if successful, false otherwise
* @since 2.1
*/
- public static boolean decodeToFile(final String dataToDecode, final String filename)
- {
+ public static boolean decodeToFile(final String dataToDecode, final String filename) {
boolean success = false;
Base64.OutputStream bos = null;
- try
- {
+ try {
bos = new Base64.OutputStream(new java.io.FileOutputStream(filename), Base64.DECODE);
bos.write(dataToDecode.getBytes(Base64.PREFERRED_ENCODING));
success = true;
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
success = false;
} // end catch: IOException
- finally
- {
- try
- {
+ finally {
+ try {
bos.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1676,12 +1070,10 @@ public class Base64
* @return decoded byte array or null if unsuccessful
* @since 2.1
*/
- public static byte[] decodeFromFile(final String filename)
- {
+ public static byte[] decodeFromFile(final String filename) {
byte[] decodedData = null;
Base64.InputStream bis = null;
- try
- {
+ try {
// Set up some useful variables
java.io.File file = new java.io.File(filename);
byte[] buffer = null;
@@ -1689,8 +1081,7 @@ public class Base64
int numBytes = 0;
// Check for size of file
- if (file.length() > Integer.MAX_VALUE)
- {
+ if (file.length() > Integer.MAX_VALUE) {
System.err.println("File is too big for this convenience method (" + file.length() + " bytes).");
return null;
} // end if: file too big for int index
@@ -1700,8 +1091,7 @@ public class Base64
bis = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), Base64.DECODE);
// Read until done
- while ((numBytes = bis.read(buffer, length, 4096)) >= 0)
- {
+ while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
length += numBytes;
}
@@ -1710,21 +1100,16 @@ public class Base64
System.arraycopy(buffer, 0, decodedData, 0, length);
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
System.err.println("Error decoding from file " + filename);
} // end catch: IOException
- finally
- {
- try
- {
- if (bis != null)
- {
+ finally {
+ try {
+ if (bis != null) {
bis.close();
}
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1739,12 +1124,10 @@ public class Base64
* @return base64-encoded string or null if unsuccessful
* @since 2.1
*/
- public static String encodeFromFile(final String filename)
- {
+ public static String encodeFromFile(final String filename) {
String encodedData = null;
Base64.InputStream bis = null;
- try
- {
+ try {
// Set up some useful variables
java.io.File file = new java.io.File(filename);
byte[] buffer = new byte[Math.max((int) (file.length() * 1.4), 40)]; // Need max() for math on small files
@@ -1756,8 +1139,7 @@ public class Base64
bis = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), Base64.ENCODE);
// Read until done
- while ((numBytes = bis.read(buffer, length, 4096)) >= 0)
- {
+ while ((numBytes = bis.read(buffer, length, 4096)) >= 0) {
length += numBytes;
}
@@ -1765,18 +1147,14 @@ public class Base64
encodedData = new String(buffer, 0, length, Base64.PREFERRED_ENCODING);
} // end try
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
System.err.println("Error encoding from file " + filename);
} // end catch: IOException
- finally
- {
- try
- {
+ finally {
+ try {
bis.close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
}
} // end finally
@@ -1791,43 +1169,33 @@ public class Base64
* @return true if the operation is successful
* @since 2.2
*/
- public static boolean encodeFileToFile(final String infile, final String outfile)
- {
+ public static boolean encodeFileToFile(final String infile, final String outfile) {
boolean success = false;
java.io.InputStream in = null;
java.io.OutputStream out = null;
- try
- {
- in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)),
- Base64.ENCODE);
+ try {
+ in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
byte[] buffer = new byte[65536]; // 64K
int read = -1;
- while ((read = in.read(buffer)) >= 0)
- {
+ while ((read = in.read(buffer)) >= 0) {
out.write(buffer, 0, read);
} // end while: through file
success = true;
}
- catch (java.io.IOException exc)
- {
+ catch (java.io.IOException exc) {
exc.printStackTrace();
}
- finally
- {
- try
- {
+ finally {
+ try {
in.close();
}
- catch (Exception exc)
- {
+ catch (Exception exc) {
}
- try
- {
+ try {
out.close();
}
- catch (Exception exc)
- {
+ catch (Exception exc) {
}
} // end finally
@@ -1842,43 +1210,33 @@ public class Base64
* @return true if the operation is successful
* @since 2.2
*/
- public static boolean decodeFileToFile(final String infile, final String outfile)
- {
+ public static boolean decodeFileToFile(final String infile, final String outfile) {
boolean success = false;
java.io.InputStream in = null;
java.io.OutputStream out = null;
- try
- {
- in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)),
- Base64.DECODE);
+ try {
+ in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
byte[] buffer = new byte[65536]; // 64K
int read = -1;
- while ((read = in.read(buffer)) >= 0)
- {
+ while ((read = in.read(buffer)) >= 0) {
out.write(buffer, 0, read);
} // end while: through file
success = true;
}
- catch (java.io.IOException exc)
- {
+ catch (java.io.IOException exc) {
exc.printStackTrace();
}
- finally
- {
- try
- {
+ finally {
+ try {
in.close();
}
- catch (Exception exc)
- {
+ catch (Exception exc) {
}
- try
- {
+ try {
out.close();
}
- catch (Exception exc)
- {
+ catch (Exception exc) {
}
} // end finally
@@ -1895,8 +1253,8 @@ public class Base64
* @see Base64
* @since 1.3
*/
- public static class InputStream extends java.io.FilterInputStream
- {
+ public static class InputStream extends java.io.FilterInputStream {
+
private final boolean encode; // Encoding or decoding
private int position; // Current position in the buffer
@@ -1923,8 +1281,7 @@ public class Base64
* @param in the java.io.InputStream from which to read data.
* @since 1.3
*/
- public InputStream(final java.io.InputStream in)
- {
+ public InputStream(final java.io.InputStream in) {
this(in, Base64.DECODE);
} // end constructor
@@ -1948,8 +1305,7 @@ public class Base64
* @see Base64#DONT_BREAK_LINES
* @since 2.0
*/
- public InputStream(final java.io.InputStream in, final int options)
- {
+ public InputStream(final java.io.InputStream in, final int options) {
super(in);
breakLines = (options & Base64.DONT_BREAK_LINES) != Base64.DONT_BREAK_LINES;
encode = (options & Base64.ENCODE) == Base64.ENCODE;
@@ -1970,86 +1326,68 @@ public class Base64
* @since 1.3
*/
@Override
- public int read() throws java.io.IOException
- {
+ public int read() throws java.io.IOException {
// Do we need to get data?
- if (position < 0)
- {
- if (encode)
- {
+ if (position < 0) {
+ if (encode) {
byte[] b3 = new byte[3];
int numBinaryBytes = 0;
- for (int i = 0; i < 3; i++)
- {
- try
- {
+ for (int i = 0; i < 3; i++) {
+ try {
int b = in.read();
// If end of stream, b is -1.
- if (b >= 0)
- {
+ if (b >= 0) {
b3[i] = (byte) b;
numBinaryBytes++;
} // end if: not end of stream
} // end try: read
- catch (java.io.IOException e)
- {
+ catch (java.io.IOException e) {
// Only a problem if we got no data at all.
- if (i == 0)
- {
+ if (i == 0) {
throw e;
}
} // end catch
} // end for: each needed input byte
- if (numBinaryBytes > 0)
- {
+ if (numBinaryBytes > 0) {
Base64.encode3to4(b3, 0, numBinaryBytes, buffer, 0, options);
position = 0;
numSigBytes = 4;
} // end if: got data
- else
- {
+ else {
return -1;
}
} // end if: encoding
// Else decoding
- else
- {
+ else {
byte[] b4 = new byte[4];
int i = 0;
- for (i = 0; i < 4; i++)
- {
+ for (i = 0; i < 4; i++) {
// Read four "meaningful" bytes:
int b = 0;
- do
- {
+ do {
b = in.read();
- }
- while (b >= 0 && decodabet[b & 0x7f] <= Base64.WHITE_SPACE_ENC);
+ } while (b >= 0 && decodabet[b & 0x7f] <= Base64.WHITE_SPACE_ENC);
- if (b < 0)
- {
+ if (b < 0) {
break; // Reads a -1 if end of stream
}
b4[i] = (byte) b;
} // end for: each needed input byte
- if (i == 4)
- {
+ if (i == 4) {
numSigBytes = Base64.decode4to3(b4, 0, buffer, 0, options);
position = 0;
} // end if: got four characters
- else if (i == 0)
- {
+ else if (i == 0) {
return -1;
}
- else
- {
+ else {
// Must have broken out from above.
throw new java.io.IOException("Improperly padded Base64 input.");
}
@@ -2058,29 +1396,24 @@ public class Base64
} // end else: get data
// Got data?
- if (position >= 0)
- {
+ if (position >= 0) {
// End of relevant data?
- if ( /*!encode &&*/position >= numSigBytes)
- {
+ if ( /*!encode &&*/position >= numSigBytes) {
return -1;
}
- if (encode && breakLines && lineLength >= Base64.MAX_LINE_LENGTH)
- {
+ if (encode && breakLines && lineLength >= Base64.MAX_LINE_LENGTH) {
lineLength = 0;
return '\n';
} // end if
- else
- {
+ else {
lineLength++; // This isn't important when decoding
// but throwing an extra "if" seems
// just as wasteful.
int b = buffer[position++];
- if (position >= bufferLength)
- {
+ if (position >= bufferLength) {
position = -1;
}
@@ -2088,8 +1421,7 @@ public class Base64
// intended to be unsigned.
} // end else
} // end if: position >= 0
- else
- {
+ else {
// When JDK1.4 is more accepted, use an assertion here.
throw new java.io.IOException("Error in Base64 code reading stream.");
}
@@ -2108,27 +1440,22 @@ public class Base64
* @since 1.3
*/
@Override
- public int read(final byte[] dest, final int off, final int len) throws java.io.IOException
- {
+ public int read(final byte[] dest, final int off, final int len) throws java.io.IOException {
int i;
int b;
- for (i = 0; i < len; i++)
- {
+ for (i = 0; i < len; i++) {
b = read();
// if( b < 0 && i == 0 )
// return -1;
- if (b >= 0)
- {
+ if (b >= 0) {
dest[off + i] = (byte) b;
}
- else if (i == 0)
- {
+ else if (i == 0) {
return -1;
}
- else
- {
+ else {
break; // Out of 'for' loop
}
} // end for: each byte read
@@ -2147,8 +1474,8 @@ public class Base64
* @see Base64
* @since 1.3
*/
- public static class OutputStream extends java.io.FilterOutputStream
- {
+ public static class OutputStream extends java.io.FilterOutputStream {
+
private final boolean encode;
private int position;
@@ -2177,8 +1504,7 @@ public class Base64
* @param out the java.io.OutputStream to which data will be written.
* @since 1.3
*/
- public OutputStream(final java.io.OutputStream out)
- {
+ public OutputStream(final java.io.OutputStream out) {
this(out, Base64.ENCODE);
} // end constructor
@@ -2202,8 +1528,7 @@ public class Base64
* @see Base64#DONT_BREAK_LINES
* @since 1.3
*/
- public OutputStream(final java.io.OutputStream out, final int options)
- {
+ public OutputStream(final java.io.OutputStream out, final int options) {
super(out);
breakLines = (options & Base64.DONT_BREAK_LINES) != Base64.DONT_BREAK_LINES;
encode = (options & Base64.ENCODE) == Base64.ENCODE;
@@ -2232,26 +1557,22 @@ public class Base64
* @since 1.3
*/
@Override
- public void write(final int theByte) throws java.io.IOException
- {
+ public void write(final int theByte) throws java.io.IOException {
// Encoding suspended?
- if (suspendEncoding)
- {
+ if (suspendEncoding) {
super.out.write(theByte);
return;
} // end if: supsended
// Encode?
- if (encode)
- {
+ if (encode) {
buffer[position++] = (byte) theByte;
if (position >= bufferLength) // Enough to encode.
{
out.write(Base64.encode3to4(b4, buffer, bufferLength, options));
lineLength += 4;
- if (breakLines && lineLength >= Base64.MAX_LINE_LENGTH)
- {
+ if (breakLines && lineLength >= Base64.MAX_LINE_LENGTH) {
out.write(Base64.NEW_LINE);
lineLength = 0;
} // end if: end of line
@@ -2261,11 +1582,9 @@ public class Base64
} // end if: encoding
// Else, Decoding
- else
- {
+ else {
// Meaningful Base64 character?
- if (decodabet[theByte & 0x7f] > Base64.WHITE_SPACE_ENC)
- {
+ if (decodabet[theByte & 0x7f] > Base64.WHITE_SPACE_ENC) {
buffer[position++] = (byte) theByte;
if (position >= bufferLength) // Enough to output.
{
@@ -2275,8 +1594,7 @@ public class Base64
position = 0;
} // end if: enough to output
} // end if: meaningful base64 character
- else if (decodabet[theByte & 0x7f] != Base64.WHITE_SPACE_ENC)
- {
+ else if (decodabet[theByte & 0x7f] != Base64.WHITE_SPACE_ENC) {
throw new java.io.IOException("Invalid character in Base64 data.");
}
} // end else: decoding
@@ -2289,21 +1607,18 @@ public class Base64
* @param theBytes array from which to read bytes
* @param off offset for array
* @param len max number of bytes to read into array
- * @since 1.3
* @throws java.io.IOException Throws IOException
+ * @since 1.3
*/
@Override
- public void write(final byte[] theBytes, final int off, final int len) throws java.io.IOException
- {
+ public void write(final byte[] theBytes, final int off, final int len) throws java.io.IOException {
// Encoding suspended?
- if (suspendEncoding)
- {
+ if (suspendEncoding) {
super.out.write(theBytes, off, len);
return;
} // end if: supsended
- for (int i = 0; i < len; i++)
- {
+ for (int i = 0; i < len; i++) {
write(theBytes[off + i]);
} // end for: each byte written
@@ -2312,19 +1627,16 @@ public class Base64
/**
* Method added by PHIL. [Thanks, PHIL. -Rob]
* This pads the buffer without closing the stream.
+ *
* @throws java.io.IOException On IO Exception
*/
- public void flushBase64() throws java.io.IOException
- {
- if (position > 0)
- {
- if (encode)
- {
+ public void flushBase64() throws java.io.IOException {
+ if (position > 0) {
+ if (encode) {
out.write(Base64.encode3to4(b4, buffer, position, options));
position = 0;
} // end if: encoding
- else
- {
+ else {
throw new java.io.IOException("Base64 input not properly padded.");
}
} // end if: buffer partially full
@@ -2336,11 +1648,9 @@ public class Base64
*
* @throws java.io.IOException Throws IOException
* @since 1.3
- *
*/
@Override
- public void close() throws java.io.IOException
- {
+ public void close() throws java.io.IOException {
// 1. Ensure that pending characters are written
flushBase64();
@@ -2356,11 +1666,11 @@ public class Base64
* Suspends encoding of the stream.
* May be helpful if you need to embed a piece of
* base640-encoded data in a stream.
+ *
* @throws java.io.IOException On IO Exception
* @since 1.5.1
*/
- public void suspendEncoding() throws java.io.IOException
- {
+ public void suspendEncoding() throws java.io.IOException {
flushBase64();
suspendEncoding = true;
} // end suspendEncoding
@@ -2372,8 +1682,7 @@ public class Base64
*
* @since 1.5.1
*/
- public void resumeEncoding()
- {
+ public void resumeEncoding() {
suspendEncoding = false;
} // end resumeEncoding
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
index f2b4e4f..6e2ca99 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
@@ -19,36 +19,28 @@ package org.apache.activemq.artemis.utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
-public class ByteUtil
-{
+public class ByteUtil {
private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
- public static String maxString(String value, int size)
- {
- if (value.length() < size)
- {
+ public static String maxString(String value, int size) {
+ if (value.length() < size) {
return value;
}
- else
- {
+ else {
return value.substring(0, size / 2) + " ... " + value.substring(value.length() - size / 2);
}
}
- public static String bytesToHex(byte[] bytes, int groupSize)
- {
- if (bytes == null)
- {
+
+ public static String bytesToHex(byte[] bytes, int groupSize) {
+ if (bytes == null) {
return "null";
}
- else
- {
+ else {
char[] hexChars = new char[bytes.length * 2 + numberOfGroups(bytes, groupSize)];
int outPos = 0;
- for (int j = 0; j < bytes.length; j++)
- {
- if (j > 0 && j % groupSize == 0)
- {
+ for (int j = 0; j < bytes.length; j++) {
+ if (j > 0 && j % groupSize == 0) {
hexChars[outPos++] = ' ';
}
int v = bytes[j] & 0xFF;
@@ -59,20 +51,17 @@ public class ByteUtil
}
}
- private static int numberOfGroups(byte[] bytes, int groupSize)
- {
+ private static int numberOfGroups(byte[] bytes, int groupSize) {
int groups = bytes.length / groupSize;
- if (bytes.length % groupSize == 0)
- {
+ if (bytes.length % groupSize == 0) {
groups--;
}
return groups;
}
- public static byte[] longToBytes(long x)
- {
+ public static byte[] longToBytes(long x) {
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.heapBuffer(8, 8);
buffer.writeLong(x);
return buffer.array();
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ClassloadingUtil.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ClassloadingUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ClassloadingUtil.java
index 098bc56..707635e 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ClassloadingUtil.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ClassloadingUtil.java
@@ -25,101 +25,80 @@ import java.net.URL;
* Is't required to use a Security Block on any calls to this class.
*/
-public final class ClassloadingUtil
-{
- private static final String INSTANTIATION_EXCEPTION_MESSAGE =
- "Your class must have a constructor without arguments. If it is an inner class, it must be static!";
+public final class ClassloadingUtil {
- public static Object newInstanceFromClassLoader(final String className)
- {
+ private static final String INSTANTIATION_EXCEPTION_MESSAGE = "Your class must have a constructor without arguments. If it is an inner class, it must be static!";
+
+ public static Object newInstanceFromClassLoader(final String className) {
ClassLoader loader = ClassloadingUtil.class.getClassLoader();
- try
- {
+ try {
Class> clazz = loader.loadClass(className);
return clazz.newInstance();
}
- catch (Throwable t)
- {
- if (t instanceof InstantiationException)
- {
+ catch (Throwable t) {
+ if (t instanceof InstantiationException) {
System.out.println(INSTANTIATION_EXCEPTION_MESSAGE);
}
loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
throw new RuntimeException("No local context classloader", t);
- try
- {
+ try {
return loader.loadClass(className).newInstance();
}
- catch (InstantiationException e)
- {
+ catch (InstantiationException e) {
throw new RuntimeException(INSTANTIATION_EXCEPTION_MESSAGE + " " + className, e);
}
- catch (ClassNotFoundException e)
- {
+ catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
- catch (IllegalAccessException e)
- {
+ catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
- public static Object newInstanceFromClassLoader(final String className, Object... objs)
- {
+ public static Object newInstanceFromClassLoader(final String className, Object... objs) {
ClassLoader loader = ClassloadingUtil.class.getClassLoader();
- try
- {
+ try {
Class>[] parametersType = new Class>[objs.length];
- for (int i = 0; i < objs.length; i++)
- {
+ for (int i = 0; i < objs.length; i++) {
parametersType[i] = objs[i].getClass();
}
Class> clazz = loader.loadClass(className);
return clazz.getConstructor(parametersType).newInstance(objs);
}
- catch (Throwable t)
- {
- if (t instanceof InstantiationException)
- {
+ catch (Throwable t) {
+ if (t instanceof InstantiationException) {
System.out.println(INSTANTIATION_EXCEPTION_MESSAGE);
}
loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
throw new RuntimeException("No local context classloader", t);
- try
- {
+ try {
return loader.loadClass(className).newInstance();
}
- catch (InstantiationException e)
- {
+ catch (InstantiationException e) {
throw new RuntimeException(INSTANTIATION_EXCEPTION_MESSAGE + " " + className, e);
}
- catch (ClassNotFoundException e)
- {
+ catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
- catch (IllegalAccessException e)
- {
+ catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
- public static URL findResource(final String resourceName)
- {
+ public static URL findResource(final String resourceName) {
ClassLoader loader = ClassloadingUtil.class.getClassLoader();
- try
- {
+ try {
URL resource = loader.getResource(resourceName);
if (resource != null)
return resource;
}
- catch (Throwable t)
- {
+ catch (Throwable t) {
}
loader = Thread.currentThread().getContextClassLoader();
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentHashSet.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentHashSet.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentHashSet.java
index e39b36e..c0fe578 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentHashSet.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentHashSet.java
@@ -22,67 +22,56 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
- *
* A ConcurrentHashSet.
*
* Offers same concurrency as ConcurrentHashMap but for a Set
- *
*/
-public class ConcurrentHashSet extends AbstractSet implements ConcurrentSet
-{
+public class ConcurrentHashSet extends AbstractSet implements ConcurrentSet {
+
private final ConcurrentMap theMap;
private static final Object dummy = new Object();
- public ConcurrentHashSet()
- {
+ public ConcurrentHashSet() {
theMap = new ConcurrentHashMap();
}
@Override
- public int size()
- {
+ public int size() {
return theMap.size();
}
@Override
- public Iterator iterator()
- {
+ public Iterator iterator() {
return theMap.keySet().iterator();
}
@Override
- public boolean isEmpty()
- {
+ public boolean isEmpty() {
return theMap.isEmpty();
}
@Override
- public boolean add(final E o)
- {
+ public boolean add(final E o) {
return theMap.put(o, ConcurrentHashSet.dummy) == null;
}
@Override
- public boolean contains(final Object o)
- {
+ public boolean contains(final Object o) {
return theMap.containsKey(o);
}
@Override
- public void clear()
- {
+ public void clear() {
theMap.clear();
}
@Override
- public boolean remove(final Object o)
- {
+ public boolean remove(final Object o) {
return theMap.remove(o) == ConcurrentHashSet.dummy;
}
- public boolean addIfAbsent(final E o)
- {
+ public boolean addIfAbsent(final E o) {
Object obj = theMap.putIfAbsent(o, ConcurrentHashSet.dummy);
return obj == null;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentSet.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentSet.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentSet.java
index e88cac4..e55be24 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentSet.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ConcurrentSet.java
@@ -19,12 +19,11 @@ package org.apache.activemq.artemis.utils;
import java.util.Set;
/**
- *
* A ConcurrentSet
*
* @param The generic class
*/
-public interface ConcurrentSet extends Set
-{
+public interface ConcurrentSet extends Set {
+
boolean addIfAbsent(E o);
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DataConstants.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DataConstants.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DataConstants.java
index 9ea5cf3..38df9b6 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DataConstants.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DataConstants.java
@@ -16,8 +16,8 @@
*/
package org.apache.activemq.artemis.utils;
-public final class DataConstants
-{
+public final class DataConstants {
+
public static final int SIZE_INT = 4;
public static final int SIZE_BOOLEAN = 1;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
index 8e1a1db..6028742 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DefaultSensitiveStringCodec.java
@@ -38,31 +38,24 @@ import javax.crypto.spec.SecretKeySpec;
* The decode() and encode() method is copied originally from
* JBoss AS code base.
*/
-public class DefaultSensitiveStringCodec implements SensitiveDataCodec
-{
+public class DefaultSensitiveStringCodec implements SensitiveDataCodec {
+
private byte[] internalKey = "clusterpassword".getBytes();
- public String decode(Object secret) throws NoSuchPaddingException,
- NoSuchAlgorithmException,
- InvalidKeyException,
- BadPaddingException,
- IllegalBlockSizeException
- {
+ public String decode(Object secret) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
SecretKeySpec key = new SecretKeySpec(internalKey, "Blowfish");
- BigInteger n = new BigInteger((String)secret, 16);
+ BigInteger n = new BigInteger((String) secret, 16);
byte[] encoding = n.toByteArray();
// JBAS-3457: fix leading zeros
- if (encoding.length % 8 != 0)
- {
+ if (encoding.length % 8 != 0) {
int length = encoding.length;
int newLength = ((length / 8) + 1) * 8;
int pad = newLength - length; // number of leading zeros
byte[] old = encoding;
encoding = new byte[newLength];
- for (int i = old.length - 1; i >= 0; i--)
- {
+ for (int i = old.length - 1; i >= 0; i--) {
encoding[i + pad] = old[i];
}
}
@@ -74,12 +67,7 @@ public class DefaultSensitiveStringCodec implements SensitiveDataCodec
return new String(decode);
}
- public Object encode(String secret) throws NoSuchPaddingException,
- NoSuchAlgorithmException,
- InvalidKeyException,
- BadPaddingException,
- IllegalBlockSizeException
- {
+ public Object encode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
SecretKeySpec key = new SecretKeySpec(internalKey, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
@@ -89,24 +77,21 @@ public class DefaultSensitiveStringCodec implements SensitiveDataCodec
return n.toString(16);
}
- public void init(Map params)
- {
+ public void init(Map params) {
String key = params.get("key");
- if (key != null)
- {
+ if (key != null) {
updateKey(key);
}
}
/**
* This main class is as documented on configuration-index.md, where the user can mask the password here. *
+ *
* @param args
* @throws Exception
*/
- public static void main(String[] args) throws Exception
- {
- if (args.length != 1)
- {
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
System.err.println("Use: java -cp org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec password-to-encode");
System.err.println("Error: no password on the args");
System.exit(-1);
@@ -116,10 +101,8 @@ public class DefaultSensitiveStringCodec implements SensitiveDataCodec
System.out.println("Encoded password (without quotes): \"" + encode + "\"");
}
- private void updateKey(String key)
- {
+ private void updateKey(String key) {
this.internalKey = key.getBytes();
}
-
}