Example usage for java.net URLConnection getDoOutput

List of usage examples for java.net URLConnection getDoOutput

Introduction

In this page you can find the example usage for java.net URLConnection getDoOutput.

Prototype

public boolean getDoOutput() 

Source Link

Document

Returns the value of this URLConnection 's doOutput flag.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getDoOutput());
}

From source file:com.senseidb.servlet.AbstractSenseiClientServlet.java

private void handleJMXRequest(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    InputStream is = null;//from ww w .  j av a2  s.  com
    OutputStream os = null;
    try {
        String myPath = req.getRequestURI().substring(req.getServletPath().length() + 11);
        URL adminUrl = null;
        if (myPath.indexOf('/') > 0) {
            adminUrl = new URL(
                    new StringBuilder(URLDecoder.decode(myPath.substring(0, myPath.indexOf('/')), "UTF-8"))
                            .append("/admin/jmx").append(myPath.substring(myPath.indexOf('/'))).toString());
        } else {
            adminUrl = new URL(
                    new StringBuilder(URLDecoder.decode(myPath, "UTF-8")).append("/admin/jmx").toString());
        }

        URLConnection conn = adminUrl.openConnection();

        byte[] buffer = new byte[8192]; // 8k
        int len = 0;

        InputStream ris = req.getInputStream();

        while ((len = ris.read(buffer)) > 0) {
            if (!conn.getDoOutput()) {
                conn.setDoOutput(true);
                os = conn.getOutputStream();
            }
            os.write(buffer, 0, len);
        }
        if (os != null)
            os.flush();

        is = conn.getInputStream();
        OutputStream ros = resp.getOutputStream();

        while ((len = is.read(buffer)) > 0) {
            ros.write(buffer, 0, len);
        }
        ros.flush();
    } catch (Exception e) {
        throw new ServletException(e.getMessage(), e);
    } finally {
        if (is != null)
            is.close();
        if (os != null)
            os.close();
    }
}