本文整理了Java中java.net.URLConnection.getContent()
方法的一些代码示例,展示了URLConnection.getContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.getContent()
方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:getContent
[英]Returns an object representing the content of the resource this URLConnection is connected to. First, it attempts to get the content type from the method getContentType() which looks at the response header field "Content-Type". If none is found it will guess the content type from the filename extension. If that fails the stream itself will be used to guess the content type.
[中]返回一个对象,该对象表示此URLConnection连接到的资源的内容。首先,它尝试从getContentType()方法获取内容类型,该方法查看响应头字段“content type”。如果没有找到,它将根据文件扩展名猜测内容类型。如果失败,流本身将用于猜测内容类型。
代码示例来源:origin: stackoverflow.com
URL url = new URL(strUrl);
URLConnection connection = url.openConnection();
connection.setUseCaches(true);
Object response = connection.getContent();
if (response instanceof Bitmap) {
Bitmap bitmap = (Bitmap)response;
}
代码示例来源:origin: robovm/robovm
/**
* Equivalent to {@code openConnection().getContent(types)}.
*/
@SuppressWarnings("unchecked") // Param not generic in spec
public final Object getContent(Class[] types) throws IOException {
return openConnection().getContent(types);
}
代码示例来源:origin: robovm/robovm
/**
* Returns the content of the resource which is referred by this URL. By
* default this returns an {@code InputStream}, or null if the content type
* of the response is unknown.
*/
public final Object getContent() throws IOException {
return openConnection().getContent();
}
代码示例来源:origin: stackoverflow.com
@Loggable(Loggable.DEBUG)
public String load(URL url) {
return url.openConnection().getContent();
}
代码示例来源:origin: stackoverflow.com
@Loggable(Loggable.DEBUG, prepend=true)
public String load(URL url) {
return url.openConnection().getContent();
}
代码示例来源:origin: stackoverflow.com
String sURL = "http://freegeoip.net/json/"; //just a string
// Connect to the URL using java's native library
URL url = new URL(sURL);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.connect();
// Convert to a JSON object to print data
JsonParser jp = new JsonParser(); //from gson
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
zipcode = rootobj.get("zip_code").getAsString(); //just grab the zipcode
代码示例来源:origin: ronmamo/reflections
public Vfs.Dir createDir(URL url) throws Exception {
Object content = url.openConnection().getContent();
Class<?> virtualFile = ClasspathHelper.contextClassLoader().loadClass("org.jboss.vfs.VirtualFile");
java.io.File physicalFile = (java.io.File) virtualFile.getMethod("getPhysicalFile").invoke(content);
String name = (String) virtualFile.getMethod("getName").invoke(content);
java.io.File file = new java.io.File(physicalFile.getParentFile(), name);
if (!file.exists() || !file.canRead()) file = physicalFile;
return file.isDirectory() ? new SystemDir(file) : new ZipDir(new JarFile(file));
}
},
代码示例来源:origin: org.reflections/reflections
public Vfs.Dir createDir(URL url) throws Exception {
Object content = url.openConnection().getContent();
Class<?> virtualFile = ClasspathHelper.contextClassLoader().loadClass("org.jboss.vfs.VirtualFile");
java.io.File physicalFile = (java.io.File) virtualFile.getMethod("getPhysicalFile").invoke(content);
String name = (String) virtualFile.getMethod("getName").invoke(content);
java.io.File file = new java.io.File(physicalFile.getParentFile(), name);
if (!file.exists() || !file.canRead()) file = physicalFile;
return file.isDirectory() ? new SystemDir(file) : new ZipDir(new JarFile(file));
}
},
代码示例来源:origin: apache/incubator-gobblin
private String fetchContent(int tunnelPort)
throws IOException {
InputStream content = (InputStream) new URL(String.format("http://localhost:%s/", tunnelPort)).openConnection()
.getContent(new Class[]{InputStream.class});
return IOUtils.toString(content);
}
代码示例来源:origin: mulesoft/mule
/**
* Checks that a connection can be established to a provided URL.
*
* @param connectivityUrl the URL to check connectivity to.
* @return {@code true} if there is connectivity to the provided url, {@code false} otherwise.
*/
public static boolean checkConnectivity(String connectivityUrl) {
try {
new URL(connectivityUrl).openConnection().getContent();
return true;
} catch (IOException e) {
return false;
}
}
}
代码示例来源:origin: glowroot/glowroot
private static @Nullable Location getFileFromJBossVfsURL(URL url, ClassLoader loader)
throws Exception {
Object virtualFile = url.openConnection().getContent();
Class<?> virtualFileClass = loader.loadClass("org.jboss.vfs.VirtualFile");
Method getPhysicalFileMethod = virtualFileClass.getMethod("getPhysicalFile");
Method getNameMethod = virtualFileClass.getMethod("getName");
File physicalFile = (File) getPhysicalFileMethod.invoke(virtualFile);
checkNotNull(physicalFile, "org.jboss.vfs.VirtualFile.getPhysicalFile() returned null");
String name = (String) getNameMethod.invoke(virtualFile);
checkNotNull(name, "org.jboss.vfs.VirtualFile.getName() returned null");
File file = new File(physicalFile.getParentFile(), name);
return getLocationFromFile(file);
}
代码示例来源:origin: net.sf.ehcache/ehcache
URL physicalUrl = null;
URLConnection vfsURLConnection = vfsUrl.openConnection();
Object vfsVirtualFile = vfsURLConnection.getContent();
try {
Class vfsUtilsClass = Class.forName("org.jboss.vfs.VFSUtils");
代码示例来源:origin: MobiVM/robovm
/**
* Equivalent to {@code openConnection().getContent(types)}.
*/
@SuppressWarnings("unchecked") // Param not generic in spec
public final Object getContent(Class[] types) throws IOException {
return openConnection().getContent(types);
}
代码示例来源:origin: MobiVM/robovm
/**
* Returns the content of the resource which is referred by this URL. By
* default this returns an {@code InputStream}, or null if the content type
* of the response is unknown.
*/
public final Object getContent() throws IOException {
return openConnection().getContent();
}
代码示例来源:origin: com.mobidevelop.robovm/robovm-rt
/**
* Equivalent to {@code openConnection().getContent(types)}.
*/
@SuppressWarnings("unchecked") // Param not generic in spec
public final Object getContent(Class[] types) throws IOException {
return openConnection().getContent(types);
}
代码示例来源:origin: ibinti/bugvm
/**
* Returns the content of the resource which is referred by this URL. By
* default this returns an {@code InputStream}, or null if the content type
* of the response is unknown.
*/
public final Object getContent() throws IOException {
return openConnection().getContent();
}
代码示例来源:origin: com.gluonhq/robovm-rt
/**
* Returns the content of the resource which is referred by this URL. By
* default this returns an {@code InputStream}, or null if the content type
* of the response is unknown.
*/
public final Object getContent() throws IOException {
return openConnection().getContent();
}
代码示例来源:origin: stackoverflow.com
import org.jboss.vfs.*;
String filename = ...;
URLConnection conn = new URL("vfs:/...").openConnection();
VirtualFile vf = (VirtualFile)conn.getContent();
File contentsFile = vf.getPhysicalFile();
File dir = contentsFile.getParentFile();
File physicalFile = new File(dir, filename);
InputStream is = new FileInputStream(physicalFile);
代码示例来源:origin: org.samba.jcifs/jcifs
public Object getContent(Class[] classes) throws IOException {
try {
handshake();
} catch (IOException ex) { }
return connection.getContent(classes);
}
代码示例来源:origin: net.oneandone.reflections8/reflections8
public Vfs.Dir createDir(URL url) throws Exception {
Object content = url.openConnection().getContent();
Class<?> virtualFile = ClasspathHelper.contextClassLoader().loadClass("org.jboss.vfs.VirtualFile");
java.io.File physicalFile = (java.io.File) virtualFile.getMethod("getPhysicalFile").invoke(content);
String name = (String) virtualFile.getMethod("getName").invoke(content);
java.io.File file = new java.io.File(physicalFile.getParentFile(), name);
if (!file.exists() || !file.canRead()) file = physicalFile;
return file.isDirectory() ? new SystemDir(file) : new ZipDir(new JarFile(file));
}
},
内容来源于网络,如有侵权,请联系作者删除!