3247 changed files with 117989 additions and 96371 deletions
@ -0,0 +1,2 @@ |
|||||||
|
apache commons fileupload https://archive.apache.org/dist/commons/fileupload/source/ |
||||||
|
1.3.3 |
Binary file not shown.
@ -0,0 +1,76 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload; |
||||||
|
|
||||||
|
import java.util.Iterator; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> This class provides support for accessing the headers for a file or form |
||||||
|
* item that was received within a <code>multipart/form-data</code> POST |
||||||
|
* request.</p> |
||||||
|
* |
||||||
|
* @since 1.2.1 |
||||||
|
* |
||||||
|
* @version $Id$ |
||||||
|
*/ |
||||||
|
public interface FileItemHeaders { |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the value of the specified part header as a <code>String</code>. |
||||||
|
* |
||||||
|
* If the part did not include a header of the specified name, this method |
||||||
|
* return <code>null</code>. If there are multiple headers with the same |
||||||
|
* name, this method returns the first header in the item. The header |
||||||
|
* name is case insensitive. |
||||||
|
* |
||||||
|
* @param name a <code>String</code> specifying the header name |
||||||
|
* @return a <code>String</code> containing the value of the requested |
||||||
|
* header, or <code>null</code> if the item does not have a header |
||||||
|
* of that name |
||||||
|
*/ |
||||||
|
String getHeader(String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* Returns all the values of the specified item header as an |
||||||
|
* <code>Iterator</code> of <code>String</code> objects. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* If the item did not include any headers of the specified name, this |
||||||
|
* method returns an empty <code>Iterator</code>. The header name is |
||||||
|
* case insensitive. |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @param name a <code>String</code> specifying the header name |
||||||
|
* @return an <code>Iterator</code> containing the values of the |
||||||
|
* requested header. If the item does not have any headers of |
||||||
|
* that name, return an empty <code>Iterator</code> |
||||||
|
*/ |
||||||
|
Iterator<String> getHeaders(String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* Returns an <code>Iterator</code> of all the header names. |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @return an <code>Iterator</code> containing all of the names of |
||||||
|
* headers provided with this file item. If the item does not have |
||||||
|
* any headers return an empty <code>Iterator</code> |
||||||
|
*/ |
||||||
|
Iterator<String> getHeaderNames(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload; |
||||||
|
|
||||||
|
/** |
||||||
|
* Interface that will indicate that {@link FileItem} or {@link FileItemStream} |
||||||
|
* implementations will accept the headers read for the item. |
||||||
|
* |
||||||
|
* @since 1.2.1 |
||||||
|
* |
||||||
|
* @see FileItem |
||||||
|
* @see FileItemStream |
||||||
|
* |
||||||
|
* @version $Id$ |
||||||
|
*/ |
||||||
|
public interface FileItemHeadersSupport { |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the collection of headers defined locally within this item. |
||||||
|
* |
||||||
|
* @return the {@link FileItemHeaders} present for this item. |
||||||
|
*/ |
||||||
|
FileItemHeaders getHeaders(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets the headers read from within an item. Implementations of |
||||||
|
* {@link FileItem} or {@link FileItemStream} should implement this |
||||||
|
* interface to be able to get the raw headers found within the item |
||||||
|
* header block. |
||||||
|
* |
||||||
|
* @param headers the instance that holds onto the headers |
||||||
|
* for this instance. |
||||||
|
*/ |
||||||
|
void setHeaders(FileItemHeaders headers); |
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,64 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload; |
||||||
|
|
||||||
|
/** |
||||||
|
* This exception is thrown in case of an invalid file name. |
||||||
|
* A file name is invalid, if it contains a NUL character. |
||||||
|
* Attackers might use this to circumvent security checks: |
||||||
|
* For example, a malicious user might upload a file with the name |
||||||
|
* "foo.exe\0.png". This file name might pass security checks (i.e. |
||||||
|
* checks for the extension ".png"), while, depending on the underlying |
||||||
|
* C library, it might create a file named "foo.exe", as the NUL |
||||||
|
* character is the string terminator in C. |
||||||
|
* |
||||||
|
* @version $Id$ |
||||||
|
*/ |
||||||
|
public class InvalidFileNameException extends RuntimeException { |
||||||
|
|
||||||
|
/** |
||||||
|
* Serial version UID, being used, if the exception |
||||||
|
* is serialized. |
||||||
|
*/ |
||||||
|
private static final long serialVersionUID = 7922042602454350470L; |
||||||
|
|
||||||
|
/** |
||||||
|
* The file name causing the exception. |
||||||
|
*/ |
||||||
|
private final String name; |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a new instance. |
||||||
|
* |
||||||
|
* @param pName The file name causing the exception. |
||||||
|
* @param pMessage A human readable error message. |
||||||
|
*/ |
||||||
|
public InvalidFileNameException(String pName, String pMessage) { |
||||||
|
super(pMessage); |
||||||
|
name = pName; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the invalid file name. |
||||||
|
* |
||||||
|
* @return the invalid file name. |
||||||
|
*/ |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload; |
||||||
|
|
||||||
|
/** |
||||||
|
* Enhanced access to the request information needed for file uploads, |
||||||
|
* which fixes the Content Length data access in {@link RequestContext}. |
||||||
|
* |
||||||
|
* The reason of introducing this new interface is just for backward compatibility |
||||||
|
* and it might vanish for a refactored 2.x version moving the new method into |
||||||
|
* RequestContext again. |
||||||
|
* |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
public interface UploadContext extends RequestContext { |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the content length of the request. |
||||||
|
* |
||||||
|
* @return The content length of the request. |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
long contentLength(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* A disk-based implementation of the |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileItem FileItem} |
||||||
|
* interface. This implementation retains smaller items in memory, while |
||||||
|
* writing larger ones to disk. The threshold between these two is |
||||||
|
* configurable, as is the location of files that are written to disk. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* In typical usage, an instance of |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory} |
||||||
|
* would be created, configured, and then passed to a |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} |
||||||
|
* implementation such as |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.servlet.ServletFileUpload ServletFileUpload} |
||||||
|
* or |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.portlet.PortletFileUpload PortletFileUpload}. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* The following code fragment demonstrates this usage. |
||||||
|
* </p> |
||||||
|
* <pre> |
||||||
|
* DiskFileItemFactory factory = new DiskFileItemFactory(); |
||||||
|
* // maximum size that will be stored in memory
|
||||||
|
* factory.setSizeThreshold(4096); |
||||||
|
* // the location for saving data that is larger than getSizeThreshold()
|
||||||
|
* factory.setRepository(new File("/tmp")); |
||||||
|
* |
||||||
|
* ServletFileUpload upload = new ServletFileUpload(factory); |
||||||
|
* </pre> |
||||||
|
* <p> |
||||||
|
* Please see the FileUpload |
||||||
|
* <a href="http://commons.apache.org/fileupload/using.html" target="_top">User Guide</a> |
||||||
|
* for further details and examples of how to use this package. |
||||||
|
* </p> |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.disk; |
@ -1,58 +0,0 @@ |
|||||||
<!-- |
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
contributor license agreements. See the NOTICE file distributed with |
|
||||||
this work for additional information regarding copyright ownership. |
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
(the "License"); you may not use this file except in compliance with |
|
||||||
the License. You may obtain a copy of the License at |
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software |
|
||||||
distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
See the License for the specific language governing permissions and |
|
||||||
limitations under the License. |
|
||||||
--> |
|
||||||
<!-- $Id$ --> |
|
||||||
<html> |
|
||||||
<head> |
|
||||||
<title>Overview of the com.fr.third.org.apache.commons.fileupload.disk component</title> |
|
||||||
</head> |
|
||||||
<body> |
|
||||||
<p> |
|
||||||
A disk-based implementation of the |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.FileItem FileItem} |
|
||||||
interface. This implementation retains smaller items in memory, while |
|
||||||
writing larger ones to disk. The threshold between these two is |
|
||||||
configurable, as is the location of files that are written to disk. |
|
||||||
</p> |
|
||||||
<p> |
|
||||||
In typical usage, an instance of |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory} |
|
||||||
would be created, configured, and then passed to a |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} |
|
||||||
implementation such as |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.servlet.ServletFileUpload ServletFileUpload} |
|
||||||
or |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.portlet.PortletFileUpload PortletFileUpload}. |
|
||||||
</p> |
|
||||||
<p> |
|
||||||
The following code fragment demonstrates this usage. |
|
||||||
</p> |
|
||||||
<pre> |
|
||||||
DiskFileItemFactory factory = new DiskFileItemFactory(); |
|
||||||
// maximum size that will be stored in memory |
|
||||||
factory.setSizeThreshold(4096); |
|
||||||
// the location for saving data that is larger than getSizeThreshold() |
|
||||||
factory.setRepository(new File("/tmp")); |
|
||||||
|
|
||||||
ServletFileUpload upload = new ServletFileUpload(factory); |
|
||||||
</pre> |
|
||||||
<p> |
|
||||||
Please see the FileUpload |
|
||||||
<a href="http://jakarta.apache.org/commons/fileupload/using.html" target="_top">User Guide</a> |
|
||||||
for further details and examples of how to use this package. |
|
||||||
</p> |
|
||||||
</body> |
|
||||||
</html> |
|
@ -0,0 +1,85 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* A component for handling HTML file uploads as specified by |
||||||
|
* <a href="http://www.ietf.org/rfc/rfc1867.txt" target="_top">RFC 1867</a>. |
||||||
|
* This component provides support for uploads within both servlets (JSR 53) |
||||||
|
* and portlets (JSR 168). |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* While this package provides the generic functionality for file uploads, |
||||||
|
* these classes are not typically used directly. Instead, normal usage |
||||||
|
* involves one of the provided extensions of |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} such as |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.servlet.ServletFileUpload ServletFileUpload} |
||||||
|
* or |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.portlet.PortletFileUpload PortletFileUpload}, |
||||||
|
* together with a factory for |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileItem FileItem} instances, |
||||||
|
* such as |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* The following is a brief example of typical usage in a servlet, storing |
||||||
|
* the uploaded files on disk. |
||||||
|
* </p> |
||||||
|
* <pre>public void doPost(HttpServletRequest req, HttpServletResponse res) { |
||||||
|
* DiskFileItemFactory factory = new DiskFileItemFactory(); |
||||||
|
* // maximum size that will be stored in memory
|
||||||
|
* factory.setSizeThreshold(4096); |
||||||
|
* // the location for saving data that is larger than getSizeThreshold()
|
||||||
|
* factory.setRepository(new File("/tmp")); |
||||||
|
* |
||||||
|
* ServletFileUpload upload = new ServletFileUpload(factory); |
||||||
|
* // maximum size before a FileUploadException will be thrown
|
||||||
|
* upload.setSizeMax(1000000); |
||||||
|
* |
||||||
|
* List fileItems = upload.parseRequest(req); |
||||||
|
* // assume we know there are two files. The first file is a small
|
||||||
|
* // text file, the second is unknown and is written to a file on
|
||||||
|
* // the server
|
||||||
|
* Iterator i = fileItems.iterator(); |
||||||
|
* String comment = ((FileItem)i.next()).getString(); |
||||||
|
* FileItem fi = (FileItem)i.next(); |
||||||
|
* // filename on the client
|
||||||
|
* String fileName = fi.getName(); |
||||||
|
* // save comment and filename to database
|
||||||
|
* ... |
||||||
|
* // write the file
|
||||||
|
* fi.write(new File("/www/uploads/", fileName)); |
||||||
|
* } |
||||||
|
* </pre> |
||||||
|
* <p> |
||||||
|
* In the example above, the first file is loaded into memory as a |
||||||
|
* <code>String</code>. Before calling the <code>getString</code> method, |
||||||
|
* the data may have been in memory or on disk depending on its size. The |
||||||
|
* second file we assume it will be large and therefore never explicitly |
||||||
|
* load it into memory, though if it is less than 4096 bytes it will be |
||||||
|
* in memory before it is written to its final location. When writing to |
||||||
|
* the final location, if the data is larger than the threshold, an attempt |
||||||
|
* is made to rename the temporary file to the given location. If it cannot |
||||||
|
* be renamed, it is streamed to the new location. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* Please see the FileUpload |
||||||
|
* <a href="http://commons.apache.org/fileupload/using.html" target="_top">User Guide</a> |
||||||
|
* for further details and examples of how to use this package. |
||||||
|
* </p> |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload; |
@ -1,90 +0,0 @@ |
|||||||
<!-- |
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
contributor license agreements. See the NOTICE file distributed with |
|
||||||
this work for additional information regarding copyright ownership. |
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
(the "License"); you may not use this file except in compliance with |
|
||||||
the License. You may obtain a copy of the License at |
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software |
|
||||||
distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
See the License for the specific language governing permissions and |
|
||||||
limitations under the License. |
|
||||||
--> |
|
||||||
<!-- $Id$ --> |
|
||||||
<html> |
|
||||||
<head> |
|
||||||
<title>Overview of the com.fr.third.org.apache.commons.fileupload component</title> |
|
||||||
</head> |
|
||||||
<body> |
|
||||||
<p> |
|
||||||
A component for handling HTML file uploads as specified by |
|
||||||
<a href="http://www.ietf.org/rfc/rfc1867.txt" target="_top">RFC 1867</a>. |
|
||||||
This component provides support for uploads within both servlets (JSR 53) |
|
||||||
and portlets (JSR 168). |
|
||||||
</p> |
|
||||||
<p> |
|
||||||
While this package provides the generic functionality for file uploads, |
|
||||||
these classes are not typically used directly. Instead, normal usage |
|
||||||
involves one of the provided extensions of |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} such as |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.servlet.ServletFileUpload ServletFileUpload} |
|
||||||
or |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.portlet.PortletFileUpload PortletFileUpload}, |
|
||||||
together with a factory for |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.FileItem FileItem} instances, |
|
||||||
such as |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}. |
|
||||||
</p> |
|
||||||
<p> |
|
||||||
The following is a brief example of typical usage in a servlet, storing |
|
||||||
the uploaded files on disk. |
|
||||||
</p> |
|
||||||
<pre> |
|
||||||
public void doPost(HttpServletRequest req, HttpServletResponse res) { |
|
||||||
DiskFileItemFactory factory = new DiskFileItemFactory(); |
|
||||||
// maximum size that will be stored in memory |
|
||||||
factory.setSizeThreshold(4096); |
|
||||||
// the location for saving data that is larger than getSizeThreshold() |
|
||||||
factory.setRepository(new File("/tmp")); |
|
||||||
|
|
||||||
ServletFileUpload upload = new ServletFileUpload(factory); |
|
||||||
// maximum size before a FileUploadException will be thrown |
|
||||||
upload.setSizeMax(1000000); |
|
||||||
|
|
||||||
List fileItems = upload.parseRequest(req); |
|
||||||
// assume we know there are two files. The first file is a small |
|
||||||
// text file, the second is unknown and is written to a file on |
|
||||||
// the server |
|
||||||
Iterator i = fileItems.iterator(); |
|
||||||
String comment = ((FileItem)i.next()).getString(); |
|
||||||
FileItem fi = (FileItem)i.next(); |
|
||||||
// filename on the client |
|
||||||
String fileName = fi.getName(); |
|
||||||
// save comment and filename to database |
|
||||||
... |
|
||||||
// write the file |
|
||||||
fi.write(new File("/www/uploads/", fileName)); |
|
||||||
} |
|
||||||
</pre> |
|
||||||
<p> |
|
||||||
In the example above, the first file is loaded into memory as a |
|
||||||
<code>String</code>. Before calling the <code>getString</code> method, |
|
||||||
the data may have been in memory or on disk depending on its size. The |
|
||||||
second file we assume it will be large and therefore never explicitly |
|
||||||
load it into memory, though if it is less than 4096 bytes it will be |
|
||||||
in memory before it is written to its final location. When writing to |
|
||||||
the final location, if the data is larger than the threshold, an attempt |
|
||||||
is made to rename the temporary file to the given location. If it cannot |
|
||||||
be renamed, it is streamed to the new location. |
|
||||||
</p> |
|
||||||
<p> |
|
||||||
Please see the FileUpload |
|
||||||
<a href="http://jakarta.apache.org/commons/fileupload/using.html" target="_top">User Guide</a> |
|
||||||
for further details and examples of how to use this package. |
|
||||||
</p> |
|
||||||
</body> |
|
||||||
</html> |
|
@ -0,0 +1,152 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.portlet; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import javax.portlet.ActionRequest; |
||||||
|
|
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileItem; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileItemFactory; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileItemIterator; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileUpload; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileUploadBase; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileUploadException; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.servlet.ServletFileUpload; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p>High level API for processing file uploads.</p> |
||||||
|
* |
||||||
|
* <p>This class handles multiple files per single HTML widget, sent using |
||||||
|
* <code>multipart/mixed</code> encoding type, as specified by |
||||||
|
* <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use |
||||||
|
* {@link ServletFileUpload |
||||||
|
* #parseRequest(javax.servlet.http.HttpServletRequest)} to acquire a list |
||||||
|
* of {@link FileItem FileItems} associated |
||||||
|
* with a given HTML widget.</p> |
||||||
|
* |
||||||
|
* <p>How the data for individual parts is stored is determined by the factory |
||||||
|
* used to create them; a given part may be in memory, on disk, or somewhere |
||||||
|
* else.</p> |
||||||
|
* |
||||||
|
* @since FileUpload 1.1 |
||||||
|
* |
||||||
|
* @version $Id$ |
||||||
|
*/ |
||||||
|
public class PortletFileUpload extends FileUpload { |
||||||
|
|
||||||
|
// ---------------------------------------------------------- Class methods
|
||||||
|
|
||||||
|
/** |
||||||
|
* Utility method that determines whether the request contains multipart |
||||||
|
* content. |
||||||
|
* |
||||||
|
* @param request The portlet request to be evaluated. Must be non-null. |
||||||
|
* |
||||||
|
* @return <code>true</code> if the request is multipart; |
||||||
|
* <code>false</code> otherwise. |
||||||
|
*/ |
||||||
|
public static final boolean isMultipartContent(ActionRequest request) { |
||||||
|
return FileUploadBase.isMultipartContent( |
||||||
|
new PortletRequestContext(request)); |
||||||
|
} |
||||||
|
|
||||||
|
// ----------------------------------------------------------- Constructors
|
||||||
|
|
||||||
|
/** |
||||||
|
* Constructs an uninitialised instance of this class. A factory must be |
||||||
|
* configured, using <code>setFileItemFactory()</code>, before attempting |
||||||
|
* to parse requests. |
||||||
|
* |
||||||
|
* @see FileUpload#FileUpload(FileItemFactory) |
||||||
|
*/ |
||||||
|
public PortletFileUpload() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructs an instance of this class which uses the supplied factory to |
||||||
|
* create <code>FileItem</code> instances. |
||||||
|
* |
||||||
|
* @see FileUpload#FileUpload() |
||||||
|
* @param fileItemFactory The factory to use for creating file items. |
||||||
|
*/ |
||||||
|
public PortletFileUpload(FileItemFactory fileItemFactory) { |
||||||
|
super(fileItemFactory); |
||||||
|
} |
||||||
|
|
||||||
|
// --------------------------------------------------------- Public methods
|
||||||
|
|
||||||
|
/** |
||||||
|
* Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> |
||||||
|
* compliant <code>multipart/form-data</code> stream. |
||||||
|
* |
||||||
|
* @param request The portlet request to be parsed. |
||||||
|
* |
||||||
|
* @return A list of <code>FileItem</code> instances parsed from the |
||||||
|
* request, in the order that they were transmitted. |
||||||
|
* |
||||||
|
* @throws FileUploadException if there are problems reading/parsing |
||||||
|
* the request or storing files. |
||||||
|
*/ |
||||||
|
public List<FileItem> parseRequest(ActionRequest request) |
||||||
|
throws FileUploadException { |
||||||
|
return parseRequest(new PortletRequestContext(request)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> |
||||||
|
* compliant <code>multipart/form-data</code> stream. |
||||||
|
* |
||||||
|
* @param request The portlet request to be parsed. |
||||||
|
* |
||||||
|
* @return A map of <code>FileItem</code> instances parsed from the request. |
||||||
|
* |
||||||
|
* @throws FileUploadException if there are problems reading/parsing |
||||||
|
* the request or storing files. |
||||||
|
* |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
public Map<String, List<FileItem>> parseParameterMap(ActionRequest request) |
||||||
|
throws FileUploadException { |
||||||
|
return parseParameterMap(new PortletRequestContext(request)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> |
||||||
|
* compliant <code>multipart/form-data</code> stream. |
||||||
|
* |
||||||
|
* @param request The portlet request to be parsed. |
||||||
|
* |
||||||
|
* @return An iterator to instances of <code>FileItemStream</code> |
||||||
|
* parsed from the request, in the order that they were |
||||||
|
* transmitted. |
||||||
|
* |
||||||
|
* @throws FileUploadException if there are problems reading/parsing |
||||||
|
* the request or storing files. |
||||||
|
* @throws IOException An I/O error occurred. This may be a network |
||||||
|
* error while communicating with the client or a problem while |
||||||
|
* storing the uploaded content. |
||||||
|
*/ |
||||||
|
public FileItemIterator getItemIterator(ActionRequest request) |
||||||
|
throws FileUploadException, IOException { |
||||||
|
return super.getItemIterator(new PortletRequestContext(request)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,129 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.portlet; |
||||||
|
|
||||||
|
import static java.lang.String.format; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
|
||||||
|
import javax.portlet.ActionRequest; |
||||||
|
|
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileUploadBase; |
||||||
|
import com.fr.third.org.apache.commons.fileupload.UploadContext; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p>Provides access to the request information needed for a request made to |
||||||
|
* a portlet.</p> |
||||||
|
* |
||||||
|
* @since FileUpload 1.1 |
||||||
|
* |
||||||
|
* @version $Id$ |
||||||
|
*/ |
||||||
|
public class PortletRequestContext implements UploadContext { |
||||||
|
|
||||||
|
// ----------------------------------------------------- Instance Variables
|
||||||
|
|
||||||
|
/** |
||||||
|
* The request for which the context is being provided. |
||||||
|
*/ |
||||||
|
private final ActionRequest request; |
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------- Constructors
|
||||||
|
|
||||||
|
/** |
||||||
|
* Construct a context for this request. |
||||||
|
* |
||||||
|
* @param request The request to which this context applies. |
||||||
|
*/ |
||||||
|
public PortletRequestContext(ActionRequest request) { |
||||||
|
this.request = request; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------- Public Methods
|
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the character encoding for the request. |
||||||
|
* |
||||||
|
* @return The character encoding for the request. |
||||||
|
*/ |
||||||
|
public String getCharacterEncoding() { |
||||||
|
return request.getCharacterEncoding(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the content type of the request. |
||||||
|
* |
||||||
|
* @return The content type of the request. |
||||||
|
*/ |
||||||
|
public String getContentType() { |
||||||
|
return request.getContentType(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the content length of the request. |
||||||
|
* |
||||||
|
* @return The content length of the request. |
||||||
|
* @deprecated 1.3 Use {@link #contentLength()} instead |
||||||
|
*/ |
||||||
|
@Deprecated |
||||||
|
public int getContentLength() { |
||||||
|
return request.getContentLength(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the content length of the request. |
||||||
|
* |
||||||
|
* @return The content length of the request. |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
public long contentLength() { |
||||||
|
long size; |
||||||
|
try { |
||||||
|
size = Long.parseLong(request.getProperty(FileUploadBase.CONTENT_LENGTH)); |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
size = request.getContentLength(); |
||||||
|
} |
||||||
|
return size; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the input stream for the request. |
||||||
|
* |
||||||
|
* @return The input stream for the request. |
||||||
|
* |
||||||
|
* @throws IOException if a problem occurs. |
||||||
|
*/ |
||||||
|
public InputStream getInputStream() throws IOException { |
||||||
|
return request.getPortletInputStream(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns a string representation of this object. |
||||||
|
* |
||||||
|
* @return a string representation of this object. |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return format("ContentLength=%s, ContentType=%s", |
||||||
|
Long.valueOf(this.contentLength()), |
||||||
|
this.getContentType()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* An implementation of |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} |
||||||
|
* for use in portlets conforming to JSR 168. This implementation requires |
||||||
|
* only access to the portlet's current <code>ActionRequest</code> instance, |
||||||
|
* and a suitable |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileItemFactory FileItemFactory} |
||||||
|
* implementation, such as |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* The following code fragment demonstrates typical usage. |
||||||
|
* </p> |
||||||
|
* <pre> |
||||||
|
* DiskFileItemFactory factory = new DiskFileItemFactory(); |
||||||
|
* // Configure the factory here, if desired.
|
||||||
|
* PortletFileUpload upload = new PortletFileUpload(factory); |
||||||
|
* // Configure the uploader here, if desired.
|
||||||
|
* List fileItems = upload.parseRequest(request); |
||||||
|
* </pre> |
||||||
|
* <p> |
||||||
|
* Please see the FileUpload |
||||||
|
* <a href="http://commons.apache.org/fileupload/using.html" target="_top">User Guide</a> |
||||||
|
* for further details and examples of how to use this package. |
||||||
|
* </p> |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.portlet; |
@ -0,0 +1,45 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* An implementation of |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} |
||||||
|
* for use in servlets conforming to JSR 53. This implementation requires |
||||||
|
* only access to the servlet's current <code>HttpServletRequest</code> |
||||||
|
* instance, and a suitable |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.FileItemFactory FileItemFactory} |
||||||
|
* implementation, such as |
||||||
|
* {@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}. |
||||||
|
* </p> |
||||||
|
* <p> |
||||||
|
* The following code fragment demonstrates typical usage. |
||||||
|
* </p> |
||||||
|
* <pre> |
||||||
|
* DiskFileItemFactory factory = new DiskFileItemFactory(); |
||||||
|
* // Configure the factory here, if desired.
|
||||||
|
* ServletFileUpload upload = new ServletFileUpload(factory); |
||||||
|
* // Configure the uploader here, if desired.
|
||||||
|
* List fileItems = upload.parseRequest(request); |
||||||
|
* </pre> |
||||||
|
* <p> |
||||||
|
* Please see the FileUpload |
||||||
|
* <a href="http://commons.apache.org/fileupload/using.html" target="_top">User Guide</a> |
||||||
|
* for further details and examples of how to use this package. |
||||||
|
* </p> |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.servlet; |
@ -1,49 +0,0 @@ |
|||||||
<!-- |
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
contributor license agreements. See the NOTICE file distributed with |
|
||||||
this work for additional information regarding copyright ownership. |
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
(the "License"); you may not use this file except in compliance with |
|
||||||
the License. You may obtain a copy of the License at |
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software |
|
||||||
distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
See the License for the specific language governing permissions and |
|
||||||
limitations under the License. |
|
||||||
--> |
|
||||||
<!-- $Id$ --> |
|
||||||
<html> |
|
||||||
<head> |
|
||||||
<title>Overview of the com.fr.third.org.apache.commons.fileupload.servlet component</title> |
|
||||||
</head> |
|
||||||
<body> |
|
||||||
<p> |
|
||||||
An implementation of |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.FileUpload FileUpload} |
|
||||||
for use in servlets conforming to JSR 53. This implementation requires |
|
||||||
only access to the servlet's current <code>HttpServletRequest</code> |
|
||||||
instance, and a suitable |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.FileItemFactory FileItemFactory} |
|
||||||
implementation, such as |
|
||||||
{@link com.fr.third.org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}. |
|
||||||
</p> |
|
||||||
<p> |
|
||||||
The following code fragment demonstrates typical usage. |
|
||||||
</p> |
|
||||||
<pre> |
|
||||||
DiskFileItemFactory factory = new DiskFileItemFactory(); |
|
||||||
// Configure the factory here, if desired. |
|
||||||
ServletFileUpload upload = new ServletFileUpload(factory); |
|
||||||
// Configure the uploader here, if desired. |
|
||||||
List fileItems = upload.parseRequest(request); |
|
||||||
</pre> |
|
||||||
<p> |
|
||||||
Please see the FileUpload |
|
||||||
<a href="http://jakarta.apache.org/commons/fileupload/using.html" target="_top">User Guide</a> |
|
||||||
for further details and examples of how to use this package. |
|
||||||
</p> |
|
||||||
</body> |
|
||||||
</html> |
|
@ -0,0 +1,97 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Locale; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import com.fr.third.org.apache.commons.fileupload.FileItemHeaders; |
||||||
|
|
||||||
|
/** |
||||||
|
* Default implementation of the {@link FileItemHeaders} interface. |
||||||
|
* |
||||||
|
* @since 1.2.1 |
||||||
|
* |
||||||
|
* @version $Id$ |
||||||
|
*/ |
||||||
|
public class FileItemHeadersImpl implements FileItemHeaders, Serializable { |
||||||
|
|
||||||
|
/** |
||||||
|
* Serial version UID, being used, if serialized. |
||||||
|
*/ |
||||||
|
private static final long serialVersionUID = -4455695752627032559L; |
||||||
|
|
||||||
|
/** |
||||||
|
* Map of <code>String</code> keys to a <code>List</code> of |
||||||
|
* <code>String</code> instances. |
||||||
|
*/ |
||||||
|
private final Map<String, List<String>> headerNameToValueListMap = new LinkedHashMap<String, List<String>>(); |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public String getHeader(String name) { |
||||||
|
String nameLower = name.toLowerCase(Locale.ENGLISH); |
||||||
|
List<String> headerValueList = headerNameToValueListMap.get(nameLower); |
||||||
|
if (null == headerValueList) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return headerValueList.get(0); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Iterator<String> getHeaderNames() { |
||||||
|
return headerNameToValueListMap.keySet().iterator(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritDoc} |
||||||
|
*/ |
||||||
|
public Iterator<String> getHeaders(String name) { |
||||||
|
String nameLower = name.toLowerCase(Locale.ENGLISH); |
||||||
|
List<String> headerValueList = headerNameToValueListMap.get(nameLower); |
||||||
|
if (null == headerValueList) { |
||||||
|
headerValueList = Collections.emptyList(); |
||||||
|
} |
||||||
|
return headerValueList.iterator(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Method to add header values to this instance. |
||||||
|
* |
||||||
|
* @param name name of this header |
||||||
|
* @param value value of this header |
||||||
|
*/ |
||||||
|
public synchronized void addHeader(String name, String value) { |
||||||
|
String nameLower = name.toLowerCase(Locale.ENGLISH); |
||||||
|
List<String> headerValueList = headerNameToValueListMap.get(nameLower); |
||||||
|
if (null == headerValueList) { |
||||||
|
headerValueList = new ArrayList<String>(); |
||||||
|
headerNameToValueListMap.put(nameLower, headerValueList); |
||||||
|
} |
||||||
|
headerValueList.add(value); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,152 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util.mime; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.OutputStream; |
||||||
|
|
||||||
|
/** |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
final class Base64Decoder { |
||||||
|
|
||||||
|
/** |
||||||
|
* Decoding table value for invalid bytes. |
||||||
|
*/ |
||||||
|
private static final int INVALID_BYTE = -1; // must be outside range 0-63
|
||||||
|
|
||||||
|
/** |
||||||
|
* Decoding table value for padding bytes, so can detect PAD afer conversion. |
||||||
|
*/ |
||||||
|
private static final int PAD_BYTE = -2; // must be outside range 0-63
|
||||||
|
|
||||||
|
/** |
||||||
|
* Mask to treat byte as unsigned integer. |
||||||
|
*/ |
||||||
|
private static final int MASK_BYTE_UNSIGNED = 0xFF; |
||||||
|
|
||||||
|
/** |
||||||
|
* Number of bytes per encoded chunk - 4 6bit bytes produce 3 8bit bytes on output. |
||||||
|
*/ |
||||||
|
private static final int INPUT_BYTES_PER_CHUNK = 4; |
||||||
|
|
||||||
|
/** |
||||||
|
* Set up the encoding table. |
||||||
|
*/ |
||||||
|
private static final byte[] ENCODING_TABLE = { |
||||||
|
(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', |
||||||
|
(byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N', |
||||||
|
(byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', |
||||||
|
(byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', |
||||||
|
(byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f', (byte) 'g', |
||||||
|
(byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', |
||||||
|
(byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', (byte) 'u', |
||||||
|
(byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', |
||||||
|
(byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', |
||||||
|
(byte) '7', (byte) '8', (byte) '9', |
||||||
|
(byte) '+', (byte) '/' |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* The padding byte. |
||||||
|
*/ |
||||||
|
private static final byte PADDING = (byte) '='; |
||||||
|
|
||||||
|
/** |
||||||
|
* Set up the decoding table; this is indexed by a byte converted to an unsigned int, |
||||||
|
* so must be at least as large as the number of different byte values, |
||||||
|
* positive and negative and zero. |
||||||
|
*/ |
||||||
|
private static final byte[] DECODING_TABLE = new byte[Byte.MAX_VALUE - Byte.MIN_VALUE + 1]; |
||||||
|
|
||||||
|
static { |
||||||
|
// Initialise as all invalid characters
|
||||||
|
for (int i = 0; i < DECODING_TABLE.length; i++) { |
||||||
|
DECODING_TABLE[i] = INVALID_BYTE; |
||||||
|
} |
||||||
|
// set up valid characters
|
||||||
|
for (int i = 0; i < ENCODING_TABLE.length; i++) { |
||||||
|
DECODING_TABLE[ENCODING_TABLE[i]] = (byte) i; |
||||||
|
} |
||||||
|
// Allow pad byte to be easily detected after conversion
|
||||||
|
DECODING_TABLE[PADDING] = PAD_BYTE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Hidden constructor, this class must not be instantiated. |
||||||
|
*/ |
||||||
|
private Base64Decoder() { |
||||||
|
// do nothing
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decode the base 64 encoded byte data writing it to the given output stream, |
||||||
|
* whitespace characters will be ignored. |
||||||
|
* |
||||||
|
* @param data the buffer containing the Base64-encoded data |
||||||
|
* @param out the output stream to hold the decoded bytes |
||||||
|
* |
||||||
|
* @return the number of bytes produced. |
||||||
|
* @throws IOException thrown when the padding is incorrect or the input is truncated. |
||||||
|
*/ |
||||||
|
public static int decode(byte[] data, OutputStream out) throws IOException { |
||||||
|
int outLen = 0; |
||||||
|
byte [] cache = new byte[INPUT_BYTES_PER_CHUNK]; |
||||||
|
int cachedBytes = 0; |
||||||
|
|
||||||
|
for (byte b : data) { |
||||||
|
final byte d = DECODING_TABLE[MASK_BYTE_UNSIGNED & b]; |
||||||
|
if (d == INVALID_BYTE) { |
||||||
|
continue; // Ignore invalid bytes
|
||||||
|
} |
||||||
|
cache[cachedBytes++] = d; |
||||||
|
if (cachedBytes == INPUT_BYTES_PER_CHUNK) { |
||||||
|
// CHECKSTYLE IGNORE MagicNumber FOR NEXT 4 LINES
|
||||||
|
final byte b1 = cache[0]; |
||||||
|
final byte b2 = cache[1]; |
||||||
|
final byte b3 = cache[2]; |
||||||
|
final byte b4 = cache[3]; |
||||||
|
if (b1 == PAD_BYTE || b2 == PAD_BYTE) { |
||||||
|
throw new IOException("Invalid Base64 input: incorrect padding, first two bytes cannot be padding"); |
||||||
|
} |
||||||
|
// Convert 4 6-bit bytes to 3 8-bit bytes
|
||||||
|
// CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
|
||||||
|
out.write((b1 << 2) | (b2 >> 4)); // 6 bits of b1 plus 2 bits of b2
|
||||||
|
outLen++; |
||||||
|
if (b3 != PAD_BYTE) { |
||||||
|
// CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
|
||||||
|
out.write((b2 << 4) | (b3 >> 2)); // 4 bits of b2 plus 4 bits of b3
|
||||||
|
outLen++; |
||||||
|
if (b4 != PAD_BYTE) { |
||||||
|
// CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
|
||||||
|
out.write((b3 << 6) | b4); // 2 bits of b3 plus 6 bits of b4
|
||||||
|
outLen++; |
||||||
|
} |
||||||
|
} else if (b4 != PAD_BYTE) { // if byte 3 is pad, byte 4 must be pad too
|
||||||
|
throw new // line wrap to avoid 120 char limit
|
||||||
|
IOException("Invalid Base64 input: incorrect padding, 4th byte must be padding if 3rd byte is"); |
||||||
|
} |
||||||
|
cachedBytes = 0; |
||||||
|
} |
||||||
|
} |
||||||
|
// Check for anything left over
|
||||||
|
if (cachedBytes != 0) { |
||||||
|
throw new IOException("Invalid Base64 input: truncated"); |
||||||
|
} |
||||||
|
return outLen; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,283 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util.mime; |
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Locale; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Utility class to decode MIME texts. |
||||||
|
* |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
public final class MimeUtility { |
||||||
|
|
||||||
|
/** |
||||||
|
* The {@code US-ASCII} charset identifier constant. |
||||||
|
*/ |
||||||
|
private static final String US_ASCII_CHARSET = "US-ASCII"; |
||||||
|
|
||||||
|
/** |
||||||
|
* The marker to indicate text is encoded with BASE64 algorithm. |
||||||
|
*/ |
||||||
|
private static final String BASE64_ENCODING_MARKER = "B"; |
||||||
|
|
||||||
|
/** |
||||||
|
* The marker to indicate text is encoded with QuotedPrintable algorithm. |
||||||
|
*/ |
||||||
|
private static final String QUOTEDPRINTABLE_ENCODING_MARKER = "Q"; |
||||||
|
|
||||||
|
/** |
||||||
|
* If the text contains any encoded tokens, those tokens will be marked with "=?". |
||||||
|
*/ |
||||||
|
private static final String ENCODED_TOKEN_MARKER = "=?"; |
||||||
|
|
||||||
|
/** |
||||||
|
* If the text contains any encoded tokens, those tokens will terminate with "=?". |
||||||
|
*/ |
||||||
|
private static final String ENCODED_TOKEN_FINISHER = "?="; |
||||||
|
|
||||||
|
/** |
||||||
|
* The linear whitespace chars sequence. |
||||||
|
*/ |
||||||
|
private static final String LINEAR_WHITESPACE = " \t\r\n"; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mappings between MIME and Java charset. |
||||||
|
*/ |
||||||
|
private static final Map<String, String> MIME2JAVA = new HashMap<String, String>(); |
||||||
|
|
||||||
|
static { |
||||||
|
MIME2JAVA.put("iso-2022-cn", "ISO2022CN"); |
||||||
|
MIME2JAVA.put("iso-2022-kr", "ISO2022KR"); |
||||||
|
MIME2JAVA.put("utf-8", "UTF8"); |
||||||
|
MIME2JAVA.put("utf8", "UTF8"); |
||||||
|
MIME2JAVA.put("ja_jp.iso2022-7", "ISO2022JP"); |
||||||
|
MIME2JAVA.put("ja_jp.eucjp", "EUCJIS"); |
||||||
|
MIME2JAVA.put("euc-kr", "KSC5601"); |
||||||
|
MIME2JAVA.put("euckr", "KSC5601"); |
||||||
|
MIME2JAVA.put("us-ascii", "ISO-8859-1"); |
||||||
|
MIME2JAVA.put("x-us-ascii", "ISO-8859-1"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Hidden constructor, this class must not be instantiated. |
||||||
|
*/ |
||||||
|
private MimeUtility() { |
||||||
|
// do nothing
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decode a string of text obtained from a mail header into |
||||||
|
* its proper form. The text generally will consist of a |
||||||
|
* string of tokens, some of which may be encoded using |
||||||
|
* base64 encoding. |
||||||
|
* |
||||||
|
* @param text The text to decode. |
||||||
|
* |
||||||
|
* @return The decoded text string. |
||||||
|
* @throws UnsupportedEncodingException if the detected encoding in the input text is not supported. |
||||||
|
*/ |
||||||
|
public static String decodeText(String text) throws UnsupportedEncodingException { |
||||||
|
// if the text contains any encoded tokens, those tokens will be marked with "=?". If the
|
||||||
|
// source string doesn't contain that sequent, no decoding is required.
|
||||||
|
if (text.indexOf(ENCODED_TOKEN_MARKER) < 0) { |
||||||
|
return text; |
||||||
|
} |
||||||
|
|
||||||
|
int offset = 0; |
||||||
|
int endOffset = text.length(); |
||||||
|
|
||||||
|
int startWhiteSpace = -1; |
||||||
|
int endWhiteSpace = -1; |
||||||
|
|
||||||
|
StringBuilder decodedText = new StringBuilder(text.length()); |
||||||
|
|
||||||
|
boolean previousTokenEncoded = false; |
||||||
|
|
||||||
|
while (offset < endOffset) { |
||||||
|
char ch = text.charAt(offset); |
||||||
|
|
||||||
|
// is this a whitespace character?
|
||||||
|
if (LINEAR_WHITESPACE.indexOf(ch) != -1) { // whitespace found
|
||||||
|
startWhiteSpace = offset; |
||||||
|
while (offset < endOffset) { |
||||||
|
// step over the white space characters.
|
||||||
|
ch = text.charAt(offset); |
||||||
|
if (LINEAR_WHITESPACE.indexOf(ch) != -1) { // whitespace found
|
||||||
|
offset++; |
||||||
|
} else { |
||||||
|
// record the location of the first non lwsp and drop down to process the
|
||||||
|
// token characters.
|
||||||
|
endWhiteSpace = offset; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
// we have a word token. We need to scan over the word and then try to parse it.
|
||||||
|
int wordStart = offset; |
||||||
|
|
||||||
|
while (offset < endOffset) { |
||||||
|
// step over the non white space characters.
|
||||||
|
ch = text.charAt(offset); |
||||||
|
if (LINEAR_WHITESPACE.indexOf(ch) == -1) { // not white space
|
||||||
|
offset++; |
||||||
|
} else { |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
//NB: Trailing whitespace on these header strings will just be discarded.
|
||||||
|
} |
||||||
|
// pull out the word token.
|
||||||
|
String word = text.substring(wordStart, offset); |
||||||
|
// is the token encoded? decode the word
|
||||||
|
if (word.startsWith(ENCODED_TOKEN_MARKER)) { |
||||||
|
try { |
||||||
|
// if this gives a parsing failure, treat it like a non-encoded word.
|
||||||
|
String decodedWord = decodeWord(word); |
||||||
|
|
||||||
|
// are any whitespace characters significant? Append 'em if we've got 'em.
|
||||||
|
if (!previousTokenEncoded && startWhiteSpace != -1) { |
||||||
|
decodedText.append(text.substring(startWhiteSpace, endWhiteSpace)); |
||||||
|
startWhiteSpace = -1; |
||||||
|
} |
||||||
|
// this is definitely a decoded token.
|
||||||
|
previousTokenEncoded = true; |
||||||
|
// and add this to the text.
|
||||||
|
decodedText.append(decodedWord); |
||||||
|
// we continue parsing from here...we allow parsing errors to fall through
|
||||||
|
// and get handled as normal text.
|
||||||
|
continue; |
||||||
|
|
||||||
|
} catch (ParseException e) { |
||||||
|
// just ignore it, skip to next word
|
||||||
|
} |
||||||
|
} |
||||||
|
// this is a normal token, so it doesn't matter what the previous token was. Add the white space
|
||||||
|
// if we have it.
|
||||||
|
if (startWhiteSpace != -1) { |
||||||
|
decodedText.append(text.substring(startWhiteSpace, endWhiteSpace)); |
||||||
|
startWhiteSpace = -1; |
||||||
|
} |
||||||
|
// this is not a decoded token.
|
||||||
|
previousTokenEncoded = false; |
||||||
|
decodedText.append(word); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return decodedText.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse a string using the RFC 2047 rules for an "encoded-word" |
||||||
|
* type. This encoding has the syntax: |
||||||
|
* |
||||||
|
* encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" |
||||||
|
* |
||||||
|
* @param word The possibly encoded word value. |
||||||
|
* |
||||||
|
* @return The decoded word. |
||||||
|
* @throws ParseException |
||||||
|
* @throws UnsupportedEncodingException |
||||||
|
*/ |
||||||
|
private static String decodeWord(String word) throws ParseException, UnsupportedEncodingException { |
||||||
|
// encoded words start with the characters "=?". If this not an encoded word, we throw a
|
||||||
|
// ParseException for the caller.
|
||||||
|
|
||||||
|
if (!word.startsWith(ENCODED_TOKEN_MARKER)) { |
||||||
|
throw new ParseException("Invalid RFC 2047 encoded-word: " + word); |
||||||
|
} |
||||||
|
|
||||||
|
int charsetPos = word.indexOf('?', 2); |
||||||
|
if (charsetPos == -1) { |
||||||
|
throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word); |
||||||
|
} |
||||||
|
|
||||||
|
// pull out the character set information (this is the MIME name at this point).
|
||||||
|
String charset = word.substring(2, charsetPos).toLowerCase(); |
||||||
|
|
||||||
|
// now pull out the encoding token the same way.
|
||||||
|
int encodingPos = word.indexOf('?', charsetPos + 1); |
||||||
|
if (encodingPos == -1) { |
||||||
|
throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word); |
||||||
|
} |
||||||
|
|
||||||
|
String encoding = word.substring(charsetPos + 1, encodingPos); |
||||||
|
|
||||||
|
// and finally the encoded text.
|
||||||
|
int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1); |
||||||
|
if (encodedTextPos == -1) { |
||||||
|
throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word); |
||||||
|
} |
||||||
|
|
||||||
|
String encodedText = word.substring(encodingPos + 1, encodedTextPos); |
||||||
|
|
||||||
|
// seems a bit silly to encode a null string, but easy to deal with.
|
||||||
|
if (encodedText.length() == 0) { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
// the decoder writes directly to an output stream.
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(encodedText.length()); |
||||||
|
|
||||||
|
byte[] encodedData = encodedText.getBytes(US_ASCII_CHARSET); |
||||||
|
|
||||||
|
// Base64 encoded?
|
||||||
|
if (encoding.equals(BASE64_ENCODING_MARKER)) { |
||||||
|
Base64Decoder.decode(encodedData, out); |
||||||
|
} else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted printable.
|
||||||
|
QuotedPrintableDecoder.decode(encodedData, out); |
||||||
|
} else { |
||||||
|
throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding); |
||||||
|
} |
||||||
|
// get the decoded byte data and convert into a string.
|
||||||
|
byte[] decodedData = out.toByteArray(); |
||||||
|
return new String(decodedData, javaCharset(charset)); |
||||||
|
} catch (IOException e) { |
||||||
|
throw new UnsupportedEncodingException("Invalid RFC 2047 encoding"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Translate a MIME standard character set name into the Java |
||||||
|
* equivalent. |
||||||
|
* |
||||||
|
* @param charset The MIME standard name. |
||||||
|
* |
||||||
|
* @return The Java equivalent for this name. |
||||||
|
*/ |
||||||
|
private static String javaCharset(String charset) { |
||||||
|
// nothing in, nothing out.
|
||||||
|
if (charset == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
String mappedCharset = MIME2JAVA.get(charset.toLowerCase(Locale.ENGLISH)); |
||||||
|
// if there is no mapping, then the original name is used. Many of the MIME character set
|
||||||
|
// names map directly back into Java. The reverse isn't necessarily true.
|
||||||
|
if (mappedCharset == null) { |
||||||
|
return charset; |
||||||
|
} |
||||||
|
return mappedCharset; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util.mime; |
||||||
|
|
||||||
|
/** |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
final class ParseException extends Exception { |
||||||
|
|
||||||
|
/** |
||||||
|
* The UID to use when serializing this instance. |
||||||
|
*/ |
||||||
|
private static final long serialVersionUID = 5355281266579392077L; |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructs a new exception with the specified detail message. |
||||||
|
* |
||||||
|
* @param message the detail message. |
||||||
|
*/ |
||||||
|
public ParseException(String message) { |
||||||
|
super(message); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,112 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util.mime; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.OutputStream; |
||||||
|
|
||||||
|
/** |
||||||
|
* @since 1.3 |
||||||
|
*/ |
||||||
|
final class QuotedPrintableDecoder { |
||||||
|
|
||||||
|
/** |
||||||
|
* The shift value required to create the upper nibble |
||||||
|
* from the first of 2 byte values converted from ascii hex. |
||||||
|
*/ |
||||||
|
private static final int UPPER_NIBBLE_SHIFT = Byte.SIZE / 2; |
||||||
|
|
||||||
|
/** |
||||||
|
* Hidden constructor, this class must not be instantiated. |
||||||
|
*/ |
||||||
|
private QuotedPrintableDecoder() { |
||||||
|
// do nothing
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decode the encoded byte data writing it to the given output stream. |
||||||
|
* |
||||||
|
* @param data The array of byte data to decode. |
||||||
|
* @param out The output stream used to return the decoded data. |
||||||
|
* |
||||||
|
* @return the number of bytes produced. |
||||||
|
* @exception IOException |
||||||
|
*/ |
||||||
|
public static int decode(byte[] data, OutputStream out) throws IOException { |
||||||
|
int off = 0; |
||||||
|
int length = data.length; |
||||||
|
int endOffset = off + length; |
||||||
|
int bytesWritten = 0; |
||||||
|
|
||||||
|
while (off < endOffset) { |
||||||
|
byte ch = data[off++]; |
||||||
|
|
||||||
|
// space characters were translated to '_' on encode, so we need to translate them back.
|
||||||
|
if (ch == '_') { |
||||||
|
out.write(' '); |
||||||
|
} else if (ch == '=') { |
||||||
|
// we found an encoded character. Reduce the 3 char sequence to one.
|
||||||
|
// but first, make sure we have two characters to work with.
|
||||||
|
if (off + 1 >= endOffset) { |
||||||
|
throw new IOException("Invalid quoted printable encoding; truncated escape sequence"); |
||||||
|
} |
||||||
|
|
||||||
|
byte b1 = data[off++]; |
||||||
|
byte b2 = data[off++]; |
||||||
|
|
||||||
|
// we've found an encoded carriage return. The next char needs to be a newline
|
||||||
|
if (b1 == '\r') { |
||||||
|
if (b2 != '\n') { |
||||||
|
throw new IOException("Invalid quoted printable encoding; CR must be followed by LF"); |
||||||
|
} |
||||||
|
// this was a soft linebreak inserted by the encoding. We just toss this away
|
||||||
|
// on decode.
|
||||||
|
} else { |
||||||
|
// this is a hex pair we need to convert back to a single byte.
|
||||||
|
int c1 = hexToBinary(b1); |
||||||
|
int c2 = hexToBinary(b2); |
||||||
|
out.write((c1 << UPPER_NIBBLE_SHIFT) | c2); |
||||||
|
// 3 bytes in, one byte out
|
||||||
|
bytesWritten++; |
||||||
|
} |
||||||
|
} else { |
||||||
|
// simple character, just write it out.
|
||||||
|
out.write(ch); |
||||||
|
bytesWritten++; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return bytesWritten; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Convert a hex digit to the binary value it represents. |
||||||
|
* |
||||||
|
* @param b the ascii hex byte to convert (0-0, A-F, a-f) |
||||||
|
* @return the int value of the hex byte, 0-15 |
||||||
|
* @throws IOException if the byte is not a valid hex digit. |
||||||
|
*/ |
||||||
|
private static int hexToBinary(final byte b) throws IOException { |
||||||
|
// CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
|
||||||
|
final int i = Character.digit((char) b, 16); |
||||||
|
if (i == -1) { |
||||||
|
throw new IOException("Invalid quoted printable encoding: not a valid hex digit: " + b); |
||||||
|
} |
||||||
|
return i; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* MIME decoder implementation, imported and retailed from |
||||||
|
* <a href="http://svn.apache.org/repos/asf/geronimo/specs/tags/geronimo-javamail_1.4_spec-1.4/">Apache Geronimo</a>. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util.mime; |
@ -0,0 +1,23 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
* (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* This package contains various IO related utility classes |
||||||
|
* or methods, which are basically reusable and not necessarily |
||||||
|
* restricted to the scope of a file upload. |
||||||
|
*/ |
||||||
|
package com.fr.third.org.apache.commons.fileupload.util; |
@ -1,29 +0,0 @@ |
|||||||
<!-- |
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more |
|
||||||
contributor license agreements. See the NOTICE file distributed with |
|
||||||
this work for additional information regarding copyright ownership. |
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0 |
|
||||||
(the "License"); you may not use this file except in compliance with |
|
||||||
the License. You may obtain a copy of the License at |
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0 |
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software |
|
||||||
distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
See the License for the specific language governing permissions and |
|
||||||
limitations under the License. |
|
||||||
--> |
|
||||||
<!-- $Id: package.html 479262 2006-11-26 03:09:24Z niallp $ --> |
|
||||||
<html> |
|
||||||
<head> |
|
||||||
<title>Overview of the com.fr.third.org.apache.commons.fileupload.util component</title> |
|
||||||
</head> |
|
||||||
<body> |
|
||||||
<p> |
|
||||||
This package contains various IO related utility classes |
|
||||||
or methods, which are basically reusable and not necessarily |
|
||||||
restricted to the scope of a file upload. |
|
||||||
</p> |
|
||||||
</body> |
|
||||||
</html> |
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue