java.net.HttpURLConnection.getLastModified()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中java.net.HttpURLConnection.getLastModified()方法的一些代码示例,展示了HttpURLConnection.getLastModified()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpURLConnection.getLastModified()方法的具体详情如下:
包路径:java.net.HttpURLConnection
类名称:HttpURLConnection
方法名:getLastModified

HttpURLConnection.getLastModified介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

@Override public long getLastModified() {
 return delegate.getLastModified();
}

代码示例来源:origin: prestodb/presto

@Override public long getLastModified() {
 return delegate.getLastModified();
}

代码示例来源:origin: oracle/helidon

@Override
protected Optional<Instant> dataStamp() {
  try {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(HEAD_METHOD);
    if (connection.getLastModified() != 0) {
      return Optional.of(Instant.ofEpochMilli(connection.getLastModified()));
    }
  } catch (IOException ex) {
    LOGGER.log(Level.FINE, ex, () -> "Configuration at url '" + url + "' HEAD is not accessible.");
  }
  Optional<Instant> timestamp = Optional.of(Instant.MAX);
  LOGGER.finer("Missing HEAD '" + url + "' response header 'Last-Modified'. Used time '"
             + timestamp + "' as a content timestamp.");
  return timestamp;
}

代码示例来源:origin: oracle/helidon

@Override
protected Optional<Instant> dataStamp() {
  try {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(HEAD_METHOD);
    if (connection.getLastModified() != 0) {
      return Optional.of(Instant.ofEpochMilli(connection.getLastModified()));
    }
  } catch (IOException ex) {
    LOGGER.log(Level.FINE, ex, () -> "Configuration at url '" + url + "' HEAD is not accessible.");
  }
  Optional<Instant> timestamp = Optional.of(Instant.MAX);
  LOGGER.finer("Missing HEAD '" + url + "' response header 'Last-Modified'. Used time '"
             + timestamp + "' as a content timestamp.");
  return timestamp;
}

代码示例来源:origin: oracle/helidon

@Override
protected ConfigParser.Content content() throws ConfigException {
  try {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(GET_METHOD);
    final String mediaType = mediaType(connection.getContentType());
    final Optional<Instant> timestamp;
    if (connection.getLastModified() != 0) {
      timestamp = Optional.of(Instant.ofEpochMilli(connection.getLastModified()));
    } else {
      timestamp = Optional.of(Instant.now());
      LOGGER.fine("Missing GET '" + url + "' response header 'Last-Modified'. Used current time '"
                + timestamp + "' as a content timestamp.");
    }
    Reader reader = new InputStreamReader(connection.getInputStream(),
                       ConfigUtils.getContentCharset(connection.getContentEncoding()));
    return ConfigParser.Content.create(reader, mediaType, timestamp);
  } catch (ConfigException ex) {
    throw ex;
  } catch (Exception ex) {
    throw new ConfigException("Configuration at url '" + url + "' GET is not accessible.", ex);
  }
}

代码示例来源:origin: oracle/helidon

@Override
protected Data<OverrideData, Instant> loadData() throws ConfigException {
  try {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(GET_METHOD);
    Instant timestamp;
    if (connection.getLastModified() != 0) {
      timestamp = Instant.ofEpochMilli(connection.getLastModified());
    } else {
      timestamp = Instant.now();
      LOGGER.fine("Missing GET '" + url + "' response header 'Last-Modified'. Used current time '"
                + timestamp + "' as a content timestamp.");
    }
    Reader reader = new InputStreamReader(connection.getInputStream(),
                       ConfigUtils.getContentCharset(connection.getContentEncoding()));
    return new Data<>(Optional.of(OverrideData.create(reader)), Optional.of(timestamp));
  } catch (ConfigException ex) {
    throw ex;
  } catch (Exception ex) {
    throw new ConfigException("Configuration at url '" + url + "' GET is not accessible.", ex);
  }
}

代码示例来源:origin: chewiebug/GCViewer

String contentType = httpConn.getContentType();
long contentLengthLong = httpConn.getContentLengthLong();
long lastModified = httpConn.getLastModified();
LOGGER.log(Level.INFO, "Reading " + (contentLengthLong < 0L
     ? "?"

代码示例来源:origin: jeremylong/DependencyCheck

final int t = conn.getResponseCode();
if (t >= 200 && t < 300) {
  timestamp = conn.getLastModified();
} else {
  throw new DownloadFailedException(format("%s request returned a non-200 status code: %s", httpMethod, url));

代码示例来源:origin: org.apache.ant/ant

final long lastModified = httpConnection.getLastModified();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
    || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {

代码示例来源:origin: julian-klode/dns66

/**
 * Checks if we should read from the URL.
 *
 * @param connection The connection that was established.
 * @return true if there was no problem.
 * @throws IOException If an I/O Exception occured.
 */
boolean validateResponse(HttpURLConnection connection) throws IOException {
  Log.d(TAG, "validateResponse: " + item.title + ": local = " + new Date(connection.getIfModifiedSince()) + " remote = " + new Date(connection.getLastModified()));
  if (connection.getResponseCode() != 200) {
    Log.d(TAG, "validateResponse: " + item.title + ": Skipping: Server responded with " + connection.getResponseCode() + " for " + item.location);
    if (connection.getResponseCode() == 404) {
      parentTask.addError(item, context.getString(R.string.file_not_found));
    } else if (connection.getResponseCode() != 304) {
      context.getResources().getString(R.string.host_update_error_item);
      parentTask.addError(item, context.getResources().getString(R.string.host_update_error_item, connection.getResponseCode(), connection.getResponseMessage()));
    }
    return false;
  }
  return true;
}

代码示例来源:origin: julian-klode/dns66

/**
 * Downloads a file from a connection to an singleWriterMultipleReaderFile.
 *
 * @param file                           The file to write to
 * @param singleWriterMultipleReaderFile The atomic file for the destination file
 * @param connection                     The connection to read from
 * @throws IOException I/O exceptions.
 */
void downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection) throws IOException {
  InputStream inStream = connection.getInputStream();
  FileOutputStream outStream = singleWriterMultipleReaderFile.startWrite();
  try {
    copyStream(inStream, outStream);
    singleWriterMultipleReaderFile.finishWrite(outStream);
    outStream = null;
    // Write has started, set modification time.
    if (connection.getLastModified() == 0 || !file.setLastModified(connection.getLastModified())) {
      Log.d(TAG, "downloadFile: Could not set last modified");
    }
  } finally {
    if (outStream != null)
      singleWriterMultipleReaderFile.failWrite(outStream);
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Creates an input stream for the URI, assuming it's a URL, and returns it.
 *
 * @return an open input stream.
 * @exception IOException if there is a problem obtaining an open input stream.
 */
@Override
public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
  try {
    final HttpURLConnection httpConnection = getConnection(uri);
    httpConnection.setConnectTimeout(connectionTimeout);
    httpConnection.setReadTimeout(readTimeout);
    InputStream result = httpConnection.getInputStream();
    Map<Object, Object> response = getResponse(options);
    if (response != null) {
      response.put(
          URIConverter.RESPONSE_TIME_STAMP_PROPERTY,
          httpConnection.getLastModified());
    }
    return result;
  } catch (RuntimeException exception) {
    throw new Resource.IOWrappedException(exception);
  }
}

代码示例来源:origin: rakam-io/rakam

long lastModified = httpConnection.getLastModified();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
    || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {

代码示例来源:origin: rakam-io/rakam

long lastModified = httpConnection.getLastModified();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
    || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {

代码示例来源:origin: rakam-io/rakam

long lastModified = httpConnection.getLastModified();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
    || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {

代码示例来源:origin: PhoenicisOrg/phoenicis

/**
 * Get last modified header
 *
 * @return last modified
 */
long getLastModified() {
  return delegateUrlConnexion.getLastModified();
}

代码示例来源:origin: julian-klode/dns66

when(connection.getLastModified()).thenReturn(0L);
when(file.setLastModified(anyLong())).then(setLastModifiedAnswerFalse);
when(connection.getLastModified()).thenReturn(0L);
when(file.setLastModified(anyLong())).then(setLastModifiedAnswerTrue);
when(connection.getLastModified()).thenReturn(1L);
when(file.setLastModified(anyLong())).then(setLastModifiedAnswerFalse);
when(connection.getLastModified()).thenReturn(1L);
when(file.setLastModified(anyLong())).then(setLastModifiedAnswerTrue);

代码示例来源:origin: dcm4che/dcm4che

private static void logIncoming(HttpURLConnection connection) throws Exception {
  LOG.info("< Content-Length: " + connection.getContentLength());
  LOG.info("< HTTP/1.1 Response: " + String.valueOf(connection.getResponseCode()) + " " + connection.getResponseMessage());
  LOG.info("< Transfer-Encoding: " + connection.getContentEncoding());
  LOG.info("< Content-Type: " + connection.getContentType());
  LOG.info("< Date: " + connection.getLastModified());
  LOG.info("< Response Content: ");
  try (InputStream is = connection.getInputStream()) {
    LOG.debug(readFullyAsString(is));
  }
}

代码示例来源:origin: org.codelibs/jcifs

@Override
public long getLastModified () {
  handshake();
  return this.connection.getLastModified();
}

代码示例来源:origin: com.eas.platypus/platypus-js-core

@Override
public void visit(AppQueryRequest.Response rsp) throws Exception {
  if (responseCode == HttpURLConnection.HTTP_OK) {
    long timeStamp = conn.getLastModified();
    rsp.setTimeStamp(new Date(timeStamp));
    rsp.setAppQueryJson(extractText());
  } else if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
    rsp.setAppQueryJson(null);
    rsp.setTimeStamp(null);
  }
}

相关文章

HttpURLConnection类方法