forked from NanoHttpd/nanohttpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'originalMaster' of https://github.com/vnnv/nanohttpd in…
…to vnnv-originalMaster Conflicts: pom.xml
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<artifactId>nanohttpd-project</artifactId> | ||
<groupId>org.nanohttpd</groupId> | ||
<version>2.2.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>apache-fileupload-integration</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.nanohttpd</groupId> | ||
<artifactId>nanohttpd</artifactId> | ||
<version>2.2.0-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-fileupload</groupId> | ||
<artifactId>commons-fileupload</artifactId> | ||
<version>1.3.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- this is just to pass the compilation. Servlets are not used in NanoHTTPD --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
89 changes: 89 additions & 0 deletions
89
fileupload/src/main/java/fi/iki/elonen/NanoFileUpload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package fi.iki.elonen; | ||
|
||
import org.apache.commons.fileupload.FileItem; | ||
import org.apache.commons.fileupload.FileItemFactory; | ||
import org.apache.commons.fileupload.FileItemIterator; | ||
import org.apache.commons.fileupload.FileUpload; | ||
import org.apache.commons.fileupload.FileUploadBase; | ||
import org.apache.commons.fileupload.FileUploadException; | ||
import org.apache.commons.fileupload.UploadContext; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by victor on 7/30/15. | ||
*/ | ||
public class NanoFileUpload extends FileUpload { | ||
|
||
public static class NanoHttpdContext implements UploadContext { | ||
|
||
private NanoHTTPD.IHTTPSession session; | ||
|
||
public NanoHttpdContext(NanoHTTPD.IHTTPSession session) { | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public long contentLength() { | ||
long size; | ||
try { | ||
String cl1 = session.getHeaders().get("content-length"); | ||
size = Long.parseLong(cl1); | ||
} catch (NumberFormatException var4) { | ||
size = -1L; | ||
} | ||
|
||
return size; | ||
} | ||
|
||
@Override | ||
public String getCharacterEncoding() { | ||
return "UTF-8"; | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return this.session.getHeaders().get("content-type"); | ||
} | ||
|
||
@Override | ||
public int getContentLength() { | ||
return (int)contentLength(); | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() throws IOException { | ||
return session.getInputStream(); | ||
} | ||
} | ||
|
||
private static final String POST_METHOD = "POST"; | ||
|
||
public static final boolean isMultipartContent(NanoHTTPD.IHTTPSession session) { | ||
return !"POST".equalsIgnoreCase(session.getMethod().toString()) | ||
? false: FileUploadBase.isMultipartContent(new NanoHttpdContext(session)); | ||
} | ||
|
||
public NanoFileUpload() { | ||
} | ||
|
||
public NanoFileUpload(FileItemFactory fileItemFactory) { | ||
super(fileItemFactory); | ||
} | ||
|
||
public List<FileItem> parseRequest(NanoHTTPD.IHTTPSession session) throws FileUploadException { | ||
return this.parseRequest(new NanoHttpdContext(session)); | ||
} | ||
|
||
public Map<String, List<FileItem>> parseParameterMap(NanoHTTPD.IHTTPSession session) throws FileUploadException { | ||
return this.parseParameterMap(new NanoHttpdContext(session)); | ||
} | ||
|
||
public FileItemIterator getItemIterator(NanoHTTPD.IHTTPSession session) throws FileUploadException, IOException { | ||
return super.getItemIterator(new NanoHttpdContext(session)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters