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

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

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

HttpURLConnection.getContentLengthLong介绍

暂无

代码示例

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

@IgnoreJRERequirement // Should only be invoked on Java 8+ or Android API 24+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: TeamNewPipe/NewPipe

public static long getContentLength(HttpURLConnection connection) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
      return connection.getContentLengthLong();
    }

    try {
      long length = Long.parseLong(connection.getHeaderField("Content-Length"));
      if (length >= 0) return length;
    } catch (Exception err) {
      // nothing to do
    }

    return -1;
  }
}

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

@IgnoreJRERequirement // Should only be invoked on Java 7+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Path call() throws IOException {
  Path folder = target.getParent();
  String prefix = target.getFileName().toString();
  Path tempModuleLocation = Files.createTempFile(folder, prefix + "_", ".tmp");
  tempModuleLocation.toFile().deleteOnExit();
  logger.debug("Downloading {} from {}", target, url);
  long length = -1;
  URLConnection conn = url.openConnection();
  if (conn instanceof HttpURLConnection) {
    length = ((HttpURLConnection) conn).getContentLengthLong();
  }
  try (InputStream is = url.openStream();
     OutputStream os = Files.newOutputStream(tempModuleLocation)) {
    copy(is, os, length, listener);
    Files.move(tempModuleLocation, target, StandardCopyOption.REPLACE_EXISTING);
  }
  return target;
}

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

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

代码示例来源:origin: com.pubnub/pubnub-gson

@Override
public long contentLength() {
  return connection.getContentLengthLong();
}
@Override

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

/**
 * Returns the value of the content-length header field as long
 *
 * @return the content-length of the resource
 */
long getContentLengthLong() {
  return delegateUrlConnexion.getContentLengthLong();
}

代码示例来源:origin: com.pubnub/pubnub

@Override
public long contentLength() {
  return connection.getContentLengthLong();
}

代码示例来源:origin: org.pageseeder.bridge/pso-bridge

/**
 * Returns the value of "Content-Length" response header.
 *
 * <pre><code>Content-Length: 49</code></pre>
 *
 * @return the value of "Content-Length" response header or -1 if the content length is not known.
 */
@Override
public long length() {
 HttpURLConnection con = this._connection;
 if (con == null) return -1;
 return con.getContentLengthLong();
}

代码示例来源:origin: EvoSuite/evosuite

@Override
public long getContentLengthLong() {
  return super.getContentLengthLong();
}

代码示例来源:origin: dzikoysk/Pandomium

protected static long getFileSize(URL url) throws Exception {
  HttpURLConnection  conn = (HttpURLConnection) url.openConnection();
  long length = conn.getContentLengthLong();
  conn.disconnect();
  return length;
}

代码示例来源:origin: stevespringett/nist-data-mirror

private long checkHead(String cveUrl) {
  try {
    URL url = new URL(cveUrl);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("HEAD");
    connection.connect();
    connection.getInputStream();
    return connection.getContentLengthLong();
  } catch (IOException e) {
    System.out.println("Failed to determine content length");
  }
  return 0;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp-urlconnection

@IgnoreJRERequirement // Should only be invoked on Java 8+ or Android API 24+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: gradle.plugin.pl.itgolo.libs/updategradle

private Long getFileWeightRemote(String urlFileRemote) throws IOException, InterruptedException {
  URL url = new URL(urlFileRemote);
  HttpURLConnection conn = DeployApp.buildHttpUrlConnection(url);
  return conn.getContentLengthLong();
}

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

@IgnoreJRERequirement // Should only be invoked on Java 7+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: com.facebook.presto/presto-jdbc

@IgnoreJRERequirement // Should only be invoked on Java 7+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: io.prestosql/presto-jdbc

@IgnoreJRERequirement // Should only be invoked on Java 7+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: gradle.plugin.pl.itgolo.libs/updategradle

private void validateUpload(File file, String remotePathRelative) throws IOException, InterruptedException {
  if (file.isFile() && this.validateUpdate) {
    String urlFile = String.format("%1$s/files/%2$s/%3$s", this.urlApp, this.newVersion, remotePathRelative);
    URL url = new URL(urlFile);
    HttpURLConnection conn = buildHttpUrlConnection(url);
    Long weightRemote = conn.getContentLengthLong();
    Long weight = file.length();
    if (!weight.equals(weightRemote)) {
      throw new IOException("In validate upload file to FTP, file in server not equal length to file local");
    }
    conn.disconnect();
  }
}

代码示例来源:origin: com.github.ljun20160606/okhttp-urlconnection

@IgnoreJRERequirement // Should only be invoked on Java 7+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

代码示例来源:origin: apache/servicemix-bundles

@IgnoreJRERequirement // Should only be invoked on Java 7+.
@Override public long getContentLengthLong() {
 return delegate.getContentLengthLong();
}

相关文章

HttpURLConnection类方法