]> WPIA git - gigi.git/blobdiff - lib/jetty/org/eclipse/jetty/util/UrlEncoded.java
updating jetty to jetty-9.2.16.v2016040
[gigi.git] / lib / jetty / org / eclipse / jetty / util / UrlEncoded.java
index ef7f2f5fa9ef88ca04a24bcd720713ad34756067..a893fc9bc6130fd9bdcc9ca35b60947d9c9351da 100644 (file)
@@ -1,6 +1,6 @@
 //
 //  ========================================================================
-//  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
 //  ------------------------------------------------------------------------
 //  All rights reserved. This program and the accompanying materials
 //  are made available under the terms of the Eclipse Public License v1.0
@@ -684,87 +684,89 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
             int c;
             
             int totalLength = 0;
-            ByteArrayOutputStream2 output = new ByteArrayOutputStream2();
             
-            int size=0;
-            
-            while ((c=in.read())>0)
+            try(ByteArrayOutputStream2 output = new ByteArrayOutputStream2();)
             {
-                switch ((char) c)
+                int size=0;
+
+                while ((c=in.read())>0)
                 {
-                    case '&':
-                        size=output.size();
-                        value = size==0?"":output.toString(charset);
-                        output.setCount(0);
-                        if (key != null)
-                        {
-                            map.add(key,value);
-                        }
-                        else if (value!=null&&value.length()>0)
-                        {
-                            map.add(value,"");
-                        }
-                        key = null;
-                        value=null;
-                        if (maxKeys>0 && map.size()>maxKeys)
-                            throw new IllegalStateException("Form too many keys");
-                        break;
-                    case '=':
-                        if (key!=null)
-                        {
-                            output.write(c);
+                    switch ((char) c)
+                    {
+                        case '&':
+                            size=output.size();
+                            value = size==0?"":output.toString(charset);
+                            output.setCount(0);
+                            if (key != null)
+                            {
+                                map.add(key,value);
+                            }
+                            else if (value!=null&&value.length()>0)
+                            {
+                                map.add(value,"");
+                            }
+                            key = null;
+                            value=null;
+                            if (maxKeys>0 && map.size()>maxKeys)
+                                throw new IllegalStateException("Form too many keys");
                             break;
-                        }
-                        size=output.size();
-                        key = size==0?"":output.toString(charset);
-                        output.setCount(0);
-                        break;
-                    case '+':
-                        output.write(' ');
-                        break;
-                    case '%':
-                        int code0=in.read();
-                        if ('u'==code0)
-                        {
-                            int code1=in.read();
-                            if (code1>=0)
+                        case '=':
+                            if (key!=null)
                             {
-                                int code2=in.read();
-                                if (code2>=0)
+                                output.write(c);
+                                break;
+                            }
+                            size=output.size();
+                            key = size==0?"":output.toString(charset);
+                            output.setCount(0);
+                            break;
+                        case '+':
+                            output.write(' ');
+                            break;
+                        case '%':
+                            int code0=in.read();
+                            if ('u'==code0)
+                            {
+                                int code1=in.read();
+                                if (code1>=0)
                                 {
-                                    int code3=in.read();
-                                    if (code3>=0)
-                                        output.write(new String(Character.toChars((convertHexDigit(code0)<<12)+(convertHexDigit(code1)<<8)+(convertHexDigit(code2)<<4)+convertHexDigit(code3))).getBytes(charset));
+                                    int code2=in.read();
+                                    if (code2>=0)
+                                    {
+                                        int code3=in.read();
+                                        if (code3>=0)
+                                            output.write(new String(Character.toChars((convertHexDigit(code0)<<12)+(convertHexDigit(code1)<<8)+(convertHexDigit(code2)<<4)+convertHexDigit(code3))).getBytes(charset));
+                                    }
                                 }
+
                             }
-                            
-                        }
-                        else if (code0>=0)
-                        {
-                            int code1=in.read();
-                            if (code1>=0)
-                                output.write((convertHexDigit(code0)<<4)+convertHexDigit(code1));
-                        }
-                        break;
-                    default:
-                        output.write(c);
-                    break;
+                            else if (code0>=0)
+                            {
+                                int code1=in.read();
+                                if (code1>=0)
+                                    output.write((convertHexDigit(code0)<<4)+convertHexDigit(code1));
+                            }
+                            break;
+                        default:
+                            output.write(c);
+                            break;
+                    }
+
+                    totalLength++;
+                    if (maxLength>=0 && totalLength > maxLength)
+                        throw new IllegalStateException("Form too large");
                 }
-                
-                totalLength++;
-                if (maxLength>=0 && totalLength > maxLength)
-                    throw new IllegalStateException("Form too large");
-            }
 
-            size=output.size();
-            if (key != null)
-            {
-                value = size==0?"":output.toString(charset);
-                output.setCount(0);
-                map.add(key,value);
+                size=output.size();
+                if (key != null)
+                {
+                    value = size==0?"":output.toString(charset);
+                    output.setCount(0);
+                    map.add(key,value);
+                }
+                else if (size>0)
+                    map.add(output.toString(charset),"");
             }
-            else if (size>0)
-                map.add(output.toString(charset),"");
         }
     }