Author: simonetripodi Date: Wed Mar 6 09:39:17 2013 New Revision: 1453239 URL: http://svn.apache.org/r1453239 Log: [FILEUPLOAD-224] #comment string concatenation replaced by temporary buffers #resolve
Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/MultipartStream.java commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java?rev=1453239&r1=1453238&r2=1453239&view=diff ============================================================================== --- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java (original) +++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java Wed Mar 6 09:39:17 2013 @@ -16,6 +16,8 @@ */ package org.apache.commons.fileupload; +import static java.lang.String.format; + import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; @@ -371,9 +373,8 @@ public abstract class FileUploadBase { } catch (FileUploadIOException e) { throw (FileUploadException) e.getCause(); } catch (IOException e) { - throw new IOFileUploadException( - "Processing of " + MULTIPART_FORM_DATA - + " request failed. " + e.getMessage(), e); + throw new IOFileUploadException(format("Processing of %s request failed. ", + MULTIPART_FORM_DATA, e.getMessage()), e); } if (fileItem instanceof FileItemHeadersSupport) { final FileItemHeaders fih = item.getHeaders(); @@ -582,7 +583,7 @@ public abstract class FileUploadBase { if (start == end) { break; } - String header = headerPart.substring(start, end); + StringBuilder header = new StringBuilder(headerPart.substring(start, end)); start = end + 2; while (start < len) { int nonWs = start; @@ -598,10 +599,10 @@ public abstract class FileUploadBase { } // Continuation line found end = parseEndOfLine(headerPart, nonWs); - header += " " + headerPart.substring(nonWs, end); + header.append(" ").append(headerPart.substring(nonWs, end)); start = end + 2; } - parseHeaderLine(headers, header); + parseHeaderLine(headers, header.toString()); } return headers; } @@ -634,11 +635,11 @@ public abstract class FileUploadBase { for (Iterator<String> iter = headers.getHeaderNames(); iter.hasNext();) { String headerName = iter.next(); Iterator<String> iter2 = headers.getHeaders(headerName); - String headerValue = iter2.next(); + StringBuilder headerValue = new StringBuilder(iter2.next()); while (iter2.hasNext()) { - headerValue += "," + iter2.next(); + headerValue.append(",").append(iter2.next()); } - result.put(headerName, headerValue); + result.put(headerName, headerValue.toString()); } return result; } @@ -754,10 +755,8 @@ public abstract class FileUploadBase { && pContentLength > fileSizeMax) { FileSizeLimitExceededException e = new FileSizeLimitExceededException( - "The field " + fieldName - + " exceeds its maximum permitted " - + " size of " + fileSizeMax - + " bytes.", + format("The field %s exceeds its maximum permitted size of %s bytes.", + fieldName, fileSizeMax ), pContentLength, fileSizeMax); e.setFileName(pName); e.setFieldName(pFieldName); @@ -770,10 +769,8 @@ public abstract class FileUploadBase { itemStream.close(true); FileSizeLimitExceededException e = new FileSizeLimitExceededException( - "The field " + fieldName - + " exceeds its maximum permitted " - + " size of " + pSizeMax - + " bytes.", + format("The field %s exceeds its maximum permitted size of %s bytes.", + fieldName, pSizeMax ), pCount, pSizeMax); e.setFieldName(fieldName); e.setFileName(name); @@ -914,12 +911,8 @@ public abstract class FileUploadBase { if ((null == contentType) || (!contentType.toLowerCase().startsWith(MULTIPART))) { throw new InvalidContentTypeException( - "the request doesn't contain a " - + MULTIPART_FORM_DATA - + " or " - + MULTIPART_MIXED - + " stream, content type header is " - + contentType); + format("the request doesn't contain a %s or %s stream, content type header is %s", + MULTIPART_FORM_DATA, MULTIPART_FORM_DATA, contentType)); } InputStream input = ctx.getInputStream(); @@ -931,24 +924,19 @@ public abstract class FileUploadBase { @Override protected void raiseError(long pSizeMax, long pCount) throws IOException { - FileUploadException ex = - new SizeLimitExceededException( - "the request was rejected because" - + " its size (" + pCount - + ") exceeds the configured maximum" - + " (" + pSizeMax + ")", - pCount, pSizeMax); + FileUploadException ex = new SizeLimitExceededException( + format("the request was rejected because its size (%s) exceeds the configured maximum (%s)", + pCount, pSizeMax), + pCount, pSizeMax); throw new FileUploadIOException(ex); } }; } else { if (sizeMax >= 0 && requestSize > sizeMax) { throw new SizeLimitExceededException( - "the request was rejected because its size (" - + requestSize - + ") exceeds the configured maximum (" - + sizeMax + ")", - requestSize, sizeMax); + format("the request was rejected because its size (%s) exceeds the configured maximum (%s)", + requestSize, sizeMax), + requestSize, sizeMax); } } } @@ -960,9 +948,7 @@ public abstract class FileUploadBase { boundary = getBoundary(contentType); if (boundary == null) { - throw new FileUploadException( - "the request was rejected because " - + "no multipart boundary was found"); + throw new FileUploadException("the request was rejected because no multipart boundary was found"); } notifier = new MultipartStream.ProgressNotifier(listener, Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/MultipartStream.java URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/MultipartStream.java?rev=1453239&r1=1453238&r2=1453239&view=diff ============================================================================== --- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/MultipartStream.java (original) +++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/MultipartStream.java Wed Mar 6 09:39:17 2013 @@ -16,6 +16,8 @@ */ package org.apache.commons.fileupload; +import static java.lang.String.format; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -530,8 +532,8 @@ public class MultipartStream { } if (++size > HEADER_PART_SIZE_MAX) { throw new MalformedStreamException( - "Header section has more than " + HEADER_PART_SIZE_MAX - + " bytes (maybe it is not properly terminated)"); + format("Header section has more than %s bytes (maybe it is not properly terminated)", + HEADER_PART_SIZE_MAX)); } if (b == HEADER_SEPARATOR[i]) { i++; Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=1453239&r1=1453238&r2=1453239&view=diff ============================================================================== --- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java (original) +++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java Wed Mar 6 09:39:17 2013 @@ -16,6 +16,8 @@ */ package org.apache.commons.fileupload.disk; +import static java.lang.String.format; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; @@ -585,8 +587,7 @@ public class DiskFileItem tempDir = new File(System.getProperty("java.io.tmpdir")); } - String tempFileName = - "upload_" + UID + "_" + getUniqueId() + ".tmp"; + String tempFileName = format("upload_%s_%s.tmp", UID, getUniqueId()); tempFile = new File(tempDir, tempFileName); } @@ -624,15 +625,8 @@ public class DiskFileItem */ @Override public String toString() { - return "name=" + this.getName() - + ", StoreLocation=" - + String.valueOf(this.getStoreLocation()) - + ", size=" - + this.getSize() - + "bytes, " - + "isFormField=" + isFormField() - + ", FieldName=" - + this.getFieldName(); + return format("name=%s, StoreLocation=%s, size=%s bytes, isFormField=%s, FieldName=%s", + getName(), getStoreLocation(), getSize(), isFormField(), getFieldName()); } // -------------------------------------------------- Serialization methods Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java?rev=1453239&r1=1453238&r2=1453239&view=diff ============================================================================== --- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java (original) +++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/portlet/PortletRequestContext.java Wed Mar 6 09:39:17 2013 @@ -16,6 +16,8 @@ */ package org.apache.commons.fileupload.portlet; +import static java.lang.String.format; + import java.io.InputStream; import java.io.IOException; import javax.portlet.ActionRequest; @@ -100,10 +102,9 @@ public class PortletRequestContext imple */ @Override public String toString() { - return "ContentLength=" - + this.getContentLength() - + ", ContentType=" - + this.getContentType(); + return format("ContentLength=%s, ContentType=%s", + this.getContentLength(), + this.getContentType()); } } Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java?rev=1453239&r1=1453238&r2=1453239&view=diff ============================================================================== --- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java (original) +++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/servlet/ServletRequestContext.java Wed Mar 6 09:39:17 2013 @@ -16,6 +16,8 @@ */ package org.apache.commons.fileupload.servlet; +import static java.lang.String.format; + import java.io.InputStream; import java.io.IOException; import javax.servlet.http.HttpServletRequest; @@ -98,10 +100,9 @@ public class ServletRequestContext imple */ @Override public String toString() { - return "ContentLength=" - + this.getContentLength() - + ", ContentType=" - + this.getContentType(); + return format("ContentLength=%s, ContentType=%s", + this.getContentLength(), + this.getContentType()); } }