本文整理了Java中java.net.URLConnection.getContentLengthLong()
方法的一些代码示例,展示了URLConnection.getContentLengthLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.getContentLengthLong()
方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:getContentLengthLong
[英]Returns the value of the content-length
header field as a long.
[中]将content-length
标题字段的值作为长字符串返回。
代码示例来源:origin: MovingBlocks/Terasology
private Map<URL, Long> getSizes() throws IOException {
Map<URL, Long> result = new HashMap<>();
int current = 1;
int total = urlToTargetMap.size();
for (URL url: urlToTargetMap.keySet()) {
progressListener.onSizeMetadataProgress(current, total);
URLConnection conn = url.openConnection();
result.put(url, conn.getContentLengthLong());
current++;
}
return result;
}
代码示例来源:origin: line/armeria
@Override
public HttpFileAttributes readAttributes() throws IOException {
if (attrs == null) {
final URLConnection conn = url.openConnection();
final long length = conn.getContentLengthLong();
final long lastModifiedMillis = conn.getLastModified();
attrs = new HttpFileAttributes(length, lastModifiedMillis);
}
return attrs;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public long contentLength() throws IOException {
URL url = getURL();
if (ResourceUtils.isFileURL(url)) {
// Proceed with file system resolution
File file = getFile();
long length = file.length();
if (length == 0L && !file.exists()) {
throw new FileNotFoundException(getDescription() +
" cannot be resolved in the file system for checking its content length");
}
return length;
}
else {
// Try a URL connection content-length header
URLConnection con = url.openConnection();
customizeConnection(con);
return con.getContentLengthLong();
}
}
代码示例来源:origin: jooby-project/jooby
private static Supplier attr(final URL resource, final BiConsumer<Long, Long> attrs)
throws Exception {
if ("file".equals(resource.getProtocol())) {
File file = new File(resource.toURI());
if (file.exists() && file.isFile()) {
attrs.accept(file.length(), file.lastModified());
return () -> new FileInputStream(file);
}
return null;
} else {
URLConnection cnn = resource.openConnection();
cnn.setUseCaches(false);
attrs.accept(cnn.getContentLengthLong(), cnn.getLastModified());
try {
Closeables.closeQuietly(cnn.getInputStream());
} catch (NullPointerException ex) {
// dir entries throw NPE :S
return null;
}
return () -> resource.openStream();
}
}
代码示例来源:origin: wildfly/wildfly
lastModified = new Date(connection.getLastModified());
contentLength = connection.getContentLengthLong();
} finally {
if (connection != null) {
代码示例来源:origin: spring-projects/spring-framework
long contentLength = con.getContentLengthLong();
if (contentLength > 0) {
return true;
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Immediately opens a connection to the given URL to retrieve
* data about the connection, including the input stream.
*
* @param url The URL to resource
*/
public StreamedFile(URL url) {
String path = url.getPath();
int idx = path.lastIndexOf(File.separatorChar);
this.name = idx > -1 ? path.substring(idx + 1) : path;
this.mediaType = MediaType.forFilename(name);
try {
URLConnection con = url.openConnection();
this.lastModified = con.getLastModified();
this.inputStream = con.getInputStream();
this.length = con.getContentLengthLong();
} catch (IOException e) {
throw new CustomizableResponseTypeException("Could not open a connection to the URL: " + path, e);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public long lastModified() throws IOException {
URL url = getURL();
boolean fileCheck = false;
if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
// Proceed with file system resolution
fileCheck = true;
try {
File fileToCheck = getFileForLastModifiedCheck();
long lastModified = fileToCheck.lastModified();
if (lastModified > 0L || fileToCheck.exists()) {
return lastModified;
}
}
catch (FileNotFoundException ex) {
// Defensively fall back to URL connection check instead
}
}
// Try a URL connection last-modified header
URLConnection con = url.openConnection();
customizeConnection(con);
long lastModified = con.getLastModified();
if (fileCheck && lastModified == 0 && con.getContentLengthLong() <= 0) {
throw new FileNotFoundException(getDescription() +
" cannot be resolved in the file system for checking its last-modified timestamp");
}
return lastModified;
}
代码示例来源:origin: spring-projects/spring-framework
if (con.getContentLengthLong() > 0) {
return true;
代码示例来源:origin: micronaut-projects/micronaut-core
if (con.getContentLengthLong() >= 0) {
return true;
代码示例来源:origin: org.springframework/spring-core
@Override
public long contentLength() throws IOException {
URL url = getURL();
if (ResourceUtils.isFileURL(url)) {
// Proceed with file system resolution
File file = getFile();
long length = file.length();
if (length == 0L && !file.exists()) {
throw new FileNotFoundException(getDescription() +
" cannot be resolved in the file system for checking its content length");
}
return length;
}
else {
// Try a URL connection content-length header
URLConnection con = url.openConnection();
customizeConnection(con);
return con.getContentLengthLong();
}
}
代码示例来源:origin: org.springframework/spring-core
long contentLength = con.getContentLengthLong();
if (contentLength > 0) {
return true;
代码示例来源:origin: org.springframework/spring-core
@Override
public long lastModified() throws IOException {
URL url = getURL();
boolean fileCheck = false;
if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
// Proceed with file system resolution
fileCheck = true;
try {
File fileToCheck = getFileForLastModifiedCheck();
long lastModified = fileToCheck.lastModified();
if (lastModified > 0L || fileToCheck.exists()) {
return lastModified;
}
}
catch (FileNotFoundException ex) {
// Defensively fall back to URL connection check instead
}
}
// Try a URL connection last-modified header
URLConnection con = url.openConnection();
customizeConnection(con);
long lastModified = con.getLastModified();
if (fileCheck && lastModified == 0 && con.getContentLengthLong() <= 0) {
throw new FileNotFoundException(getDescription() +
" cannot be resolved in the file system for checking its last-modified timestamp");
}
return lastModified;
}
代码示例来源:origin: org.springframework/spring-core
if (con.getContentLengthLong() > 0) {
return true;
代码示例来源:origin: org.jboss.modules/jboss-modules
public long getSize() {
final long len = connection.getContentLengthLong();
return len == -1 ? 0 : len;
}
}
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
@Override
public long getContentLengthLong() {
return wrappedJarUrlConnection.getContentLengthLong();
}
代码示例来源:origin: com.google.enterprise.cloudsearch/google-cloudsearch-indexing-connector-sdk
public UrlInputStreamContent(String type, URL url) throws IOException {
super(type);
this.url = url;
this.urlConnection = url.openConnection();
this.length =
urlConnection.getContentLengthLong() == -1L ? 0L : urlConnection.getContentLengthLong();
}
代码示例来源:origin: com.github.subchen/jetbrick-commons
@Override
public long length() {
try {
return url.openConnection().getContentLengthLong();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: org.apache.tomcat/tomcat-catalina
@Override
public long getFileSize(String path, boolean virtual) throws IOException {
long fileSize = -1;
try {
URLConnection urlConnection = getURLConnection(path, virtual);
fileSize = urlConnection.getContentLengthLong();
} catch (IOException e) {
// Ignore this. It will always fail for non-file based includes
}
return fileSize;
}
代码示例来源:origin: octo-online/reactive-audit
@Test(expected = NetworkReactiveAuditException.class)
public void getContentLengthLong()
throws IOException
{
Assume.assumeTrue(IOTestTools.isNetworkConnected());
ReactiveAudit.off.commit();
URLConnection conn = new URL("http://" + HOST + ":" + PORT).openConnection();
TestTools.strict.commit();
conn.getContentLengthLong();
}
内容来源于网络,如有侵权,请联系作者删除!