Example usage for java.net HttpURLConnection getOutputStream

List of usage examples for java.net HttpURLConnection getOutputStream

Introduction

In this page you can find the example usage for java.net HttpURLConnection getOutputStream.

Prototype

public OutputStream getOutputStream() throws IOException 

Source Link

Document

Returns an output stream that writes to this connection.

Usage

From source file:me.prokopyl.commandtools.migration.UUIDFetcher.java

private static void writeBody(HttpURLConnection connection, List<String> names) throws IOException {
    OutputStream stream = connection.getOutputStream();
    String body = JSONArray.toJSONString(names);
    stream.write(body.getBytes());//w  ww  . j  a  va  2 s.c o  m
    stream.flush();
    stream.close();
}

From source file:com.codelanx.playtime.callable.UUIDFetcher.java

private static void writeBody(HttpURLConnection connection, String body) throws Exception {
    OutputStream stream = connection.getOutputStream();
    stream.write(body.getBytes());//ww w. j  av  a  2s .  c  o  m
    stream.flush();
    stream.close();
}

From source file:com.cnaude.mutemanager.UUIDFetcher.java

private static void writeBody(HttpURLConnection connection, String body) throws Exception {
    try (OutputStream stream = connection.getOutputStream()) {
        stream.write(body.getBytes());//from  w  ww .  j  a  v  a 2  s  .co m
        stream.flush();
    }
}

From source file:me.sonarbeserk.lockup.utils.UUIDFetcher.java

private static void writeBody(HttpURLConnection connection, String body) throws Exception {
    DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
    writer.write(body.getBytes());//from   w w  w. j av a  2  s  .  c  o m
    writer.flush();
    writer.close();
}

From source file:com.intellectualcrafters.plot.uuid.UUIDFetcher.java

private static void writeBody(final HttpURLConnection connection, final String body) throws Exception {
    final OutputStream stream = connection.getOutputStream();
    stream.write(body.getBytes());//  w w  w. j ava 2  s  .  co  m
    stream.flush();
    stream.close();
}

From source file:Main.java

public static String uploadFile(String filePath, String requestURL) {

    String result = "";
    File file = new File(filePath);

    try {/*from   w w w.  jav  a 2  s.  c o  m*/
        HttpURLConnection connection = initHttpURLConn(requestURL);

        if (filePath != null) {
            DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
            StringBuffer sb = new StringBuffer();
            InputStream is = new FileInputStream(filePath);
            byte[] bytes = new byte[1024];
            int len = 0;
            while ((len = is.read(bytes)) != -1) {
                dos.write(bytes, 0, len);
            }
            dos.flush();
            is.close();
            int res = connection.getResponseCode();
            Log.e(TAG, "response code:" + res);
            if (res == 200) {
                Log.e(TAG, "request success");
                InputStream input = connection.getInputStream();
                StringBuffer sb1 = new StringBuffer();
                int ss;
                while ((ss = input.read()) != -1) {
                    sb1.append((char) ss);
                }

                result = sb1.toString();
                Log.d(TAG, "result: " + result);

                input.close();
            }
        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return result;

}

From source file:it.unicaradio.android.gcm.GcmServerRpcCall.java

/**
 * @param bytes/*w  w  w .  j  a v  a 2 s  .  c  o  m*/
 * @param conn
 * @throws IOException
 */
private static void postRequest(HttpURLConnection conn, byte[] bytes) throws IOException {
    OutputStream out = conn.getOutputStream();
    out.write(bytes);
    out.close();
}

From source file:org.esupportail.twitter.services.OAuthTwitterApplicationOnlyService.java

private static boolean writeRequest(HttpURLConnection connection, String textBody) {
    try {/*  ww  w .  j  a  v a2 s . co  m*/
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
        wr.write(textBody);
        wr.flush();
        wr.close();

        return true;
    } catch (IOException e) {
        return false;
    }
}

From source file:com.flexdesktop.connections.restfulConnection.java

public static void postRequest(HttpURLConnection connection, String data) {
    DataOutputStream wr = null;//from w w  w .  j  av a  2  s  .c om
    try {
        wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(data);
        wr.flush();
        wr.close();
    } catch (IOException ex) {
        Logger.getLogger(com.flexdesktop.connections.restfulConnection.class.getName()).log(Level.SEVERE, null,
                ex);
    }

}

From source file:flexpos.restfulConnection.java

public static void postRequest(HttpURLConnection connection, String data) {
    DataOutputStream wr = null;/*from  w  w w.j  a  v  a  2 s. co  m*/
    try {
        wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(data);
        wr.flush();
        wr.close();
    } catch (IOException ex) {
        Logger.getLogger(restfulConnection.class.getName()).log(Level.SEVERE, null, ex);
    }

}