/** * Loads a source file at a URL. * * @param url the URL of where the source is. * @return the loaded source \ */ public String loadSourceFromURL(URL url) { try { return loadSource(url.openStream()); } catch (IOException ex) { ErrorLogger.println("Could not load source from URL"); return null; } }
/** * Loads the source from a file. * * @param loc the relative location of the file. * @return the source from the file. */ public String loadSource(String loc) { try { return loadSource(new FileInputStream(getFile(loc))); } catch (FileNotFoundException ex) { ErrorLogger.println("Could not find file: " + loc); return null; } }
/** * Loads source from an input stream. * * @param inputStream the input stream where the source is located * @return the source */ private String loadSource(InputStream inputStream) { try { String source = ""; InputStreamReader rdr = new InputStreamReader(inputStream); int c; while ((c = rdr.read()) != -1) { source += (char) c; } rdr.close(); return source; } catch (IOException ioe) { ErrorLogger.println("Could not load source from input stream"); return null; } }