All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.data.parsing.TextParser Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
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);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy