List of usage examples for java.net URLConnection getHeaderFieldDate
@SuppressWarnings("deprecation") public long getHeaderFieldDate(String name, long Default)
From source file:Main.java
public static void main(String args[]) throws Exception { URL url = new URL("http://www.google.com"); URLConnection httpCon = (URLConnection) url.openConnection(); long s = httpCon.getHeaderFieldDate("Date", 10000); System.out.println(s);/*from www .j a v a 2 s. c o m*/ }
From source file:org.pentaho.reporting.libraries.resourceloader.loader.URLResourceData.java
private void readMetaData(final URLConnection c) { modificationDate = c.getHeaderFieldDate("last-modified", -1); if (modificationDate <= 0) { if (isFixBrokenWebServiceDateHeader()) { modificationDate = System.currentTimeMillis(); } else {//from w ww . j a v a 2s . com modificationDate = -1; } } contentLength = new Long(c.getContentLength()); contentType = c.getHeaderField("content-type"); metaDataOK = true; lastDateMetaDataRead = System.currentTimeMillis(); }
From source file:piuk.blockchain.android.ui.WalletActivity.java
private void checkVersionAndTimeskewAlert() { new Thread() { @Override/*from www . jav a 2 s . c om*/ public void run() { try { final int versionCode = getWalletApplication().applicationVersionCode(); final URLConnection connection = new URL(Constants.VERSION_URL + "?current=" + versionCode) .openConnection(); connection.connect(); final long serverTime = connection.getHeaderFieldDate("Date", 0); final InputStream is = connection.getInputStream(); final BufferedReader reader = new BufferedReader(new InputStreamReader(is)); // final String version = reader.readLine(); reader.close(); if (serverTime > 0) { final long diffMinutes = Math.abs((System.currentTimeMillis() - serverTime) / 1000 / 60); if (diffMinutes >= 60) { runOnUiThread(new Runnable() { public void run() { if (!isFinishing()) timeskewAlert(diffMinutes); } }); } } } catch (final Exception x) { x.printStackTrace(); } } }.start(); }
From source file:com.ibm.datapower.amt.clientAPI.Blob.java
/** * A check to verify that the content can be read when needed. * /*from w w w . j av a2 s. c o m*/ * @return true if the content can be read, false otherwise. This is used * mostly when a Blob was constructed from a File. This method * checks to make sure the File exists and that the File is * readable. If this Blob was constructed from a byte array * it always returns true. */ public boolean canRead() { final String METHOD_NAME = "canRead"; //$NON-NLS-1$ boolean result = false; if (this.bytes != null) { result = true; } else if (this.file != null) { if (this.file.exists() && this.file.canRead()) { result = true; } } else if (this.url != null) { long lastModified = 0; try { URLConnection urlConn = this.url.openConnection(); lastModified = urlConn.getHeaderFieldDate("Last-Modified", 0); //$NON-NLS-1$ } catch (IOException e) { //It is unlikely that this exception will ever happen //So eat the exception and the method keep lastModified at 0. //We will treat 0 as unreadable. } if (lastModified == 0) { result = false; } else { result = true; } } else { // this should not happen logger.logp(Level.INFO, CLASS_NAME, METHOD_NAME, Messages.getString("wamt.clientAPI.Blob.internalErr", this.toString())); //$NON-NLS-1$ } return (result); }