List of utility methods to do URL Connection
String | doGet(String url, String charset) doGet URL reqUrl = null; URLConnection conn = null; BufferedReader in = null; StringBuffer result = new StringBuffer(); try { reqUrl = new URL(url); conn = reqUrl.openConnection(); conn.setConnectTimeout(10000); ... |
InputStream | doPost(final URL url, final Map do Post final URLConnection urlConn = url.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream os = null; try { os = new DataOutputStream(urlConn.getOutputStream()); ... |
String | doPost(String url, String params, String charset) doPost URL reqUrl = null; URLConnection conn = null; OutputStreamWriter out = null; BufferedWriter bw = null; OutputStream os = null; BufferedReader in = null; StringBuffer result = new StringBuffer(); try { ... |
List | findClasses(URL resource, String packageName, boolean annotated) Recursive method used to find all classes in a given directory and subdirs. List<Class<?>> classes = new ArrayList<Class<?>>(); File directory = new File(resource.getFile()); if (directory.exists()) { findClassInDir(directory, packageName, classes, annotated); } else { JarURLConnection conn = (JarURLConnection) resource.openConnection(); JarFile jarFile = conn.getJarFile(); Enumeration<JarEntry> e = jarFile.entries(); ... |
Set | findClasspathUrls(ClassLoader classLoader) find Classpath Urls Set<URL> urls = new HashSet<URL>(); try { String[] classpathProperties = System.getProperty("java.class.path").split(File.pathSeparator); for (String classpathProperty : classpathProperties) { urls.add(new File(classpathProperty).toURI().toURL()); urls.addAll(getExtURLs(getExtDirs())); } catch (IOException e) { ... |
void | findResourceInJarPackage(URL url, String packageName, String packageDirName, boolean recursive, List find Resource In Jar Package JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile(); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String name = entry.getName(); if (name.charAt(0) == '/') name = name.substring(1); if (name.startsWith(packageDirName)) { ... |
InputStream | getAsStream(URL url) get As Stream URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(false);
return conn.getInputStream();
|
InputStream | getBaseAuthInputStreamFromURL(String query, String basicAuthString) get Base Auth Input Stream From URL URL url = new URL(query); URLConnection uc = url.openConnection(); uc.setRequestProperty("Authorization", basicAuthString); return uc.getInputStream(); |
String | getBaseURL(URLConnection conn) get the base URL from a connection String url = conn.getURL().toExternalForm();
return getBaseURL(url);
|
boolean | getBooleanFromUrl(String url) get Boolean From Url URL website = new URL(url); URLConnection connection = website.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); in.close(); if (response.toString().equals("true")) { return true; } else { return false; |