Skip to content

Commit c3ead05

Browse files
author
Stephane Landelle
committed
Use a switch with enum, not if/else if
1 parent 8418f56 commit c3ead05

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ enum FileLocation {
5555
}
5656

5757
public MultipartBody(List<Part> parts, String contentType, long contentLength) {
58-
this.boundary = MultipartEncodingUtil.getAsciiBytes(contentType.substring(contentType.indexOf("boundary=") + "boundary=".length()));
58+
this.boundary = MultipartEncodingUtil.getAsciiBytes(contentType.substring(contentType.indexOf("boundary=")
59+
+ "boundary=".length()));
5960
this.contentLength = contentLength;
6061
this.parts = parts;
6162
}
@@ -113,14 +114,19 @@ public long read(ByteBuffer buffer) throws IOException {
113114
startPart++;
114115

115116
} else if (part instanceof AbstractFilePart) {
116-
if (fileLocation == FileLocation.NONE) {
117+
118+
switch (fileLocation) {
119+
case NONE:
117120
currentFilePart = (AbstractFilePart) part;
118121
initializeFilePart(currentFilePart);
119-
} else if (fileLocation == FileLocation.START) {
122+
break;
123+
case START:
120124
initializeFileBody(currentFilePart);
121-
} else if (fileLocation == FileLocation.MIDDLE) {
125+
break;
126+
case MIDDLE:
122127
initializeFileEnd(currentFilePart);
123-
} else if (fileLocation == FileLocation.END) {
128+
break;
129+
case END:
124130
startPart++;
125131
fileLocation = FileLocation.NONE;
126132
if (startPart == parts.size() && currentStream.available() == 0) {

0 commit comments

Comments
 (0)