Example usage for java.net URLConnection setDoInput

List of usage examples for java.net URLConnection setDoInput

Introduction

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

Prototype

public void setDoInput(boolean doinput) 

Source Link

Document

Sets the value of the doInput field for this URLConnection to the specified value.

Usage

From source file:org.anyframe.oden.bundle.auth.AuthTest.java

private static URLConnection init(String url) throws MalformedURLException, IOException {
    URLConnection con = new URL(url).openConnection();
    con.setUseCaches(false);/* w w  w .jav a 2  s  .  c o  m*/
    con.setDoOutput(true);
    con.setDoInput(true);
    con.setConnectTimeout(TIMEOUT);
    con.setRequestProperty("Authorization", "Basic " + encode("oden", "oden0"));
    return con;
}

From source file:Main.java

/**
 *  This method is used to send a XML request file to web server to process the request and return
 *  xml response containing event id./*from w  ww. j  a v a2 s  .  c om*/
 */
public static String postXMLWithTimeout(String postUrl, String xml, int readTimeout) throws Exception {

    System.out.println("XMLUtils.postXMLWithTimeout: Connecting to Web Server .......");

    InputStream in = null;
    BufferedReader bufferedReader = null;
    OutputStream out = null;
    PrintWriter printWriter = null;
    StringBuffer responseMessageBuffer = new StringBuffer("");

    try {
        URL url = new URL(postUrl);
        URLConnection con = url.openConnection();

        // Prepare for both input and output
        con.setDoInput(true);
        con.setDoOutput(true);

        // Turn off caching
        con.setUseCaches(false);
        con.setRequestProperty("Content-Type", "text/xml");
        con.setReadTimeout(readTimeout);
        out = con.getOutputStream();
        // Write the arguments as post data
        printWriter = new PrintWriter(out);

        printWriter.println(xml);
        printWriter.flush();

        //Process response and return back to caller function
        in = con.getInputStream();
        bufferedReader = new BufferedReader(new InputStreamReader(in));
        String tempStr = null;

        int tempClearResponseMessageBufferCounter = 0;
        while ((tempStr = bufferedReader.readLine()) != null) {
            tempClearResponseMessageBufferCounter++;
            //clear the buffer for the first time
            if (tempClearResponseMessageBufferCounter == 1)
                responseMessageBuffer.setLength(0);
            responseMessageBuffer.append(tempStr);
        }

    } catch (Exception ex) {
        throw ex;
    } finally {
        System.out.println("Calling finally in POSTXML");
        try {
            if (in != null)
                in.close();
        } catch (Exception eex) {
            System.out.println("COULD NOT Close Input Stream in try");
        }
        try {
            if (out != null)
                out.close();
        } catch (Exception eex) {
            System.out.println("COULD NOT Close Output Stream in try");
        }

    }
    System.out.println("XMLUtils.postXMLWithTimeout: end .......");
    return responseMessageBuffer.toString();
}

From source file:org.kootox.episodesmanager.services.WebHelper.java

/**
 *
 * Download a file from the internet// w ww . jav  a2s .co m
 *
 * @param destinationDirectory the directory where the file will be saved
 * @param destinationFileName the name under which the file is saved
 * @param source the url from which to download the file
 */
public static void downloadFile(File destinationDirectory, String destinationFileName, URL source) {

    FileOutputStream out = null;
    InputStream in = null;

    try {
        URLConnection conn = source.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("content-type", "binary/data");
        in = conn.getInputStream();

        File destinationFile = new File(destinationDirectory, destinationFileName);
        out = new FileOutputStream(destinationFile);

        byte[] b = new byte[1024];
        int count;

        while ((count = in.read(b)) >= 0) {
            out.write(b, 0, count);
        }

    } catch (IOException eee) {
        log.error("Could not download file ", eee);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
            if (in != null) {
                in.close();
            }
        } catch (IOException eee) {
            log.debug("Could not close stream", eee);
        }
    }

}

From source file:skinsrestorer.shared.utils.MojangAPI.java

private static URLConnection setupConnection(URL url) throws IOException {
    URLConnection connection = url.openConnection();
    connection.setConnectTimeout(10000);
    connection.setReadTimeout(10000);//from w w  w. jav  a 2s.  c  o  m
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);
    return connection;
}

From source file:org.openlegacy.designtime.newproject.NewProjectMetadataRetriever.java

private static InputStream getUrlConnectionInputStream(String urlPath) throws IOException {
    URL url = new URL(urlPath);
    URLConnection con = url.openConnection();
    con.setDoInput(true);
    con.setDoOutput(false);//from   ww  w .  j ava  2  s .c o  m
    con.connect();

    return con.getInputStream();
}

From source file:Downloader.java

/**
 * Creates an URL connection for the specified URL and data.
 * //from   www. ja v  a2 s .c  o m
 * @param url The URL to connect to
 * @param postData The POST data to pass to the URL
 * @return An URLConnection for the specified URL/data
 * @throws java.net.MalformedURLException If the specified URL is malformed
 * @throws java.io.IOException If an I/O exception occurs while connecting
 */
private static URLConnection getConnection(final String url, final String postData)
        throws MalformedURLException, IOException {
    final URL myUrl = new URL(url);
    final URLConnection urlConn = myUrl.openConnection();

    urlConn.setUseCaches(false);
    urlConn.setDoInput(true);
    urlConn.setDoOutput(postData.length() > 0);
    urlConn.setConnectTimeout(10000);

    if (postData.length() > 0) {
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        final DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
        out.writeBytes(postData);
        out.flush();
        out.close();
    }

    return urlConn;
}

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

public static ArrayList<ArrayList<String>> getRESTful(String RESTfull_URL, ArrayList<String> columnasTabla) {
    try {/*  w  w w.ja v a 2s .co  m*/
        URL url;
        URLConnection urlConnection;
        DataInputStream readString;
        url = new URL(RESTfull_URL);
        urlConnection = url.openConnection();
        urlConnection.setDoInput(true);
        urlConnection.setUseCaches(false);
        readString = new DataInputStream(urlConnection.getInputStream());
        String s;

        String getRequest = "";
        while ((s = readString.readLine()) != null) {
            getRequest += s;
        }
        readString.close();
        if (!"".equals(getRequest)) {
            return completeArray(getRequest, columnasTabla);
        }

    } catch (Exception ex) {
        Logger.getLogger(com.flexdesktop.connections.restfulConnection.class.getName()).log(Level.SEVERE, null,
                ex);
    }
    return null;
}

From source file:flexpos.restfulConnection.java

public static ArrayList<ArrayList<String>> getRESTful(String RESTfull_URL, ArrayList<String> columnasTabla) {
    try {/* w  ww.  j a  v a2  s.com*/
        URL url;
        URLConnection urlConnection;
        DataInputStream readString;
        url = new URL(RESTfull_URL);
        urlConnection = url.openConnection();
        urlConnection.setDoInput(true);
        urlConnection.setUseCaches(false);
        readString = new DataInputStream(urlConnection.getInputStream());
        String s;

        String getRequest = "";
        while ((s = readString.readLine()) != null) {
            getRequest += s;
        }
        readString.close();
        if (!"".equals(getRequest)) {
            return completeArray(getRequest, columnasTabla);
        }

    } catch (Exception ex) {
        Logger.getLogger(restfulConnection.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:xtrememp.update.SoftwareUpdate.java

public static Version getLastVersion(URL url) throws Exception {
    Version result = null;/*from w  w w. j  ava 2 s.c o m*/
    InputStream urlStream = null;
    try {
        URLConnection urlConnection = url.openConnection();
        urlConnection.setAllowUserInteraction(false);
        urlConnection.setConnectTimeout(30000);
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(false);
        urlConnection.setReadTimeout(10000);
        urlConnection.setUseCaches(true);
        urlStream = urlConnection.getInputStream();
        Properties properties = new Properties();
        properties.load(urlStream);

        result = new Version();
        result.setMajorNumber(Integer.parseInt(properties.getProperty("xtrememp.lastVersion.majorNumber")));
        result.setMinorNumber(Integer.parseInt(properties.getProperty("xtrememp.lastVersion.minorNumber")));
        result.setMicroNumber(Integer.parseInt(properties.getProperty("xtrememp.lastVersion.microNumber")));
        result.setVersionType(
                Version.VersionType.valueOf(properties.getProperty("xtrememp.lastVersion.versionType")));
        result.setReleaseDate(properties.getProperty("xtrememp.lastVersion.releaseDate"));
        result.setDownloadURL(properties.getProperty("xtrememp.lastVersion.dounloadURL"));
    } finally {
        IOUtils.closeQuietly(urlStream);
    }
    return result;
}

From source file:com.buglabs.dragonfly.util.WSHelper.java

protected static InputStream getAsStream(URL url) throws IOException {
    URLConnection conn = url.openConnection();

    conn.setDoInput(true);
    conn.setDoOutput(false);/*from w w  w.  ja  v  a2s. c om*/

    return conn.getInputStream();
}