play.data.parsing.TextParser Maven / Gradle / Ivy
package play.data.parsing;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import play.exceptions.UnexpectedException;
import play.mvc.Http;
public class TextParser extends DataParser {
@Override
public Map parse(InputStream is) {
try {
Map params = new HashMap();
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, Http.Request.current().encoding)});
return params;
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
}