as discussed in ML, there are MagicNumbers which don't make sense to extract as constant for the sake to make just Checkstyle happy, so MagicNumbers have been reverted - dropped also the constants used only once - and added the related suppressions for interested files
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/fileupload/trunk@1457865 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 8e3d117..5eb14b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -259,6 +259,7 @@
<version>2.10</version>
<configuration>
<configLocation>${basedir}/src/checkstyle/fileupload_checks.xml</configLocation>
+ <suppressionsLocation>${basedir}/src/checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
<enableRulesSummary>false</enableRulesSummary>
<headerFile>${basedir}/src/checkstyle/license-header.txt</headerFile>
</configuration>
diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml
new file mode 100644
index 0000000..45a9b1a
--- /dev/null
+++ b/src/checkstyle/checkstyle-suppressions.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE suppressions PUBLIC
+ "-//Puppy Crawl//DTD Suppressions 1.0//EN"
+ "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
+<!--
+ 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.
+-->
+<suppressions>
+ <suppress checks="MagicNumber" files="(Base64|QuotedPrintable)Decoder.java" lines="0-9999"/>
+</suppressions>
diff --git a/src/main/java/org/apache/commons/fileupload/util/mime/Base64Decoder.java b/src/main/java/org/apache/commons/fileupload/util/mime/Base64Decoder.java
index 07dfdf3..e2a82bb 100644
--- a/src/main/java/org/apache/commons/fileupload/util/mime/Base64Decoder.java
+++ b/src/main/java/org/apache/commons/fileupload/util/mime/Base64Decoder.java
@@ -25,26 +25,6 @@
final class Base64Decoder {
/**
- * Bytes per undecoded block.
- */
- private static final int BYTES_PER_UNENCODED_BLOCK = 3;
-
- /**
- * 2 bits mask.
- */
- private static final int MASK_2BITS = 2;
-
- /**
- * 4 bits mask.
- */
- private static final int MASK_4BITS = 4;
-
- /**
- * 6 bits mask.
- */
- private static final int MASK_6BITS = 6;
-
- /**
* Set up the encoding table.
*/
private static final byte[] ENCODING_TABLE = {
@@ -67,15 +47,10 @@
private static final byte PADDING = (byte) '=';
/**
- * The number of possible byte values; i.e. positives, negatives and zero.
- */
- private static final int DISTINCT_BYTE_VALUES = Byte.MAX_VALUE - Byte.MIN_VALUE + 1;
-
- /**
* Set up the decoding table; this is indexed by a byte converted to an int,
* so must be at least as large as the number of different byte values.
*/
- private static final byte[] DECODING_TABLE = new byte[DISTINCT_BYTE_VALUES];
+ private static final byte[] DECODING_TABLE = new byte[256];
static {
for (int i = 0; i < ENCODING_TABLE.length; i++) {
@@ -127,7 +102,7 @@
}
int i = off;
- int finish = end - MASK_4BITS;
+ int finish = end - 4;
while (i < finish) {
while ((i < finish) && ignore((char) data[i])) {
@@ -154,40 +129,40 @@
b4 = DECODING_TABLE[data[i++]];
- out.write((b1 << MASK_2BITS) | (b2 >> MASK_4BITS));
- out.write((b2 << MASK_4BITS) | (b3 >> MASK_2BITS));
- out.write((b3 << MASK_6BITS) | b4);
+ out.write((b1 << 2) | (b2 >> 4));
+ out.write((b2 << 4) | (b3 >> 2));
+ out.write((b3 << 6) | b4);
- outLen += BYTES_PER_UNENCODED_BLOCK;
+ outLen += 3;
}
- if (data[end - MASK_2BITS] == PADDING) {
- b1 = DECODING_TABLE[data[end - MASK_4BITS]];
- b2 = DECODING_TABLE[data[end - BYTES_PER_UNENCODED_BLOCK]];
+ if (data[end - 2] == PADDING) {
+ b1 = DECODING_TABLE[data[end - 4]];
+ b2 = DECODING_TABLE[data[end - 3]];
- out.write((b1 << MASK_2BITS) | (b2 >> MASK_4BITS));
+ out.write((b1 << 2) | (b2 >> 4));
outLen += 1;
} else if (data[end - 1] == PADDING) {
- b1 = DECODING_TABLE[data[end - MASK_4BITS]];
- b2 = DECODING_TABLE[data[end - BYTES_PER_UNENCODED_BLOCK]];
- b3 = DECODING_TABLE[data[end - MASK_2BITS]];
+ b1 = DECODING_TABLE[data[end - 4]];
+ b2 = DECODING_TABLE[data[end - 3]];
+ b3 = DECODING_TABLE[data[end - 2]];
- out.write((b1 << MASK_2BITS) | (b2 >> MASK_4BITS));
- out.write((b2 << MASK_4BITS) | (b3 >> MASK_2BITS));
+ out.write((b1 << 2) | (b2 >> 4));
+ out.write((b2 << 4) | (b3 >> 2));
- outLen += MASK_2BITS;
+ outLen += 2;
} else {
- b1 = DECODING_TABLE[data[end - MASK_4BITS]];
- b2 = DECODING_TABLE[data[end - BYTES_PER_UNENCODED_BLOCK]];
- b3 = DECODING_TABLE[data[end - MASK_2BITS]];
+ b1 = DECODING_TABLE[data[end - 4]];
+ b2 = DECODING_TABLE[data[end - 3]];
+ b3 = DECODING_TABLE[data[end - 2]];
b4 = DECODING_TABLE[data[end - 1]];
- out.write((b1 << MASK_2BITS) | (b2 >> MASK_4BITS));
- out.write((b2 << MASK_4BITS) | (b3 >> MASK_2BITS));
- out.write((b3 << MASK_6BITS) | b4);
+ out.write((b1 << 2) | (b2 >> 4));
+ out.write((b2 << 4) | (b3 >> 2));
+ out.write((b3 << 6) | b4);
- outLen += BYTES_PER_UNENCODED_BLOCK;
+ outLen += 3;
}
return outLen;
diff --git a/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java b/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java
index 5536798..77f394c 100644
--- a/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java
+++ b/src/main/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoder.java
@@ -33,20 +33,15 @@
};
/**
- * The shift value required to create the upper nibble
- * from the first of 2 byte values converted from ascii hex.
+ * The shift value required to create the upper nibble
+ * from the first of 2 byte values converted from ascii hex.
*/
private static final int UPPER_NIBBLE_SHIFT = Byte.SIZE / 2;
/**
- * The decoding table size.
- */
- private static final int DECODING_TABLE_SIZE = 128;
-
- /**
* Set up the decoding table.
*/
- private static final byte[] DECODING_TABLE = new byte[DECODING_TABLE_SIZE];
+ private static final byte[] DECODING_TABLE = new byte[128];
static {
// initialize the decoding table