List of usage examples for java.io IOException toString
public String toString()
From source file:gov.nasa.arc.spife.europa.clientside.EuropaServerManager.java
public static void clearLocalStateArea() throws IOException { StringBuilder errors = new StringBuilder(); for (String entry : localStatePath().toFile().list()) { try {//from w ww . j ava2 s . c o m File file = localStatePath().append(entry).toFile(); if (file.isDirectory()) FileUtils.deleteDirectory(file); else file.delete(); } catch (IOException ioe) { errors.append(ioe.toString()).append("\n"); } } if (errors.length() > 0) throw new IOException(errors.toString()); }
From source file:fileoperations.FileOperations.java
public static boolean writeObjectToFile(Object ObjectToWrite, String fileToWrite) { loggerObj.log(Level.INFO, "inside writeObjectToFile method"); BufferedWriter bw = null;/*from ww w. j av a 2s.c om*/ loggerObj.log(Level.INFO, "File to write the object is:" + fileToWrite); File file = new File(fileToWrite); try { if (!file.exists()) { file.createNewFile(); loggerObj.log(Level.INFO, "File did not exist before: so created new one with the name: " + fileToWrite); } FileWriter fw = new FileWriter(file, true); bw = new BufferedWriter(fw); bw.write(ObjectToWrite.toString()); } catch (IOException ex) { loggerObj.log(Level.SEVERE, "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString()); return false; } catch (Exception ex) { loggerObj.log(Level.SEVERE, "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString()); return false; } finally { try { if (bw != null) { bw.close(); } } catch (IOException ex) { loggerObj.log(Level.SEVERE, "Error in closing the file:" + fileToWrite + " after reading"); return false; } } loggerObj.log(Level.INFO, "Successfully written the object to: " + fileToWrite); return true; }
From source file:fileoperations.FileOperations.java
public static boolean writeCollectionToFile(Collection<String> objToWrite, String delimiter, String fileToWrite) {/* w w w . j a v a2 s . co m*/ loggerObj.log(Level.INFO, "inside writeObjectToFile method"); BufferedWriter bw = null; loggerObj.log(Level.INFO, "File to write the object is:" + fileToWrite); File file = new File(fileToWrite); try { if (file.exists()) { file.delete(); } if (!file.exists()) { file.createNewFile(); loggerObj.log(Level.INFO, "File did not exist before: so created new one with the name: " + fileToWrite); } FileWriter fw = new FileWriter(file, true); bw = new BufferedWriter(fw); for (String i : objToWrite) { bw.write(i.toString() + ","); } } catch (IOException ex) { loggerObj.log(Level.SEVERE, "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString()); return false; } catch (Exception ex) { loggerObj.log(Level.SEVERE, "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString()); return false; } finally { try { if (bw != null) { bw.close(); } } catch (IOException ex) { loggerObj.log(Level.SEVERE, "Error in closing the file:" + fileToWrite + " after reading"); return false; } } loggerObj.log(Level.INFO, "Successfully written the object to: " + fileToWrite); return true; }
From source file:fileoperations.FileOperations.java
public static Object readFromJSONFile(String fileToReadFrom) { loggerObj.log(Level.INFO, "Inside readFromJSONFile method"); JSONParser parser = new JSONParser(); FileReader fileReader = null; try {/*from www . j a va2s . c om*/ loggerObj.log(Level.INFO, "file to read from is:" + fileToReadFrom); fileReader = new FileReader(fileToReadFrom); Object obj = parser.parse(fileReader); loggerObj.log(Level.INFO, "JSON Object is validated successfully from" + fileToReadFrom); fileReader.close(); return obj; } catch (IOException ex) { try { loggerObj.log(Level.SEVERE, "Error in reading the JSON from the file " + fileToReadFrom + "\n Exception is: " + ex.toString()); if (fileReader != null) { fileReader.close(); } } catch (IOException ex1) { loggerObj.log(Level.SEVERE, "Error in closing the file after problem in reading the JSON from the file " + fileToReadFrom); } return null; } catch (ParseException ex) { try { loggerObj.log(Level.SEVERE, "Error in validating the JSON from the file" + fileToReadFrom + "Exception " + ex.toString()); if (fileReader != null) { fileReader.close(); } } catch (IOException ex1) { loggerObj.log(Level.SEVERE, "Error in closing the file after problem in parsing the JSON from the file " + fileToReadFrom); } return null; } }
From source file:edu.umd.cs.eclipse.courseProjectManager.EclipseLaunchEventLog.java
static void logEventToFile(String eventName, IProject project) { // If either the project doesn't have run-logging turned on // or it's not an enabled/disabled event then don't log the event if (!eventName.equals(AutoCVSPlugin.ENABLED) && !eventName.equals(AutoCVSPlugin.DISABLED) && !AutoCVSPlugin.hasAutoRunLogNature(project)) return;/*from w w w.jav a 2s . c o m*/ // Get projectNumber from .submit file // In case the Eclipse name of the project differs from the name in the // database String projectNumber = getProjectNumber(project); // eclipseLaunchEvent timestamp md5sum projectName event String event = EclipseLaunchEventLog.ECLIPSE_LAUNCH_EVENT + "\t" + System.currentTimeMillis() + "\t" + computeChecksumOfCVSControlledFiles(project) + "\t" + projectNumber + "\t" + eventName; EclipseLaunchEventLog eclipseLaunchEventLog = EclipseLaunchEventLog.getLog(project); try { // If we lack the proper .submitUser file // then append event to the .cpmLOG file, to be uploaded later. eclipseLaunchEventLog.log(event); } catch (IOException e) { AutoCVSPlugin.getPlugin().getEventLog() .logError("Unable to log Eclipse launch events to a log file: " + e.getMessage() + "\n" + "This error is related to data gathering for the Marmoset project and should not " + "affect your ability to work on your project."); Debug.print(e.toString()); // e.printStackTrace(); } }
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
/** * Evaluate JavaScript source.// w w w . ja va 2 s . c o m * * @param cx the current context * @param filename the name of the file to compile, or null * for interactive mode. */ public static void processSource(Context cx, String filename) { if (filename == null || filename.equals("-")) { final PrintStream ps = GLOBAL.getErr(); if (filename == null) { // print implementation version ps.println(cx.getImplementationVersion()); } // Use the interpreter for interactive input cx.setOptimizationLevel(-1); final BufferedReader in = new BufferedReader(new InputStreamReader(GLOBAL.getIn())); int lineno = 1; boolean hitEOF = false; while (!hitEOF) { final int startline = lineno; if (filename == null) { ps.print("js> "); } ps.flush(); String source = ""; // Collect lines of source to compile. while (true) { String newline; try { newline = in.readLine(); } catch (IOException ioe) { ps.println(ioe.toString()); break; } if (newline == null) { hitEOF = true; break; } source = source + newline + "\n"; ++lineno; if (cx.stringIsCompilableUnit(source)) { break; } } final Script script = loadScriptFromSource(cx, source, "<stdin>", lineno, null); if (script != null) { final Object result = evaluateScript(script, cx, GLOBAL); if (result != Context.getUndefinedValue()) { try { ps.println(Context.toString(result)); } catch (RhinoException rex) { ToolErrorReporter.reportException(cx.getErrorReporter(), rex); } } final NativeArray h = GLOBAL.getHistory(); h.put((int) h.getLength(), h, source); } } ps.println(); } else { processFile(cx, GLOBAL, filename); } System.gc(); }
From source file:it.txt.access.capability.revocation.test.RevocationServiceTest.java
@SuppressWarnings("rawtypes") private static void setConfigurationData(String path) { try {//from w w w .j a v a2s . c o m // Build a properties file for student. File file = new File(path); file.createNewFile(); Properties properties = new Properties(); properties.load(new FileInputStream(file)); Enumeration e = properties.keys(); while (e.hasMoreElements()) { Object obj = e.nextElement(); System.setProperty(obj.toString(), properties.getProperty(obj.toString())); } } catch (IOException ex) { System.out.println(ex.toString()); } }
From source file:lyonlancer5.xatrocore.lib.internal.SplashProgress.java
private static boolean disableSplash() { //File configFile = new File(Minecraft.getMinecraft().mcDataDir, "config/splash.properties"); File configFile = new File(Constants.CONFIG_FILE, "splash.properties"); //FileReader r = null; enabled = false;/*from w w w . j a va2 s . c o m*/ config.setProperty("enabled", "false"); FileWriter w = null; try { w = new FileWriter(configFile); config.store(w, "Splash screen properties"); } catch (IOException e) { logger.error("Could not save the splash.properties file : " + e.toString()); return false; } finally { IOUtils.closeQuietly(w); } return true; }
From source file:com.stockita.popularmovie.utility.Utilities.java
/** * This will make a GET request to a RESTful web. * * @return String of JSON format// ww w . j a va2 s . c o m */ public static String getMovieData(String uri, Context context) { BufferedReader reader = null; HttpURLConnection con = null; try { URL url = new URL(uri); con = (HttpURLConnection) url.openConnection(); con.setReadTimeout(10000 /* milliseconds */); con.setConnectTimeout(15000 /* milliseconds */); con.setRequestMethod(REQUEST_METHOD_GET); con.connect(); int response = con.getResponseCode(); if (response < 200 || response > 299) { Log.e(LOG_TAG, "connection failed: " + response); sNetworkResponse = false; return null; } InputStream inputStream = con.getInputStream(); // Return null if no date if (inputStream == null) { Log.e(LOG_TAG, "inputStream returned null"); return null; } reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line + "\n"); } // Return null if no data if (builder.length() == 0) { Log.e(LOG_TAG, "builder return null"); return null; } return builder.toString(); } catch (IOException e) { Log.e(LOG_TAG, e.toString()); sNetworkResponse = false; return null; } finally { try { if (reader != null) reader.close(); if (con != null) con.disconnect(); } catch (Exception e) { e.printStackTrace(); Log.e(LOG_TAG, e.toString()); } } }
From source file:gov.nih.cadsr.transform.FilesTransformation.java
public static String transformToCSV(String xmlFile, String xsltFile) { StringBuffer sb = null;// w w w. j a v a 2s .c o m try { String path = "/local/content/cadsrapi/transform/data/"; String ext = "txt"; File dir = new File(path); String name = String.format("%s.%s", RandomStringUtils.randomAlphanumeric(8), ext); File rf = new File(dir, name); long startTime = System.currentTimeMillis(); //Obtain a new instance of a TransformerFactory. TransformerFactory f = TransformerFactory.newInstance(); // Process the Source into a Transformer Object...Construct a StreamSource from a File. Transformer t = f.newTransformer(new StreamSource(xsltFile)); //Construct a StreamSource from input and output Source s; try { s = new StreamSource((new ByteArrayInputStream(xmlFile.getBytes("utf-8")))); Result r = new StreamResult(rf); //Transform the XML Source to a Result. t.transform(s, r); System.out.println("Tranformation completed ..."); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block System.out.println(e1.toString()); } //convert output file to string try { BufferedReader bf = new BufferedReader(new FileReader(rf)); sb = new StringBuffer(); try { while ((bf.readLine()) != null) { sb.append(bf.readLine()); System.out.println(bf.readLine()); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("Transformation took " + (endTime - startTime) + " milliseconds"); System.out.println("Transformation took " + (endTime - startTime) / 1000 + " seconds"); } catch (TransformerConfigurationException e) { System.out.println(e.toString()); } catch (TransformerException e) { System.out.println(e.toString()); } return sb.toString(); }