Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.json.other.server;
 
 
 
    private static final int BUFF_LENGTH = 1024;
    private final HttpServletRequest req;
    private final HttpServletResponse resp;
        this. = req;
        this. = resp;
    }
    public String readRequest() throws Exception {
        InputStream in = null;
        try {
            in = .getInputStream();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buff = new byte[];
            int n;
            while ((n = in.read(buff)) > 0) {
                bos.write(buff, 0, n);
            }
            return bos.toString();
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
    public void writeResponse(String responseDatathrows Exception {
        byte[] data = responseData.getBytes(.getCharacterEncoding());
        .addHeader("Content-Type""application/json");
        .setHeader("Content-Length", Integer.toString(data.length));
        PrintWriter out = null;
        try {
            out = .getWriter();
            out.write(responseData);
            out.flush();
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }
New to GrepCode? Check out our FAQ X