slash.navigation.rest.Get.executeAsStream()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(99)

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

Get.executeAsStream介绍

暂无

代码示例

代码示例来源:origin: cpesch/RouteConverter

private InputStream openStream(URL url) throws IOException {
  String urlString = url.toExternalForm();
  // make sure HTTPS requests use HTTP Client with it's SSL tweaks
  if (urlString.contains("https://")) {
    Get get = new Get(urlString);
    return get.executeAsStream();
  }
  return url.openStream();
}

代码示例来源:origin: cpesch/RouteConverter

private Result resume() throws IOException {
  downloadExecutor.updateState(Resuming);
  long fileSize = getDownload().getTempFile().length();
  Long contentLength = getDownload().getFile().getExpectedChecksum() != null ? getDownload().getFile().getExpectedChecksum().getContentLength() : null;
  log.info(format("Resuming bytes %d-%d from %s", fileSize, contentLength, getDownload().getUrl()));
  Get get = new Get(getDownload().getUrl());
  get.setRange(fileSize, contentLength);
  InputStream inputStream = get.executeAsStream();
  log.info(format("Resume from %s returned with status code %s", getDownload().getUrl(), get.getStatusCode()));
  if (get.isPartialContent()) {
    getModelUpdater().expectingBytes(contentLength != null ? contentLength : get.getContentLength() != null ? get.getContentLength() : 0);
    new Copier(getModelUpdater()).copyAndClose(inputStream, new FileOutputStream(getDownload().getTempFile(), true), fileSize, contentLength);
    return new Result(true);
  }
  return new Result(false);
}

代码示例来源:origin: cpesch/RouteConverter

private Result download() throws IOException {
  downloadExecutor.updateState(Downloading);
  Long contentLength = getDownload().getFile().getExpectedChecksum() != null ? getDownload().getFile().getExpectedChecksum().getContentLength() : null;
  log.info(format("Downloading %d bytes from %s with ETag %s", contentLength, getDownload().getUrl(), getDownload().getETag()));
  Get get = new Get(getDownload().getUrl());
  get.setSocketTimeout(SOCKET_TIMEOUT);
  if (new Validator(getDownload()).isExistsTargets() && getDownload().getETag() != null)
    get.setIfNoneMatch(getDownload().getETag());
  InputStream inputStream = get.executeAsStream();
  log.info(format("Download from %s returned with status code %s and content length %d", getDownload().getUrl(), get.getStatusCode(), get.getContentLength()));
  if (get.isSuccessful() && inputStream != null) {
    if(contentLength == null)
      contentLength = get.getContentLength();
    if (contentLength != null)
      getModelUpdater().expectingBytes(contentLength);
    new Copier(getModelUpdater()).copyAndClose(inputStream, new FileOutputStream(getDownload().getTempFile()), 0, contentLength);
    getDownload().setETag(get.getETag());
    return new Result(true, get.getLastModified());
  }
  return new Result(get.isSuccessful(), get.isNotModified());
}

代码示例来源:origin: cpesch/RouteConverter

public void run() throws IOException {
  Get request = new Get(getDownload().getUrl());
  request.setRange(0L, RANGE_END_INDEX);
  if (getDownload().getETag() != null)
    request.setIfNoneMatch(getDownload().getETag());
  InputStream inputStream = request.executeAsStream();
  log.info(format("GET 0-%d for %s returned with status code %s and content length %d", RANGE_END_INDEX, getDownload().getUrl(), request.getStatusCode(), request.getContentLength()));
  if (request.isPartialContent()) {
    writePartialFile(inputStream, getDownload().getFile().getExpectedChecksum().getContentLength(), getDownload().getFile().getFile());
    closeQuietly(inputStream);
  } else if (request.isOk()){
    // HTTP Range not supported
    copyAndClose(inputStream, new FileOutputStream(getDownload().getFile().getFile()));
    setLastModified(getDownload().getFile().getFile(), request.getLastModified());
  }
  request.release();
  if (request.isNotModified()) {
    downloadExecutor.notModified();
  } else if (request.isSuccessful()) {
    getDownload().setETag(request.getETag());
    getDownload().getFile().setActualChecksum(extractChecksum(request));
    downloadExecutor.succeeded();
  } else
    downloadExecutor.downloadFailed();
}

相关文章