/** * Parse a repository document. * * @param url * @throws IOException * @throws XmlPullParserException * @throws Exception */ void parseDocument(URL url) throws IOException, XmlPullParserException, Exception { if (!visited.contains(url)) { visited.add(url); try { System.out.println("Visiting: " + url); InputStream in = null; if (url.getPath().endsWith(".zip")) { ZipInputStream zin = new ZipInputStream(url.openStream()); ZipEntry entry = zin.getNextEntry(); while (entry != null) { if (entry.getName().equals("repository.xml")) { in = zin; break; } entry = zin.getNextEntry(); } } else { in = url.openStream(); } Reader reader = new InputStreamReader(in); XmlPullParser parser = new KXmlParser(); parser.setInput(reader); parseRepository(parser); } catch (MalformedURLException e) { System.out.println("Cannot create connection to url"); } } }
public static void main(String[] args) throws Exception { // URL oracle = new URL("http://www.oracle.com/"); URL oracle = new URL("http://shrib.com/SSnwjY6Q"); String startTag = "<textarea "; String endTag = "</textarea>"; BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream())); StringBuilder result = new StringBuilder(); String inputLine; int textAreaOpened = 0; int indexStart = -1; int indexEnd = -1; int line = 0; int lineStart = 0; int lineEnd = 0; while ((inputLine = in.readLine()) != null) { if (indexStart == -1) { indexStart = inputLine.indexOf(startTag); lineStart = line; } if (inputLine.indexOf(endTag) != -1) { indexEnd = inputLine.indexOf(endTag); lineEnd = line; } line++; } line = 0; in = new BufferedReader(new InputStreamReader(oracle.openStream())); int desde = 0; int hasta = 0; while ((inputLine = in.readLine()) != null) { if (line >= lineStart && line <= lineEnd) { desde = 0; hasta = inputLine.length(); if (line == lineStart) { desde = inputLine.indexOf(">") + 1; } if (line == lineEnd) { hasta = inputLine.lastIndexOf("</textarea>"); } result.append(inputLine.substring(desde, hasta)); } line++; } System.out.println(result); System.out.println(indexStart + "-" + lineStart); System.out.println(indexEnd + "-" + lineEnd); in.close(); }
static { Attributes m = null; final URL loc = Prop.LOCATION; if (loc != null) { final String jar = loc.getFile(); try { final ClassLoader cl = JarManifest.class.getClassLoader(); final Enumeration<URL> list = cl.getResources("META-INF/MANIFEST.MF"); while (list.hasMoreElements()) { final URL url = list.nextElement(); if (!url.getFile().contains(jar)) continue; final InputStream in = url.openStream(); try { m = new Manifest(in).getMainAttributes(); break; } finally { in.close(); } } } catch (final IOException ex) { Util.errln(ex); } } MAP = m; }
/** * Loads the propertis from the file given the URL * * @param urlString URL of the file to be used for loading he properties * @param p Properties */ private static void loadPropertyFile(Properties p, String urlString) { if (urlString == null) { spec.harness.Context.out.println("Null urlString"); return; } try { URL url = new URL(urlString); boolean ok = true; int ind = urlString.indexOf("http:", 0); // spec.harness.Context.out.println( urlString + "=" + ind); if (ind == 0) { ok = spec.io.FileInputStream.IsURLOk(url); } if (ok) { InputStream str = url.openStream(); if (str == null) { spec.harness.Context.out.println("InputStream in loadPropertyFile is null"); } else { p.load(new BufferedInputStream(str)); } } else { spec.harness.Context.out.println("Could not open URL " + urlString); } } catch (Exception e) { spec.harness.Context.out.println("Error loading property file " + urlString + " : " + e); // e.printStackTrace( spec.harness.Context.out ); } }
/** Creates a new instance of TestLoad */ public void run() { // URL url = new URL(getCodeBase(), "/servlet/ServletName"); try { while (true) { URL url = new URL(strURL); url.openConnection(); InputStream in = url.openStream(); byte[] b = new byte[1000]; int iTotal = 0; int iLen; while ((iLen = in.read(b)) != -1) { iTotal += iLen; this.sleep(READ_DELAY); } System.out.println("read " + iTotal + " bytes " + this); this.sleep(SPIN_DELAY); in.close(); } } catch (InterruptedException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }
@Override public InputStream getInputStream() throws IOException, UnsupportedFileOperationException { VsphereConnHandler connHandler = null; try { connHandler = getConnHandler(); ManagedObjectReference fileManager = getFileManager(connHandler); FileTransferInformation fileDlInfo = connHandler .getClient() .getVimPort() .initiateFileTransferFromGuest(fileManager, vm, credentials, getPathInVm()); String fileDlUrl = fileDlInfo.getUrl().replace("*", connHandler.getClient().getServer()); // http://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java URL website = new URL(fileDlUrl); return website.openStream(); } catch (InvalidPropertyFaultMsg e) { translateandLogException(e); } catch (RuntimeFaultFaultMsg e) { translateandLogException(e); } catch (FileFaultFaultMsg e) { translateandLogException(e); } catch (GuestOperationsFaultFaultMsg e) { translateandLogException(e); } catch (InvalidStateFaultMsg e) { translateandLogException(e); } catch (TaskInProgressFaultMsg e) { translateandLogException(e); } finally { releaseConnHandler(connHandler); } return null; }
private readURL() { init(); // create an URL instance try { url = new URL(webpage); } catch (MalformedURLException except1) { System.out.println("MALFORMED URL ERROR\nREADY."); } ; // create "read"-stream from URL try { in = new BufferedReader(new InputStreamReader(url.openStream())); } catch (IOException except2) { System.out.println("IOEXCEPTION ERROR !\nREADY."); } ; // read the stream String inputLine; try { while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } catch (IOException except3) { System.out.println("IOEXCEPTION ERROR AGAIN !\nREADY."); } ; }
/** * Load string map from a URL. * * @param mapURL URL for map file. * @param separator Field separator. * @param qualifier Quote character. * @param encoding Character encoding for the file. * @throws FileNotFoundException If input file does not exist. * @throws IOException If input file cannot be opened. * @return Map with values read from file. */ public static Map<String, String> loadMap( URL mapURL, String separator, String qualifier, String encoding) throws IOException, FileNotFoundException { Map<String, String> map = MapFactory.createNewMap(); if (mapURL != null) { BufferedReader bufferedReader = new BufferedReader(new UnicodeReader(mapURL.openStream(), encoding)); String inputLine = bufferedReader.readLine(); String[] tokens; while (inputLine != null) { tokens = inputLine.split(separator); if (tokens.length > 1) { map.put(tokens[0], tokens[1]); } inputLine = bufferedReader.readLine(); } bufferedReader.close(); } return map; }
/** * Returns an input stream to the resource. * * @param resource The path leading to the resource. Can be an URL, a path leading to a class * resource or a {@link File}. * @return InputStream instance. * @throws IOException If the resource could not be found or opened. */ public static InputStream openInputStream(String resource) throws IOException { try { // See if the resource is an URL first. final URL url = new URL(resource); // success, load the resource. return url.openStream(); } catch (MalformedURLException e) { // No luck. Fallback to class loader paths. } // Try current thread's class loader first. final ClassLoader ldr = Thread.currentThread().getContextClassLoader(); InputStream is; if (ldr != null && (is = ldr.getResourceAsStream(resource)) != null) { return is; } else if ((is = ResourceUtils.class.getResourceAsStream(resource)) != null) { return is; } else if ((is = ClassLoader.getSystemResourceAsStream(resource)) != null) { return is; } // Try file path final File f = new File(resource); if (f.exists() && f.isFile() && f.canRead()) { return new FileInputStream(f); } throw new IOException("Could not locate resource: " + resource); }
public static void main(String args[]) throws IOException { try { // Create a URL object String temp = "http://ccnabaaps.hostingsiteforfree.com/folder/phppart.php?q=http://www.espncricinfo.com/india/content/player/253802.html"; URL url = new URL(temp); // Read all of the text returned by the HTTP server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String htmlText; while ((htmlText = in.readLine()) != null) { // Keep in mind that readLine() strips the newline characters System.out.println(htmlText); } in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
/** * create a Bufferedreader that read from the open url The parameter of the search term research * can be setup using the various command */ private boolean download() { buffer = new StringBuilder(); // --1. Encode url? // --2. Do the work try { url = new URL(composite_url); // Config.log("ESearch for: "+search_term); } catch (MalformedURLException e) { Config.log("Error: URL is not good.\n" + composite_url); } try { if (in_connection_open) in_connection.close(); in_connection = new BufferedReader(new InputStreamReader(url.openStream())); if (in_connection != null) in_connection_open = true; String inputLine = ""; if (isOutputToDisk()) output = new PrintWriter(new FileWriter(new File(filename))); while ((inputLine = in_connection.readLine()) != null) { if (!this.isOutputToDisk()) { buffer.append(inputLine + "\n"); } else { output.println(inputLine); } } if (isOutputToDisk()) { output.flush(); output.close(); } } catch (IOException e) { Config.log("Unable to download from..." + composite_url); return false; } return true; }
public static void main(String[] argv) { try { URL url = new URL(argv[0]); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); MarkupReader mr = new MarkupReader(br, new AceViewerConfig(), false); } catch (Exception e) { System.err.println(e); // debug } }
public static void saveURL(URL url, OutputStream os) throws IOException { InputStream is = url.openStream(); byte[] buf = new byte[1048576]; int n = is.read(buf); while (n != -1) { os.write(buf, 0, n); n = is.read(buf); } }
public InputStream getResourceAsStream(String path) { URL url = getResource(path); if (url == null) return null; try { return url.openStream(); } catch (IOException ioe) { throw new RuntimeException("can't getResourceAsStream [" + path + "]", ioe); } }
public static ModuleImpl loadModule(String resource) throws IOException, CoreException { URL url = ModuleSyncRunnerTest.class.getResource(resource); if (url == null) { Assert.fail("resource not found: " + resource); } ModuleImpl module = new ModuleManifestParser().parse(url.openStream()); module.setLocation(url); return module; }
/** * Returns an input stream for reading the specified resource from GAR file only. * * @param name Resource name. * @return An input stream for reading the resource, or {@code null} if the resource could not be * found. */ @Nullable public InputStream getResourceAsStreamGarOnly(String name) { URL url = findResource(name); try { return url != null ? url.openStream() : null; } catch (IOException ignored) { return null; } }
private void doImportFromURL(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { URL source = getSourceURL(); IOUtilities.pipe( source.openStream(), new FileOutputStream(new File(getStorageDirectory(), FILE_DATA), true), true, true); completeTransfer(req, resp); }
public Reader getReader(String entityName) { try { if (defaultLocation != null) { if (defaultLocation instanceof File) { File loc = (File) defaultLocation; BufferedReader in = new BufferedReader(new FileReader(new File(loc, entityName))); return in; } else if (defaultLocation instanceof URL) { // MAW Version 1.17 // Changed to construct new URL based on default // location plus the entity name just like is done // with the File-based name. This allows parsing of // a URL-based DTD file that references other files either // relatively or absolutely. URL url = new URL((URL) defaultLocation, entityName); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); return in; } } BufferedReader in = new BufferedReader(new FileReader(entityName)); return in; } catch (Exception ignore) { } try { URL url = new URL(entityName); InputStream inStream = url.openStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inStream)); return in; } catch (Exception ignore) { } return null; }
public static void main(String[] args) throws Exception { String host = (args.length > 0) ? args[0] : "localhost"; BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Request : "); String symbol = console.readLine(); URL url = new URL("http://" + host + ":8055/" + symbol); InputStream in = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); System.out.println("Response : " + reader.readLine()); reader.close(); }
private void Timer(ActionEvent evt) { // TODO Auto-generated method stub try { int minBus = 110; int maxBus = 120; double minAfkLat = 42.302; double maxAfkLat = 42.304; System.out.println("Timer"); timer.stop(); MapMarker init = new MapMarker(theLatitude, theLongitude); String theMapURIAsString = (String) MapLookup.getMap(theLatitude, theLongitude, init).substring(0, 87); int testint2 = 0; for (Listener l : theListeners) { // if(l.Latitude != 9999 && Float.parseFloat(l.BusID.split("#")[1]) < maxBus && // Float.parseFloat(l.BusID.split("#")[1]) > minBus) //Bussar beroende på buss nummer // if(l.Latitude != 9999 && l.Latitude > minAfkLat && l.Latitude < maxAfkLat) // //Possible afk busses // if(l.Latitude != 9999 && ( l.Latitude < minAfkLat || l.Latitude > maxAfkLat)) // //Exclude afk busses if (l.Latitude != 9999.0) // All busses { theMapURIAsString += "|"; theMapURIAsString += Float.toString(l.Latitude) + "," + Float.toString(l.Longitude); } } theMapURIAsString += "&sensor=false&key=AIzaSyBR_wUAQ3iPM2e8WeoQIUw9c3xLJPRGZL8"; // System.out.println("HEIR COWMES F****R\n" + theMapURIAsString + "\nFUCKER IS COMMEN"); String[] GetRidOfinitMarker = theMapURIAsString.split("42.358543,-71.096178\\|"); // String[] GetRidOfinitMarker = theMapURIAsString.split("42.303113,-71.109925\\|"); //afk // bussar String GottenRidOfinitMarker = GetRidOfinitMarker[0] + GetRidOfinitMarker[1]; String test = theMapURIAsString.split("&markers=")[1]; String[] testa = test.split("\\|"); // for(String v : testa)System.out.println(v); //alla inkomna positioner // Retrieve map from Google Maps. // URL theMapURI = new URL(theMapURIAsString); URL theMapURI = new URL(GottenRidOfinitMarker); // URL Utan init marker theMap = ImageIO.read(theMapURI.openStream()); // Create map image scaled to size of the application window size. imagePanel1.setImage( theMap.getScaledInstance( imagePanel1.getWidth(), imagePanel1.getHeight(), Image.SCALE_AREA_AVERAGING)); // Display map image. imagePanel1.repaint(); } catch (Exception ex) { timer.start(); } timer.start(); }
public static void main(String[] argv) { try { URL url = new URL(argv[0]); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); FASTASequenceReader fa = new FASTASequenceReader(br, false); StringBuffer sb = fa.get_sequences().get("chr7"); // StringBuffer sb = fa.get_sequences().get("302P7AAXX090507:5:73:1207:509#0.F1"); System.err.println(sb); // debug } catch (Exception e) { System.err.println(e); // debug } }
public static void downloadFileFromURL(String urlString, File destination) { try { URL website = new URL(urlString); ReadableByteChannel rbc; rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream(destination); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.close(); rbc.close(); } catch (IOException e) { e.printStackTrace(); } }
public void run() { try { InputStream in = url.openStream(); int n; while ((n = in.read(buf)) > 0) { System.out.write(buf, 0, n); } in.close(); System.err.println(url + " read complete"); } catch (Exception ex) { ex.printStackTrace(System.err); } }
public String[] parseConfig(String Server) { URL data; Server = Server.trim(); Server = Server.replaceAll(" ", ""); BufferedReader in = null; String inputLine = ""; String html = ""; String settings[] = {"", "", ""}; try { data = new URL(Server + "/icejaw/wizard_config.ini"); try { in = new BufferedReader(new InputStreamReader(data.openStream())); } catch (IOException ex) { return null; } try { while ((inputLine = in.readLine()) != null) { html = inputLine; html.replaceAll(" ", ""); if (html.indexOf("online") == 0) { html = html.substring(7); settings[0] = html; } if (html.indexOf("title") == 0 || html.indexOf("Title") == 0) { html = html.replace("title=", ""); settings[1] = html; } if (html.indexOf("minVersion") == 0) { html = html.substring(11); settings[2] = html; } } in.close(); } catch (IOException ex) { return null; } } catch (MalformedURLException u) { return null; } return settings; }
private void readFromStorableInput(String filename) { try { URL url = new URL(getCodeBase(), filename); InputStream stream = url.openStream(); StorableInput input = new StorableInput(stream); fDrawing.release(); fDrawing = (Drawing) input.readStorable(); view().setDrawing(fDrawing); } catch (IOException e) { initDrawing(); showStatus("Error:" + e); } }
private static Set<String> findStandardMBeansFromJar(URL codeBase) throws Exception { InputStream is = codeBase.openStream(); JarInputStream jis = new JarInputStream(is); Set<String> names = new TreeSet<String>(); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { String name = entry.getName(); if (!name.endsWith(".class")) continue; name = name.substring(0, name.length() - 6); name = name.replace('/', '.'); names.add(name); } return names; }
/** * Get the game information. * * <p>Returns the imported text. */ private String getGameInfo() throws IOException { final StringBuffer gameInformation = new StringBuffer(16384); URL u = null; BufferedReader reader = null; try { u = new URL( "http://www.floc.net/observer.py?judge=" + judgeName + "&game=" + gameName + "&page=history&history_from=0&history_to=999999"); fic.flocImportMessage(Utils.getLocalString(READING_CONTACT)); // output is in HTML, so using the HTML editor kit parser removes // HTML cruft. // reader = new BufferedReader(new InputStreamReader(u.openStream())); if (!isInProgress) { return ""; } ParserDelegator parser = new ParserDelegator(); parser.parse( reader, new HTMLEditorKit.ParserCallback() { public void handleText(char[] text, int pos) { if (!isInProgress) { gameInformation.setLength(0); // abort! return; } fic.flocImportMessage(Utils.getLocalString(READING_FROM_NET)); gameInformation.append(text); gameInformation.append("\n"); } // handleText() }, false); } finally { if (reader != null) { reader.close(); } } return gameInformation.toString(); } // getGameInfo()
private void setup() { env = new EnvAdvanced(); // Load the game objects try { URL url = Sysutil.getURL("world.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = br.readLine()) != null) { String[] fields = line.split(","); if (fields[0].equalsIgnoreCase("skybox")) { // The background env.setRoom(new EnvSkyRoom(fields[1])); } else if (fields[0].equalsIgnoreCase("camera")) { // The camera env.setCameraXYZ( Double.parseDouble(fields[1]), Double.parseDouble(fields[2]), Double.parseDouble(fields[3])); env.setCameraYaw(Double.parseDouble(fields[4])); env.setCameraPitch(Double.parseDouble(fields[5])); } else if (fields[0].equalsIgnoreCase("terrain")) { terrain = new EnvTerrain(fields[1]); terrain.setTextureAlpha(fields[2]); terrain.setTexture(fields[3], 1); terrain.setTexture(fields[4], 2); terrain.setTexture(fields[5], 3); env.addObject(terrain); } else if (fields[0].equalsIgnoreCase("object")) { GameObject n = (GameObject) Class.forName(fields[10]).newInstance(); n.setX(Double.parseDouble(fields[1])); n.setY(Double.parseDouble(fields[2])); n.setZ(Double.parseDouble(fields[3])); n.setScale(Double.parseDouble(fields[4])); n.setRotateX(Double.parseDouble(fields[5])); n.setRotateY(Double.parseDouble(fields[6])); n.setRotateZ(Double.parseDouble(fields[7])); n.setTexture(fields[9]); n.setModel(fields[8]); n.setEnv(env); env.addObject(n); } } } catch (Exception e) { e.printStackTrace(); } }
public static String getContent(URL url) throws IOException { String content = ""; InputStream inst = url.openStream(); InputStreamReader insr = new InputStreamReader(inst); BufferedReader buff = new BufferedReader(insr); while (true) { String line = buff.readLine(); if (line != null) content += line + "\n"; else break; } inst.close(); insr.close(); buff.close(); return content; }
private InputStream openStream(String urlpath) { InputStream stream = null; try { URL url = new URL(urlpath); stream = url.openStream(); return stream; } catch (MalformedURLException e) { System.out.println("Something's wrong with the URL: " + urlpath); e.printStackTrace(); } catch (IOException e) { System.out.println("there's a problem downloading from: " + urlpath); e.printStackTrace(); } return stream; }