You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2023/09/16 08:11:34 UTC
[commons-fileupload] 05/21: No need to nest in else
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
commit 5c17e30b1c53caa67b0c83d8e9101d1b49cefd79
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Sep 15 15:49:10 2023 +0100
No need to nest in else
---
.../commons/fileupload/disk/DiskFileItem.java | 34 +++++++++++-----------
.../commons/fileupload/util/mime/MimeUtility.java | 10 +++----
2 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
index df116751..64ea0246 100644
--- a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload/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,19 +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();
- }
- FileUtils.moveFile(outputFile, file);
- } else {
+ if (outputFile == null) {
/*
* For whatever reason we cannot write the
* file to disk.
@@ -414,6 +403,17 @@ 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();
+ }
+ FileUtils.moveFile(outputFile, file);
}
}
diff --git a/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java b/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java
index 6c60b889..af1db7c6 100644
--- a/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java
+++ b/src/main/java/org/apache/commons/fileupload/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.
}