List of usage examples for java.net URLConnection setUseCaches
public void setUseCaches(boolean usecaches)
From source file:org.squale.welcom.struts.webServer.URLManager.java
/** * Retourn l'url a partie d'un site distant * //from w w w . ja va 2 s . c o m * @param pUrl url * @throws MalformedURLException problem sur l'url * @throws IOException exception * @return webfile */ private WebFile getWebFileFromHTTP(String pUrl) throws MalformedURLException, IOException { WebFile webFile = new WebFile(WebFile.TYPE_DISTANT); webFile.setUrl(new URL(pUrl)); final URLConnection urlcon = webFile.getUrl().openConnection(); urlcon.setUseCaches(true); urlcon.connect(); webFile.setLastDate(new Date(urlcon.getLastModified())); if (urlcon.getLastModified() == 0) { webFile.setLastDate(new Date(urlcon.getDate())); } return webFile; }
From source file:dk.netarkivet.common.distribute.HTTPRemoteFile.java
/** * Invalidate all file handles, by asking the remote registry to remove the * url for this remote file from the list of shared files. * Invalidating a file handle may delete the original files, if deletable. * This method does not throw exceptions, but will warn on errors. *///from w w w . j av a2 s.c o m public void cleanup() { if (filesize == 0) { return; } try { URLConnection urlConnection = getRegistry().openConnection(getRegistry().getCleanupUrl(url)); urlConnection.setUseCaches(false); urlConnection.connect(); urlConnection.getInputStream(); } catch (IOException e) { log.warn("Unable to cleanup file '" + file.getAbsolutePath() + "' with URL'" + url + "'", e); } }
From source file:com.gmail.tracebachi.DeltaSkins.Shared.MojangApi.java
private HttpURLConnection openSkinConnection(String uuid) throws IOException { URL url = new URL(SKIN_ADDR + uuid + "?unsigned=false"); URLConnection connection = url.openConnection(); connection.setConnectTimeout(CONNECT_TIMEOUT); connection.setReadTimeout(READ_TIMEOUT); connection.setDoInput(true);/* ww w . j a va 2 s.com*/ connection.setUseCaches(false); return (HttpURLConnection) connection; }
From source file:ca.simplegames.micro.utils.UrlResource.java
/** * This implementation opens an InputStream for the given URL. * It sets the "UseCaches" flag to <code>false</code>, * mainly to avoid jar file locking on Windows. * * @see java.net.URL#openConnection()/*w w w . j a va 2s . c o m*/ * @see java.net.URLConnection#setUseCaches(boolean) * @see java.net.URLConnection#getInputStream() */ public InputStream getInputStream() throws IOException { URLConnection con = this.url.openConnection(); con.setUseCaches(false); return con.getInputStream(); }
From source file:net.sourceforge.atunes.kernel.modules.network.NetworkHandler.java
/** * Sends a POST request with given parameters and receives response with * given charset/*from w w w .jav a 2 s .co m*/ * * @param requestURL * @param params * @param charset * @return * @throws IOException */ @Override public String readURL(final String requestURL, final Map<String, String> params, final String charset) throws IOException { URLConnection connection = getConnection(requestURL); connection.setUseCaches(false); connection.setDoInput(true); if (params != null && params.size() > 0) { connection.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); writer.write(formatPOSTParameters(params)); writer.flush(); } InputStream input = null; try { input = connection.getInputStream(); return IOUtils.toString(input, charset); } finally { ClosingUtils.close(input); } }
From source file:com.qiqi8226.http.MainActivity.java
private void onBtnPost() { new AsyncTask<String, String, Void>() { @Override// w ww.j a v a2 s. c o m protected Void doInBackground(String... params) { URL url; try { url = new URL(params[0]); URLConnection conn = url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream())); bw.write(""); bw.flush(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = br.readLine()) != null) { publishProgress(line); } br.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onProgressUpdate(String... values) { tv.append(values[0] + "\n"); } }.execute("http://www.baidu.com/"); }
From source file:be.apsu.extremon.probes.tsp.TSPProbe.java
private TimeStampResponse probe(TimeStampRequest request) throws IOException, TSPException { URLConnection connection = this.url.openConnection(); connection.setDoInput(true);/*w w w .j a v a2 s .c o m*/ connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-Type", "application/timestamp-query"); OutputStream outputStream = (connection.getOutputStream()); outputStream.write(request.getEncoded()); outputStream.flush(); outputStream.close(); InputStream inputStream = connection.getInputStream(); TimeStampResponse response = new TimeStampResponse(inputStream); inputStream.close(); return response; }
From source file:com.example.chengcheng.network.httpstacks.HttpUrlConnStack.java
private HttpURLConnection createUrlConnection(String url) throws IOException { URL newURL = new URL(url); URLConnection urlConnection = newURL.openConnection(); urlConnection.setConnectTimeout(mConfig.connTimeOut); urlConnection.setReadTimeout(mConfig.soTimeOut); urlConnection.setDoInput(true);/*from www .ja va2 s . c o m*/ urlConnection.setUseCaches(false); return (HttpURLConnection) urlConnection; }
From source file:com.chiorichan.plugin.loader.Plugin.java
public InputStream getResource(String filename) { if (filename == null) { throw new IllegalArgumentException("Filename cannot be null"); }/*from w w w . j a v a2 s . c om*/ try { URL url = getClassLoader().getResource(filename); if (url == null) { return null; } URLConnection connection = url.openConnection(); connection.setUseCaches(false); return connection.getInputStream(); } catch (IOException ex) { return null; } }
From source file:org.jlibrary.core.http.client.HTTPDelegate.java
/** * Excecutes a void request//from www .ja v a2 s. co m * * @param methodName Name of the method to execute * @param params Method params * @param returnClass Class for the return object. If the class is InputStream this method will return * the HTTP request input stream * @param inputStream Stream for reading contents that will be sent * * @throws Exception If there is any problem running the request */ public Object doRequest(String methodName, Object[] params, Class returnClass, InputStream inputStream) throws Exception { try { logger.debug(servletURL.toString()); logger.debug("opening connection"); URLConnection conn = servletURL.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-type", "text/plain"); //write request and params: OutputStream stream = conn.getOutputStream(); // write streaming header if necessary if (inputStream != null) { stream.write(ByteUtils.intToByteArray("stream-input".getBytes().length)); stream.write("stream-input".getBytes()); stream.flush(); } if (returnClass == InputStream.class) { stream.write(ByteUtils.intToByteArray("stream-output".getBytes().length)); stream.write("stream-output".getBytes()); stream.flush(); } // Write method stream.write(ByteUtils.intToByteArray(methodName.getBytes().length)); stream.write(methodName.getBytes()); //stream.flush(); // Write parameters stream.write(ByteUtils.intToByteArray(params.length)); for (int i = 0; i < params.length; i++) { byte[] content = SerializationUtils.serialize((Serializable) params[i]); stream.write(ByteUtils.intToByteArray(content.length)); stream.write(content); stream.flush(); } if (inputStream != null) { IOUtils.copy(inputStream, stream); } //stream.flush(); //stream.close(); //read response: InputStream input = conn.getInputStream(); if (returnClass == InputStream.class) { // Contents will be read from outside return input; } ObjectInputStream objInput = new ObjectInputStream(input); Object o = objInput.readObject(); if (o == null) { return null; } stream.close(); if (o instanceof Exception) { throw (Exception) o; } else { if (returnClass == null) { return null; } // try to cast try { returnClass.cast(o); } catch (ClassCastException cce) { String msg = "Unexpected response from execution servlet: " + o; logger.error(msg); throw new Exception(msg); } } return o; } catch (ClassNotFoundException e) { throw new Exception(e); } catch (ClassCastException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } }