You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/03/05 19:06:38 UTC
[commons-fileupload] branch master updated: No need to nest in else.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push:
new 6edb991 No need to nest in else.
6edb991 is described below
commit 6edb9914c5e15fc3c8acb9a869b447ca3ce96347
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Mar 5 14:06:34 2021 -0500
No need to nest in else.
---
.../commons/fileupload2/disk/DiskFileItem.java | 36 +++++++++++-----------
.../commons/fileupload2/util/mime/MimeUtility.java | 10 +++---
.../jaksrvlt/MockJakSrvltHttpRequest.java | 3 +-
3 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
index ba6d85d..c173dc6 100644
--- a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
@@ -279,13 +279,14 @@ public class DiskFileItem
public long getSize() {
if (size >= 0) {
return size;
- } else if (cachedContent != null) {
+ }
+ if (cachedContent != null) {
return cachedContent.length;
- } else if (dfos.isInMemory()) {
+ }
+ if (dfos.isInMemory()) {
return dfos.getData().length;
- } else {
- return dfos.getFile().length();
}
+ return dfos.getFile().length();
}
/**
@@ -394,20 +395,7 @@ public class DiskFileItem
}
} else {
final File outputFile = getStoreLocation();
- if (outputFile != null) {
- // Save the length of the file
- size = outputFile.length();
- /*
- * The uploaded file is being stored on disk
- * in a temporary location so move it to the
- * desired file.
- */
- if (file.exists() && !file.delete()) {
- throw new FileUploadException(
- "Cannot write uploaded file to disk!");
- }
- FileUtils.moveFile(outputFile, file);
- } else {
+ if (outputFile == null) {
/*
* For whatever reason we cannot write the
* file to disk.
@@ -415,6 +403,18 @@ public class DiskFileItem
throw new FileUploadException(
"Cannot write uploaded file to disk!");
}
+ // Save the length of the file
+ size = outputFile.length();
+ /*
+ * The uploaded file is being stored on disk
+ * in a temporary location so move it to the
+ * desired file.
+ */
+ if (file.exists() && !file.delete()) {
+ throw new FileUploadException(
+ "Cannot write uploaded file to disk!");
+ }
+ FileUtils.moveFile(outputFile, file);
}
}
diff --git a/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java b/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java
index 690e394..af0f06b 100644
--- a/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java
+++ b/src/main/java/org/apache/commons/fileupload2/util/mime/MimeUtility.java
@@ -122,14 +122,13 @@ public final class MimeUtility {
while (offset < endOffset) {
// step over the white space characters.
ch = text.charAt(offset);
- if (LINEAR_WHITESPACE.indexOf(ch) != -1) { // whitespace found
- offset++;
- } else {
+ if (LINEAR_WHITESPACE.indexOf(ch) == -1) {
// record the location of the first non lwsp and drop down to process the
// token characters.
endWhiteSpace = offset;
break;
}
+ offset++;
}
} else {
// we have a word token. We need to scan over the word and then try to parse it.
@@ -138,11 +137,10 @@ public final class MimeUtility {
while (offset < endOffset) {
// step over the non white space characters.
ch = text.charAt(offset);
- if (LINEAR_WHITESPACE.indexOf(ch) == -1) { // not white space
- offset++;
- } else {
+ if (LINEAR_WHITESPACE.indexOf(ch) != -1) {
break;
}
+ offset++;
//NB: Trailing whitespace on these header strings will just be discarded.
}
diff --git a/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java
index cdab3eb..b863c5b 100644
--- a/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java
+++ b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java
@@ -595,9 +595,8 @@ public class MockJakSrvltHttpRequest implements HttpServletRequest {
final HttpSession session = getSession();
if (session == null) {
return null;
- } else {
- return session.getServletContext();
}
+ return session.getServletContext();
}
@Override