diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java index 6143270e41..c320f021d6 100644 --- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java +++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java @@ -44,9 +44,24 @@ * {@link FileUploadBase#getItemIterator(RequestContext)}. */ public class FileItemIteratorImpl implements FileItemIterator { + /** + * The file uploads processing utility. + * @see FileUploadBase + */ private final FileUploadBase fileUploadBase; + /** + * The request context. + * @see RequestContext + */ private final RequestContext ctx; - private long sizeMax, fileSizeMax; + /** + * The maximum allowed size of a complete request. + */ + private long sizeMax; + /** + * The maximum allowed size of a single uploaded file. + */ + private long fileSizeMax; @Override diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java index 7a25d556c8..e3a9b25bc3 100644 --- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java +++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java @@ -35,6 +35,11 @@ * Default implementation of {@link FileItemStream}. */ public class FileItemStreamImpl implements FileItemStream { + /** + * The File Item iterator implementation. + * + * @see FileItemIteratorImpl + */ private final FileItemIteratorImpl fileItemIteratorImpl; /** @@ -50,7 +55,7 @@ public class FileItemStreamImpl implements FileItemStream { /** * The file items file name. */ - final String name; + private final String name; /** * Whether the file item is a form field. diff --git a/src/main/java/org/apache/commons/fileupload2/impl/package-info.java b/src/main/java/org/apache/commons/fileupload2/impl/package-info.java new file mode 100644 index 0000000000..93c87acb02 --- /dev/null +++ b/src/main/java/org/apache/commons/fileupload2/impl/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/** + * Implementations and exceptions utils. + */ +package org.apache.commons.fileupload2.impl; diff --git a/src/main/java/org/apache/commons/fileupload2/util/mime/Base64Decoder.java b/src/main/java/org/apache/commons/fileupload2/util/mime/Base64Decoder.java index 231df63cf7..9b32d2df9e 100644 --- a/src/main/java/org/apache/commons/fileupload2/util/mime/Base64Decoder.java +++ b/src/main/java/org/apache/commons/fileupload2/util/mime/Base64Decoder.java @@ -104,7 +104,7 @@ private Base64Decoder() { */ public static int decode(final byte[] data, final OutputStream out) throws IOException { int outLen = 0; - final byte[ ] cache = new byte[INPUT_BYTES_PER_CHUNK]; + final byte[] cache = new byte[INPUT_BYTES_PER_CHUNK]; int cachedBytes = 0; for (final byte b : data) { diff --git a/src/main/java/org/apache/commons/fileupload2/util/mime/ParseException.java b/src/main/java/org/apache/commons/fileupload2/util/mime/ParseException.java index 38f3d91340..7981ea4907 100644 --- a/src/main/java/org/apache/commons/fileupload2/util/mime/ParseException.java +++ b/src/main/java/org/apache/commons/fileupload2/util/mime/ParseException.java @@ -31,7 +31,7 @@ final class ParseException extends Exception { * * @param message the detail message. */ - public ParseException(final String message) { + ParseException(final String message) { super(message); } diff --git a/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java b/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java index 18d0609c27..fbdea2db35 100644 --- a/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java +++ b/src/main/java/org/apache/commons/fileupload2/util/mime/RFC2231Utility.java @@ -31,10 +31,22 @@ * @see RFC 5987 */ public final class RFC2231Utility { - + /** + * The Hexadecimal values char array. + */ private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); - - private static final byte[] HEX_DECODE = new byte[0x80]; + /** + * The Hexadecimal representation of 127. + */ + private static final byte MASK = 0x7f; + /** + * The Hexadecimal representation of 128. + */ + private static final int MASK_128 = 0x80; + /** + * The Hexadecimal decode value. + */ + private static final byte[] HEX_DECODE = new byte[MASK_128]; // create a ASCII decoded array of Hexadecimal values static { @@ -44,9 +56,16 @@ public final class RFC2231Utility { } } + /** + * Private constructor so that no instances can be created. This class + * contains only static utility methods. + */ + private RFC2231Utility() { + } + /** * Checks if Asterisk (*) at the end of parameter name to indicate, - * if it has charset and language information to decode the value + * if it has charset and language information to decode the value. * @param paramName The parameter, which is being checked. * @return {@code true}, if encoded as per RFC 2231, {@code false} otherwise */ @@ -59,7 +78,7 @@ public static boolean hasEncodedValue(final String paramName) { /** * If {@code paramName} has Asterisk (*) at the end, it will be stripped off, - * else the passed value will be returned + * else the passed value will be returned. * @param paramName The parameter, which is being inspected. * @return stripped {@code paramName} of Asterisk (*), if RFC2231 encoded */ @@ -106,11 +125,12 @@ public static String decodeText(final String encodedText) throws UnsupportedEnco } /** - * Convert {@code text} to their corresponding Hex value + * Convert {@code text} to their corresponding Hex value. * @param text - ASCII text input * @return Byte array of characters decoded from ASCII table */ private static byte[] fromHex(final String text) { + final int shift = 4; final ByteArrayOutputStream out = new ByteArrayOutputStream(text.length()); for (int i = 0; i < text.length();) { final char c = text.charAt(i++); @@ -118,9 +138,9 @@ private static byte[] fromHex(final String text) { if (i > text.length() - 2) { break; // unterminated sequence } - final byte b1 = HEX_DECODE[text.charAt(i++) & 0x7f]; - final byte b2 = HEX_DECODE[text.charAt(i++) & 0x7f]; - out.write((b1 << 4) | b2); + final byte b1 = HEX_DECODE[text.charAt(i++) & MASK]; + final byte b2 = HEX_DECODE[text.charAt(i++) & MASK]; + out.write((b1 << shift) | b2); } else { out.write((byte) c); }