annotate src/org/eclipse/jetty/util/MultiPartInputStream.java @ 873:220ad4853cda

remove StreamEndPoint
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 03 Oct 2016 20:03:50 -0600
parents 3dcc52e17535
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.util;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.BufferedInputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.io.BufferedOutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.io.BufferedReader;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.io.ByteArrayInputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import java.io.ByteArrayOutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import java.io.File;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import java.io.FileInputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import java.io.FileNotFoundException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import java.io.FileOutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import java.io.FilterInputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import java.io.InputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import java.io.InputStreamReader;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import java.io.OutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import java.lang.reflect.Array;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import java.util.ArrayList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import java.util.Collection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import java.util.Collections;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 import java.util.HashMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 import java.util.List;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import java.util.Locale;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import java.util.Map;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import java.util.StringTokenizer;
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
44 import java.util.Base64;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 import javax.servlet.http.Part;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 * MultiPartInputStream
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 * Handle a MultiPart Mime input stream, breaking it up on the boundary into files and strings.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 public class MultiPartInputStream
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 {
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 private static final Logger LOG = LoggerFactory.getLogger(MultiPartInputStream.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 protected InputStream _in;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 protected String _contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 protected MultiMap<String> _parts;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68
859
3dcc52e17535 simplify multipart
Franklin Schmidt <fschmidt@gmail.com>
parents: 825
diff changeset
69 public final class MultiPart implements Part
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 protected String _name;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 protected String _filename;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 protected File _file;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 protected OutputStream _out;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 protected ByteArrayOutputStream2 _bout;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 protected String _contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 protected MultiMap<String> _headers;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 protected long _size = 0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 public MultiPart (String name, String filename)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 _name = name;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 _filename = filename;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 protected void setContentType (String contentType)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 _contentType = contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 protected void open()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 //We will either be writing to a file, if it has a filename on the content-disposition
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 //and otherwise a byte-array-input-stream, OR if we exceed the getFileSizeThreshold, we
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 //will need to change to write to a file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 if (_filename != null && _filename.trim().length() > 0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 createFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 //Write to a buffer in memory until we discover we've exceed the
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 //MultipartConfig fileSizeThreshold
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 _out = _bout= new ByteArrayOutputStream2();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 protected void close()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 _out.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 protected void write (int b)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 _out.write(b);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 _size ++;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 protected void write (byte[] bytes, int offset, int length)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 _out.write(bytes, offset, length);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 _size += length;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 protected void createFile ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 {
859
3dcc52e17535 simplify multipart
Franklin Schmidt <fschmidt@gmail.com>
parents: 825
diff changeset
135 _file = File.createTempFile("MultiPart", null);
3dcc52e17535 simplify multipart
Franklin Schmidt <fschmidt@gmail.com>
parents: 825
diff changeset
136 _file.deleteOnExit();
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 FileOutputStream fos = new FileOutputStream(_file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 BufferedOutputStream bos = new BufferedOutputStream(fos);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 if (_size > 0 && _out != null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 //already written some bytes, so need to copy them into the file
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 _out.flush();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 _bout.writeTo(bos);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 _out.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 _bout = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 _out = bos;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 protected void setHeaders(MultiMap<String> headers)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 _headers = headers;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 * @see javax.servlet.http.Part#getContentType()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 public String getContentType()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 return _contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 * @see javax.servlet.http.Part#getHeader(java.lang.String)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 public String getHeader(String name)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 if (name == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 return (String)_headers.getValue(name.toLowerCase(Locale.ENGLISH), 0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 * @see javax.servlet.http.Part#getHeaderNames()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 public Collection<String> getHeaderNames()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 return _headers.keySet();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 * @see javax.servlet.http.Part#getHeaders(java.lang.String)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 public Collection<String> getHeaders(String name)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 return _headers.getValues(name);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 * @see javax.servlet.http.Part#getInputStream()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 public InputStream getInputStream() throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 if (_file != null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 //written to a file, whether temporary or not
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 return new BufferedInputStream (new FileInputStream(_file));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 //part content is in memory
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 return new ByteArrayInputStream(_bout.getBuf(),0,_bout.size());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 public byte[] getBytes()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 if (_bout!=null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 return _bout.toByteArray();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 * @see javax.servlet.http.Part#getName()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 public String getName()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 return _name;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 * @see javax.servlet.http.Part#getSize()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 public long getSize()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 return _size;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 * @see javax.servlet.http.Part#write(java.lang.String)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 public void write(String fileName) throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 {
859
3dcc52e17535 simplify multipart
Franklin Schmidt <fschmidt@gmail.com>
parents: 825
diff changeset
237 throw new UnsupportedOperationException();
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 * Remove the file, whether or not Part.write() was called on it
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 * (ie no longer temporary)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 * @see javax.servlet.http.Part#delete()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 public void delete() throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 if (_file != null && _file.exists())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 _file.delete();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 * Only remove tmp files.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 public void cleanUp() throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 {
859
3dcc52e17535 simplify multipart
Franklin Schmidt <fschmidt@gmail.com>
parents: 825
diff changeset
258 if (_file != null && _file.exists())
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 _file.delete();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 * Get the file, if any, the data has been written to.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 public File getFile ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 return _file;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 * Get the filename from the content-disposition.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 * @return null or the filename
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 public String getContentDispositionFilename ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 return _filename;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 * @param in Request input stream
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 * @param contentType Content-Type header
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 * @param config MultipartConfigElement
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 * @param contextTmpDir javax.servlet.context.tempdir
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 */
859
3dcc52e17535 simplify multipart
Franklin Schmidt <fschmidt@gmail.com>
parents: 825
diff changeset
292 public MultiPartInputStream (InputStream in, String contentType)
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 _in = new ReadLineInputStream(in);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 _contentType = contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
297
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 * Get the already parsed parts.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 public Collection<Part> getParsedParts()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 if (_parts == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 return Collections.emptyList();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
307
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 Collection<Object> values = _parts.values();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 List<Part> parts = new ArrayList<Part>();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 for (Object o: values)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 List<Part> asList = LazyList.getList(o, false);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 parts.addAll(asList);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 return parts;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 * Delete any tmp storage for parts, and clear out the parts list.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 * @throws MultiException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 public void deleteParts ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 throws MultiException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 Collection<Part> parts = getParsedParts();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 MultiException err = new MultiException();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 for (Part p:parts)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 ((MultiPartInputStream.MultiPart)p).cleanUp();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 catch(Exception e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 err.add(e);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 _parts.clear();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 err.ifExceptionThrowMulti();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 * Parse, if necessary, the multipart data and return the list of Parts.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 * @throws ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 public Collection<Part> getParts()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 throws IOException, ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 parse();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 Collection<Object> values = _parts.values();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 List<Part> parts = new ArrayList<Part>();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 for (Object o: values)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 List<Part> asList = LazyList.getList(o, false);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 parts.addAll(asList);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 return parts;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 * Get the named Part.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 * @param name
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 * @throws ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 public Part getPart(String name)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 throws IOException, ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 parse();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 return (Part)_parts.getValue(name, 0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 * Parse, if necessary, the multipart stream.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 * @throws ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 protected void parse ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 throws IOException, ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 //have we already parsed the input?
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 if (_parts != null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 return;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 //initialize
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 long total = 0; //keep running total of size of bytes read from input and throw an exception if exceeds MultipartConfigElement._maxRequestSize
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 _parts = new MultiMap<String>();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
399
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 //if its not a multipart request, don't parse it
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
403
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 String contentTypeBoundary = "";
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 int bstart = _contentType.indexOf("boundary=");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 if (bstart >= 0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 int bend = _contentType.indexOf(";", bstart);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 bend = (bend < 0? _contentType.length(): bend);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(bstart,bend), true).trim());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 String boundary="--"+contentTypeBoundary;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
415
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 // Get first boundary
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 String line = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 line=((ReadLineInputStream)_in).readLine();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 catch (IOException e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 LOG.warn("Badly formatted multipart request");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 throw e;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
427
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 if (line == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 throw new IOException("Missing content for multipart request");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
430
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 boolean badFormatLogged = false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 line=line.trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 while (line != null && !line.equals(boundary))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 if (!badFormatLogged)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 LOG.warn("Badly formatted multipart request");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 badFormatLogged = true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 line=((ReadLineInputStream)_in).readLine();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 line=(line==null?line:line.trim());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
443
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 if (line == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 throw new IOException("Missing initial multi part boundary");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
446
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 // Read each part
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 boolean lastPart=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
449
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 outer:while(!lastPart)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 String contentDisposition=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 String contentType=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 String contentTransferEncoding=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 MultiMap<String> headers = new MultiMap<String>();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 while(true)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 line=((ReadLineInputStream)_in).readLine();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 //No more input
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 if(line==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 break outer;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
464
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 // If blank line, end of part headers
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 if("".equals(line))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 break;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 total += line.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
470
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 //get content-disposition and content-type
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 int c=line.indexOf(':',0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 if(c>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 String key=line.substring(0,c).trim().toLowerCase(Locale.ENGLISH);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 String value=line.substring(c+1,line.length()).trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 headers.put(key, value);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 if (key.equalsIgnoreCase("content-disposition"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 contentDisposition=value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 if (key.equalsIgnoreCase("content-type"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 contentType = value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 if(key.equals("content-transfer-encoding"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 contentTransferEncoding=value;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
484
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
487
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 // Extract content-disposition
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 boolean form_data=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 if(contentDisposition==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 throw new IOException("Missing content-disposition");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
494
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 QuotedStringTokenizer tok=new QuotedStringTokenizer(contentDisposition,";", false, true);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 String name=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 String filename=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 while(tok.hasMoreTokens())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 String t=tok.nextToken().trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 String tl=t.toLowerCase(Locale.ENGLISH);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 if(t.startsWith("form-data"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 form_data=true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 else if(tl.startsWith("name="))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 name=value(t, true);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 else if(tl.startsWith("filename="))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 filename=filenameValue(t);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
509
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 // Check disposition
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 if(!form_data)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 //It is valid for reset and submit buttons to have an empty name.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 //If no name is supplied, the browser skips sending the info for that field.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 //However, if you supply the empty string as the name, the browser sends the
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 //field, with name as the empty string. So, only continue this loop if we
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 //have not yet seen a name field.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 if(name==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
524
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 //Have a new Part
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 MultiPart part = new MultiPart(name, filename);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 part.setHeaders(headers);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 part.setContentType(contentType);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 _parts.add(name, part);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 part.open();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 InputStream partInput = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 if ("base64".equalsIgnoreCase(contentTransferEncoding))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 partInput = Base64.getDecoder().wrap(_in);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 else if ("quoted-printable".equalsIgnoreCase(contentTransferEncoding))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 partInput = new FilterInputStream(_in)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 @Override
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 public int read() throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 int c = in.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 if (c >= 0 && c == '=')
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 int hi = in.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 int lo = in.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 if (hi < 0 || lo < 0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 throw new IOException("Unexpected end to quoted-printable byte");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 char[] chars = new char[] { (char)hi, (char)lo };
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 c = Integer.parseInt(new String(chars),16);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 return c;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 };
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 partInput = _in;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 int state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 int c;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 boolean cr=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 boolean lf=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
569
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 // loop for all lines
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 while(true)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 int b=0;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 while((c=(state!=-2)?state:partInput.read())!=-1)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 total ++;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 // look for CR and/or LF
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 if(c==13||c==10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 if(c==13)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 partInput.mark(1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 int tmp=partInput.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 if (tmp!=10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 partInput.reset();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 state=tmp;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 break;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 // Look for boundary
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 if(b>=0&&b<byteBoundary.length&&c==byteBoundary[b])
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 b++;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 // Got a character not part of the boundary, so we don't have the boundary marker.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 // Write out as many chars as we matched, then the char we're looking at.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 if(cr)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 part.write(13);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 if(lf)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 part.write(10);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 cr=lf=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 if(b>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 part.write(byteBoundary,0,b);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 b=-1;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 part.write(c);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 // Check for incomplete boundary match, writing out the chars we matched along the way
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 if((b>0&&b<byteBoundary.length-2)||(b==byteBoundary.length-1))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 if(cr)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 part.write(13);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
624
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 if(lf)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 part.write(10);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
627
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 cr=lf=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 part.write(byteBoundary,0,b);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 b=-1;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 // Boundary match. If we've run out of input or we matched the entire final boundary marker, then this is the last part.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 if(b>0||c==-1)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 if(b==byteBoundary.length)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 lastPart=true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 if(state==10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 break;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 // handle CR LF
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 if(cr)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 part.write(13);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
647
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 if(lf)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 part.write(10);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
650
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 cr=(c==13);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 lf=(c==10||state==10);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 if(state==10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 finally
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 part.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 if (!lastPart)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 throw new IOException("Incomplete parts");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
666
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 private String value(String nameEqualsValue, boolean splitAfterSpace)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 /*
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 String value=nameEqualsValue.substring(nameEqualsValue.indexOf('=')+1).trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 int i=value.indexOf(';');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 if(i>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 value=value.substring(0,i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 if(value.startsWith("\""))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 value=value.substring(1,value.indexOf('"',1));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 else if (splitAfterSpace)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 i=value.indexOf(' ');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 if(i>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 value=value.substring(0,i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 return value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 int idx = nameEqualsValue.indexOf('=');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 String value = nameEqualsValue.substring(idx+1).trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 return QuotedStringTokenizer.unquoteOnly(value);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 private String filenameValue(String nameEqualsValue)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 int idx = nameEqualsValue.indexOf('=');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 String value = nameEqualsValue.substring(idx+1).trim();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
698
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 if (value.matches(".??[a-z,A-Z]\\:\\\\[^\\\\].*"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 //incorrectly escaped IE filenames that have the whole path
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 //we just strip any leading & trailing quotes and leave it as is
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 char first=value.charAt(0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 if (first=='"' || first=='\'')
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 value=value.substring(1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 char last=value.charAt(value.length()-1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 if (last=='"' || last=='\'')
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 value = value.substring(0,value.length()-1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
709
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 return value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 //unquote the string, but allow any backslashes that don't
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 //form a valid escape sequence to remain as many browsers
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 //even on *nix systems will not escape a filename containing
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 //backslashes
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 return QuotedStringTokenizer.unquoteOnly(value, true);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
719 }