Package yalp.data.parsing

Source Code of yalp.data.parsing.TextParser

package yalp.data.parsing;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import yalp.exceptions.UnexpectedException;
import yalp.mvc.Http;

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, Http.Request.current().encoding)});
            return params;
        } catch (Exception e) {
            throw new UnexpectedException(e);
        }
    }

}
TOP

Related Classes of yalp.data.parsing.TextParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.