From b0b765001c8cf261c20c05f0230b92f92a664953 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 9 Nov 2012 17:37:03 +0900 Subject: [PATCH] Enum should not have a non-final value --- .../http/multipart/HttpPostBodyUtil.java | 10 ++++--- .../multipart/HttpPostRequestDecoder.java | 26 +++++++++---------- .../multipart/HttpPostRequestEncoder.java | 6 ++--- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostBodyUtil.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostBodyUtil.java index 4206a430aa..b20e5978d2 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostBodyUtil.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostBodyUtil.java @@ -15,11 +15,11 @@ */ package org.jboss.netty.handler.codec.http.multipart; -import java.nio.charset.Charset; - import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.util.CharsetUtil; +import java.nio.charset.Charset; + /** * Shared Static object between HttpMessageDecoder, HttpPostRequestDecoder and HttpPostRequestEncoder */ @@ -97,7 +97,7 @@ final class HttpPostBodyUtil { */ BINARY("binary"); - public String value; + private final String value; TransferEncodingMechanism(String value) { this.value = value; @@ -107,6 +107,10 @@ final class HttpPostBodyUtil { value = name(); } + public String value() { + return value; + } + @Override public String toString() { return value; diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java index 79f71017dd..fe1ab972db 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java @@ -15,15 +15,6 @@ */ package org.jboss.netty.handler.codec.http.multipart; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.handler.codec.http.HttpChunk; @@ -36,6 +27,15 @@ import org.jboss.netty.handler.codec.http.multipart.HttpPostBodyUtil.SeekAheadOp import org.jboss.netty.handler.codec.http.multipart.HttpPostBodyUtil.TransferEncodingMechanism; import org.jboss.netty.util.internal.CaseIgnoringComparator; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + /** * This decoder will decode Body and can handle POST BODY. */ @@ -1108,13 +1108,13 @@ public class HttpPostRequestDecoder { } catch (IOException e) { throw new ErrorDataDecoderException(e); } - if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT7.value)) { + if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT7.value())) { localCharset = HttpPostBodyUtil.US_ASCII; - } else if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT8.value)) { + } else if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT8.value())) { localCharset = HttpPostBodyUtil.ISO_8859_1; mechanism = TransferEncodingMechanism.BIT8; } else if (code - .equals(HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value)) { + .equals(HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value())) { // no real charset, so let the default mechanism = TransferEncodingMechanism.BINARY; } else { @@ -1157,7 +1157,7 @@ public class HttpPostRequestDecoder { currentFileUpload = factory.createFileUpload( request, nameAttribute.getValue(), filenameAttribute.getValue(), - contentTypeAttribute.getValue(), mechanism.value, + contentTypeAttribute.getValue(), mechanism.value(), localCharset, size); } catch (NullPointerException e) { throw new ErrorDataDecoderException(e); diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java index 0cc8710ee5..5e1ffe9ba8 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java @@ -290,7 +290,7 @@ public class HttpPostRequestEncoder implements ChunkedInput { } } if (!isText) { - contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value; + contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value(); } FileUpload fileUpload = factory.createFileUpload(request, name, file.getName(), scontentType, contentTransferEncoding, null, file.length()); @@ -540,9 +540,9 @@ public class HttpPostRequestEncoder implements ChunkedInput { String contentTransferEncoding = fileUpload.getContentTransferEncoding(); if (contentTransferEncoding != null && contentTransferEncoding.equals( - HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value)) { + HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value())) { internal.addValue("\r\n" + HttpHeaders.Names.CONTENT_TRANSFER_ENCODING + - ": " + HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value + + ": " + HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value() + "\r\n\r\n"); } else if (fileUpload.getCharset() != null) { internal.addValue("; " + HttpHeaders.Values.CHARSET + "=" +