List of usage examples for java.net URLConnection setDoInput
public void setDoInput(boolean doinput)
From source file:org.jab.docsearch.DocSearch.java
private boolean downloadURLToFile(String urlString, String fileToSaveAs) { int numBytes = 0; int curI = 0; FileOutputStream dos = null;/*from www . ja va2 s . co m*/ InputStream urlStream = null; int lastPercent = 0; int curPercent = 0; try { URL url = new URL(urlString); File saveFile = new File(fileToSaveAs); dos = new FileOutputStream(saveFile); URLConnection conn = url.openConnection(); conn.setDoInput(true); conn.setUseCaches(false); conn.connect(); urlStream = conn.getInputStream(); int totalSize = conn.getContentLength(); while (curI != -1) { curI = urlStream.read(); byte curBint = (byte) curI; if (curI == -1) { break; } dos.write(curBint); numBytes++; if (totalSize > 0) { curPercent = (numBytes * 100) / totalSize; if (curPercent != lastPercent) { setStatus(curPercent + " " + I18n.getString("percent_downloaded") + " " + I18n.getString("of_file") + " " + urlString + " " + I18n.getString("total_bytes") + " " + totalSize); lastPercent = curPercent; } } // end if total size not zero } urlStream.close(); dos.close(); } catch (IOException ioe) { logger.fatal("downloadURLToFile() failed", ioe); showMessage(I18n.getString("error_download_file"), ioe.toString()); return false; } finally { IOUtils.closeQuietly(dos); IOUtils.closeQuietly(urlStream); } return true; }
From source file:org.regenstrief.util.Util.java
public final static String post(final String url, final String content) throws IOException { final URLConnection ucon = new URL(url).openConnection(); ucon.setDoInput(true); if (content != null) { ucon.setDoOutput(true);//from w w w.j a v a2 s. com ucon.getOutputStream().write(content.getBytes()); } return readStream(getRawStream(ucon)); }
From source file:com.codename1.impl.android.AndroidImplementation.java
public Object connect(String url, boolean read, boolean write, int timeout) throws IOException { URL u = new URL(url); CookieHandler.setDefault(null); URLConnection con = u.openConnection(); if (con instanceof HttpURLConnection) { HttpURLConnection c = (HttpURLConnection) con; c.setUseCaches(false);/*from w w w . j ava2s.c o m*/ c.setDefaultUseCaches(false); c.setInstanceFollowRedirects(false); if (timeout > -1) { c.setConnectTimeout(timeout); } if (read) { if (timeout > -1) { c.setReadTimeout(timeout); } else { c.setReadTimeout(10000); } } if (android.os.Build.VERSION.SDK_INT > 13) { c.setRequestProperty("Connection", "close"); } } con.setDoInput(read); con.setDoOutput(write); return con; }