wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r1666780 - /wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java
Date Sun, 15 Mar 2015 06:12:18 GMT
Author: lresende
Date: Sun Mar 15 06:12:17 2015
New Revision: 1666780

URL: http://svn.apache.org/r1666780
Log:
WINK-371 - Force UTF-8 when reading Multi-Part MIME.

Modified:
    wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java

Modified: wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java
URL: http://svn.apache.org/viewvc/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java?rev=1666780&r1=1666779&r2=1666780&view=diff
==============================================================================
--- wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java
(original)
+++ wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java
Sun Mar 15 06:12:17 2015
@@ -22,11 +22,14 @@ package org.apache.wink.common.internal.
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.wink.common.internal.CaseInsensitiveMultivaluedMap;
 import org.apache.wink.common.internal.i18n.Messages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /*
  * TODO: Add the option to get the preamble
@@ -37,6 +40,9 @@ import org.apache.wink.common.internal.i
 public class MultiPartParser {
     public final static String             SEP                 = "\n";           //$NON-NLS-1$
 
+    private static final Logger            logger              = LoggerFactory.getLogger(MultiPartParser.class);
+    private final static String            UTF8                = "UTF-8";           //$NON-NLS-1$
+
     private InputStream                    is;
     private byte[]                         boundaryBA;
     static private byte[]                  boundaryDelimiterBA = "--".getBytes(); //$NON-NLS-1$
@@ -64,7 +70,11 @@ public class MultiPartParser {
 
     public MultiPartParser(InputStream is, String boundary) {
         this.is = is;
-        boundaryBA = ("--" + boundary).getBytes(); //$NON-NLS-1$
+        try {
+            boundaryBA = ("--" + boundary).getBytes(UTF8); //$NON-NLS-1$
+        } catch(UnsupportedEncodingException e) {
+            logger.debug("Error parsing multi part: " + e.getMessage(), e);
+        }
         // make sure to allocate a buffer that is at least double then the
         // boundary length
         int buffLength = Math.max(8192, boundaryBA.length * 2);
@@ -297,7 +307,7 @@ public class MultiPartParser {
             return null;
         }
 
-        String hdr = new String(buff, buffIdx, lineIdx);
+        String hdr = new String(buff, buffIdx, lineIdx, UTF8);
         buffIdx += lineIdx + breakeSize;
         return hdr;
     }



Mime
View raw message