forked from playframework/play1
-
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.
Extract body from more text-based content types
- Loading branch information
1 parent
f342c3c
commit ac01598
Showing
3 changed files
with
36 additions
and
20 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
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,28 @@ | ||
package play.data.parsing; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import play.exceptions.UnexpectedException; | ||
|
||
public class TextParser extends DataParser { | ||
|
||
@Override | ||
public Map<String, String[]> parse(InputStream is) { | ||
try { | ||
Map<String, String[]> params = new HashMap<String, String[]>(); | ||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
int b; | ||
while ((b = is.read()) != -1) { | ||
os.write(b); | ||
} | ||
byte[] data = os.toByteArray(); | ||
params.put("body", new String[] {new String(data, "utf-8")}); | ||
return params; | ||
} catch (Exception e) { | ||
throw new UnexpectedException(e); | ||
} | ||
} | ||
|
||
} |
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