annotate src/org/eclipse/jetty/util/MultiPartInputStream.java @ 848:22a4e93ed20e

remove Container
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 19 Sep 2016 16:38:36 -0600
parents 7fb7c1915788
children 3dcc52e17535
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.MultipartConfigElement;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 import javax.servlet.http.Part;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 import org.slf4j.LoggerFactory;
802
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 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 * MultiPartInputStream
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 * 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
59 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 public class MultiPartInputStream
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 {
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 private static final Logger LOG = LoggerFactory.getLogger(MultiPartInputStream.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 public static final MultipartConfigElement __DEFAULT_MULTIPART_CONFIG = new MultipartConfigElement(System.getProperty("java.io.tmpdir"));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 protected InputStream _in;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 protected MultipartConfigElement _config;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 protected String _contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 protected MultiMap<String> _parts;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 protected File _tmpDir;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 protected File _contextTmpDir;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 protected boolean _deleteOnExit;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 public class MultiPart implements Part
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 protected String _name;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 protected String _filename;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 protected File _file;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 protected OutputStream _out;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 protected ByteArrayOutputStream2 _bout;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 protected String _contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 protected MultiMap<String> _headers;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 protected long _size = 0;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 protected boolean _temporary = true;
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 public MultiPart (String name, String filename)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 _name = name;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 _filename = filename;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 protected void setContentType (String contentType)
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 _contentType = contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 protected void open()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 throws IOException
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 //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
104 //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
105 //will need to change to write to a file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 if (_filename != null && _filename.trim().length() > 0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 createFile();
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 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 //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
113 //MultipartConfig fileSizeThreshold
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 _out = _bout= new ByteArrayOutputStream2();
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 close()
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.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 }
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 (int b)
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 if (MultiPartInputStream.this._config.getMaxFileSize() > 0 && _size + 1 > MultiPartInputStream.this._config.getMaxFileSize())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 throw new IllegalStateException ("Multipart Mime part "+_name+" exceeds max filesize");
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 if (MultiPartInputStream.this._config.getFileSizeThreshold() > 0 && _size + 1 > MultiPartInputStream.this._config.getFileSizeThreshold() && _file==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 createFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 _out.write(b);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 _size ++;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 protected void write (byte[] bytes, int offset, int length)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 throws IOException
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 (MultiPartInputStream.this._config.getMaxFileSize() > 0 && _size + length > MultiPartInputStream.this._config.getMaxFileSize())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 throw new IllegalStateException ("Multipart Mime part "+_name+" exceeds max filesize");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 if (MultiPartInputStream.this._config.getFileSizeThreshold() > 0 && _size + length > MultiPartInputStream.this._config.getFileSizeThreshold() && _file==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 createFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 _out.write(bytes, offset, length);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 _size += length;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 }
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 protected void createFile ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 throws IOException
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 _file = File.createTempFile("MultiPart", "", MultiPartInputStream.this._tmpDir);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 if (_deleteOnExit)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 _file.deleteOnExit();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 FileOutputStream fos = new FileOutputStream(_file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 BufferedOutputStream bos = new BufferedOutputStream(fos);
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 if (_size > 0 && _out != null)
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 //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
162 _out.flush();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 _bout.writeTo(bos);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 _out.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 _bout = null;
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 _out = bos;
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
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 protected void setHeaders(MultiMap<String> headers)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 _headers = headers;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 }
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 * @see javax.servlet.http.Part#getContentType()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 public String getContentType()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 return _contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 * @see javax.servlet.http.Part#getHeader(java.lang.String)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 public String getHeader(String name)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 if (name == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 return (String)_headers.getValue(name.toLowerCase(Locale.ENGLISH), 0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 * @see javax.servlet.http.Part#getHeaderNames()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 public Collection<String> getHeaderNames()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 return _headers.keySet();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202
825
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 * @see javax.servlet.http.Part#getHeaders(java.lang.String)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 public Collection<String> getHeaders(String name)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 return _headers.getValues(name);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 * @see javax.servlet.http.Part#getInputStream()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 public InputStream getInputStream() throws IOException
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 if (_file != null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 //written to a file, whether temporary or not
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 return new BufferedInputStream (new FileInputStream(_file));
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 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 //part content is in memory
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 return new ByteArrayInputStream(_bout.getBuf(),0,_bout.size());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 public byte[] getBytes()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 if (_bout!=null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 return _bout.toByteArray();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 }
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 * @see javax.servlet.http.Part#getName()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 public String getName()
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 return _name;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
242
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 * @see javax.servlet.http.Part#getSize()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 public long getSize()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 return _size;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
250
825
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 * @see javax.servlet.http.Part#write(java.lang.String)
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 public void write(String fileName) 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 if (_file == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 _temporary = false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 //part data is only in the ByteArrayOutputStream and never been written to disk
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 _file = new File (_tmpDir, fileName);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 BufferedOutputStream bos = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 bos = new BufferedOutputStream(new FileOutputStream(_file));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 _bout.writeTo(bos);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 bos.flush();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 finally
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 if (bos != null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 bos.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 _bout = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 }
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 else
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 //the part data is already written to a temporary file, just rename it
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 _temporary = false;
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 File f = new File(_tmpDir, fileName);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 if (_file.renameTo(f))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 _file = f;
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 * 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
290 * (ie no longer temporary)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 * @see javax.servlet.http.Part#delete()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 public void delete() throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 if (_file != null && _file.exists())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 _file.delete();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 }
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 * Only remove tmp files.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 public void cleanUp() throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 if (_temporary && _file != null && _file.exists())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 _file.delete();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310
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 * 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
313 * @return
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 public File getFile ()
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 return _file;
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
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 * Get the filename from the content-disposition.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 * @return null or the filename
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 public String getContentDispositionFilename ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 return _filename;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 }
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
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
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 * @param in Request input stream
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 * @param contentType Content-Type header
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 * @param config MultipartConfigElement
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 * @param contextTmpDir javax.servlet.context.tempdir
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 public MultiPartInputStream (InputStream in, String contentType, MultipartConfigElement config, File contextTmpDir)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 _in = new ReadLineInputStream(in);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 _contentType = contentType;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 _config = config;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 _contextTmpDir = contextTmpDir;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 if (_contextTmpDir == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 _contextTmpDir = new File (System.getProperty("java.io.tmpdir"));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 if (_config == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 _config = new MultipartConfigElement(_contextTmpDir.getAbsolutePath());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
352
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 * Get the already parsed parts.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 public Collection<Part> getParsedParts()
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 if (_parts == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 return Collections.emptyList();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
362
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 Collection<Object> values = _parts.values();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 List<Part> parts = new ArrayList<Part>();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 for (Object o: values)
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 List<Part> asList = LazyList.getList(o, false);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 parts.addAll(asList);
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 return parts;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 * 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
375 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 * @throws MultiException
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 public void deleteParts ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 throws MultiException
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 Collection<Part> parts = getParsedParts();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 MultiException err = new MultiException();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 for (Part p:parts)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 ((MultiPartInputStream.MultiPart)p).cleanUp();
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 catch(Exception e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 err.add(e);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 _parts.clear();
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 err.ifExceptionThrowMulti();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
398
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 * 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
402 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 * @throws ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 public Collection<Part> getParts()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 throws IOException, ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 parse();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 Collection<Object> values = _parts.values();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 List<Part> parts = new ArrayList<Part>();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 for (Object o: values)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 List<Part> asList = LazyList.getList(o, false);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 parts.addAll(asList);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 return parts;
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
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 * Get the named Part.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 * @param name
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 * @throws ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 public Part getPart(String name)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 throws IOException, ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 parse();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 return (Part)_parts.getValue(name, 0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 }
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 * Parse, if necessary, the multipart stream.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 * @throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 * @throws ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 protected void parse ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 throws IOException, ServletException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 //have we already parsed the input?
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 if (_parts != null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 return;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 //initialize
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 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
453 _parts = new MultiMap<String>();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
454
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 //if its not a multipart request, don't parse it
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
458
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 //sort out the location to which to write the files
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 if (_config.getLocation() == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 _tmpDir = _contextTmpDir;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 else if ("".equals(_config.getLocation()))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 _tmpDir = _contextTmpDir;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 File f = new File (_config.getLocation());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 if (f.isAbsolute())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 _tmpDir = f;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 _tmpDir = new File (_contextTmpDir, _config.getLocation());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 if (!_tmpDir.exists())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 _tmpDir.mkdirs();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
476
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 String contentTypeBoundary = "";
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 int bstart = _contentType.indexOf("boundary=");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 if (bstart >= 0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 int bend = _contentType.indexOf(";", bstart);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 bend = (bend < 0? _contentType.length(): bend);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(bstart,bend), true).trim());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 }
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 String boundary="--"+contentTypeBoundary;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
488
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 // Get first boundary
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 String line = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 line=((ReadLineInputStream)_in).readLine();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 catch (IOException e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 LOG.warn("Badly formatted multipart request");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 throw e;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
500
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 if (line == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 throw new IOException("Missing content for multipart request");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
503
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 boolean badFormatLogged = false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 line=line.trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 while (line != null && !line.equals(boundary))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 if (!badFormatLogged)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 LOG.warn("Badly formatted multipart request");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 badFormatLogged = true;
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 line=((ReadLineInputStream)_in).readLine();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 line=(line==null?line:line.trim());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
516
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 if (line == null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 throw new IOException("Missing initial multi part boundary");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
519
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 // Read each part
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 boolean lastPart=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
522
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 outer:while(!lastPart)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 String contentDisposition=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 String contentType=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 String contentTransferEncoding=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 MultiMap<String> headers = new MultiMap<String>();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 while(true)
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 line=((ReadLineInputStream)_in).readLine();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 //No more input
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 if(line==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 break outer;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
537
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 // If blank line, end of part headers
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 if("".equals(line))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 break;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 total += line.length();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 if (_config.getMaxRequestSize() > 0 && total > _config.getMaxRequestSize())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 throw new IllegalStateException ("Request exceeds maxRequestSize ("+_config.getMaxRequestSize()+")");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
545
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 //get content-disposition and content-type
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 int c=line.indexOf(':',0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 if(c>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 String key=line.substring(0,c).trim().toLowerCase(Locale.ENGLISH);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 String value=line.substring(c+1,line.length()).trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 headers.put(key, value);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 if (key.equalsIgnoreCase("content-disposition"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 contentDisposition=value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 if (key.equalsIgnoreCase("content-type"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 contentType = value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 if(key.equals("content-transfer-encoding"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 contentTransferEncoding=value;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
559
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
562
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 // Extract content-disposition
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 boolean form_data=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 if(contentDisposition==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 throw new IOException("Missing content-disposition");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 }
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 QuotedStringTokenizer tok=new QuotedStringTokenizer(contentDisposition,";", false, true);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 String name=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 String filename=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 while(tok.hasMoreTokens())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 String t=tok.nextToken().trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 String tl=t.toLowerCase(Locale.ENGLISH);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 if(t.startsWith("form-data"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 form_data=true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 else if(tl.startsWith("name="))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 name=value(t, true);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 else if(tl.startsWith("filename="))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 filename=filenameValue(t);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
584
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 // Check disposition
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 if(!form_data)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 //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
591 //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
592 //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
593 //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
594 //have not yet seen a name field.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 if(name==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
599
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 //Have a new Part
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 MultiPart part = new MultiPart(name, filename);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 part.setHeaders(headers);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 part.setContentType(contentType);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 _parts.add(name, part);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 part.open();
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 InputStream partInput = null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 if ("base64".equalsIgnoreCase(contentTransferEncoding))
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 partInput = Base64.getDecoder().wrap(_in);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 else if ("quoted-printable".equalsIgnoreCase(contentTransferEncoding))
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 partInput = new FilterInputStream(_in)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 @Override
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 public int read() throws IOException
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 int c = in.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 if (c >= 0 && c == '=')
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 int hi = in.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 int lo = in.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 if (hi < 0 || lo < 0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 throw new IOException("Unexpected end to quoted-printable byte");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 char[] chars = new char[] { (char)hi, (char)lo };
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 c = Integer.parseInt(new String(chars),16);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 return c;
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 };
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 partInput = _in;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 int state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 int c;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 boolean cr=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 boolean lf=false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
644
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 // loop for all lines
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 while(true)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 int b=0;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 while((c=(state!=-2)?state:partInput.read())!=-1)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 total ++;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 if (_config.getMaxRequestSize() > 0 && total > _config.getMaxRequestSize())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 throw new IllegalStateException("Request exceeds maxRequestSize ("+_config.getMaxRequestSize()+")");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 state=-2;
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 // look for CR and/or LF
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 if(c==13||c==10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 if(c==13)
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 partInput.mark(1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 int tmp=partInput.read();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 if (tmp!=10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 partInput.reset();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 state=tmp;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 break;
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 // Look for boundary
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 if(b>=0&&b<byteBoundary.length&&c==byteBoundary[b])
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 b++;
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 else
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 // 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
680 // 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
681 if(cr)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 part.write(13);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 if(lf)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 part.write(10);
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 cr=lf=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 if(b>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 part.write(byteBoundary,0,b);
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 b=-1;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 part.write(c);
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 }
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 // 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
697 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
698 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 if(cr)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 part.write(13);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
701
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 if(lf)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 part.write(10);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
704
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 cr=lf=false;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 part.write(byteBoundary,0,b);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 b=-1;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 // 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
711 if(b>0||c==-1)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 if(b==byteBoundary.length)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 lastPart=true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 if(state==10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 break;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 // handle CR LF
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 if(cr)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 part.write(13);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
724
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 if(lf)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 part.write(10);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
727
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 cr=(c==13);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 lf=(c==10||state==10);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 if(state==10)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 state=-2;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 finally
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 part.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 if (!lastPart)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 throw new IOException("Incomplete parts");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 public void setDeleteOnExit(boolean deleteOnExit)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 _deleteOnExit = deleteOnExit;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
747
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
748
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 public boolean isDeleteOnExit()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
751 return _deleteOnExit;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
753
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
754
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 private String value(String nameEqualsValue, boolean splitAfterSpace)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 /*
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 String value=nameEqualsValue.substring(nameEqualsValue.indexOf('=')+1).trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 int i=value.indexOf(';');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 if(i>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
762 value=value.substring(0,i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 if(value.startsWith("\""))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 value=value.substring(1,value.indexOf('"',1));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 else if (splitAfterSpace)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 i=value.indexOf(' ');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 if(i>0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 value=value.substring(0,i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 return value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 int idx = nameEqualsValue.indexOf('=');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 String value = nameEqualsValue.substring(idx+1).trim();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 return QuotedStringTokenizer.unquoteOnly(value);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 private String filenameValue(String nameEqualsValue)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 int idx = nameEqualsValue.indexOf('=');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 String value = nameEqualsValue.substring(idx+1).trim();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
786
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 if (value.matches(".??[a-z,A-Z]\\:\\\\[^\\\\].*"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 //incorrectly escaped IE filenames that have the whole path
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
790 //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
791 char first=value.charAt(0);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 if (first=='"' || first=='\'')
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 value=value.substring(1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
794 char last=value.charAt(value.length()-1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 if (last=='"' || last=='\'')
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 value = value.substring(0,value.length()-1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
797
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
798 return value;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 //unquote the string, but allow any backslashes that don't
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 //form a valid escape sequence to remain as many browsers
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
803 //even on *nix systems will not escape a filename containing
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
804 //backslashes
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 return QuotedStringTokenizer.unquoteOnly(value, true);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
807 }