URL url = new URL(strUrl); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { Bitmap bitmap = (Bitmap)response; }
/** * 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); }
/** * 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(); }
@Loggable(Loggable.DEBUG) public String load(URL url) { return url.openConnection().getContent(); }
@Loggable(Loggable.DEBUG, prepend=true) public String load(URL url) { return url.openConnection().getContent(); }
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
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)); } },
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)); } },
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); }
/** * 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; } } }
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); }
URL physicalUrl = null; URLConnection vfsURLConnection = vfsUrl.openConnection(); Object vfsVirtualFile = vfsURLConnection.getContent(); try { Class vfsUtilsClass = Class.forName("org.jboss.vfs.VFSUtils");
/** * 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); }
/** * 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(); }
/** * 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); }
/** * 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(); }
/** * 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(); }
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);
public Object getContent(Class[] classes) throws IOException { try { handshake(); } catch (IOException ex) { } return connection.getContent(classes); }
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)); } },