List of usage examples for java.io PrintWriter checkError
public boolean checkError()
From source file:Main.java
public static void main(String args[]) throws Exception { PrintWriter pw = new PrintWriter(new FileWriter("logfile.txt", true)); timeStamp("File opened", pw); pw.close();// ww w . java 2s . c om if (pw.checkError()) System.out.println("I/O error occurred."); }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com "; PrintWriter pw = new PrintWriter(System.out); // append the sequence pw.append(s);// w w w . j a v a2 s . c om // check if there is an error and flush System.out.println("" + pw.checkError()); }
From source file:Main.java
public static void outputData(short[] data, PrintWriter writer) { for (int i = 0; i < data.length; i++) { writer.println(String.valueOf(data[i])); }/*from w ww .j a v a 2s. c o m*/ if (writer.checkError()) { Log.w(TAG, "Error writing sensor event data"); } }
From source file:de.cgarbs.lib.json.JSONDataModel.java
/** * Converts the DataModel to JSON format and writes the JSON data to the * specified file.//from w ww . jav a2 s .com * * @param model the DataModel to be converted to JSON * @param file the File to be written to * @throws DataException either IO errors or errors during the JSON conversion */ public static void writeToFile(final DataModel model, final File file) throws DataException { PrintWriter out = null; try { out = new PrintWriter(file); out.write(convertToJSON(model)); out.close(); } catch (FileNotFoundException e) { throw wrappedAsDataException(DataException.ERROR.IO_ERROR, e); } catch (JSONException e) { throw wrappedAsDataException(DataException.ERROR.JSON_CONVERSION_ERROR, e); } finally { if (out != null) { out.close(); } } if (out.checkError()) { // FIXME: PrintWriter throws no IOExceptions?! how to find out what happened? throw new DataException(DataException.ERROR.IO_ERROR, "error writing to file"); } }
From source file:org.owasp.jbrofuzz.fuzz.io.Save.java
/** * <p>Method for writing a ".jbrofuzz" file, given the file, the URL * the Request string, the Fuzzers, as well as any specified * transforms.</p>// w w w . j a v a 2 s . c o m * * @param The file to which data will be written to. * @param The URL string, as specified in the fuzzing tab. * @param The request string, as specified in the fuzzing tab. * @param The fuzzers, specified in consecutive CSV type lines: * e.g. * <code> * 045-A85-RFC,5,10 * 034-B02-BIN,118,128 * </code> * @param The transforms, specified also in consecutive CSV type lines: * e.g. * <code> * URL UTF-8,111,222 * SHA-1 Hash,FED,THI * </code> */ public static void writeFile(final File outputFile, final String url, final String request, final String fuzzers, final String transforms) { try { final PrintWriter out = new PrintWriter(outputFile); // Write the file out.println("[JBroFuzz]"); out.println(JBroFuzzFormat.VERSION); out.println("[Fuzzing]"); out.println(JBroFuzzFormat.DATE); out.println("[Comment]"); out.println("_"); out.println("[URL]"); out.println(url); out.println("[Request]"); out.println(request); out.println("[Fuzzers]"); out.println(fuzzers); out.println("[Transforms]"); out.println(transforms); out.println("[End]"); if (out.checkError()) { Logger.log("Errors occured while saving", 4); } out.close(); } catch (final FileNotFoundException e) { Logger.log("File Could Not Be Found To Save", 4); } catch (final SecurityException e) { Logger.log("A Security Exception Occured While Saving", 4); } }
From source file:eu.brokeratcloud.rest.gui.AdminFacingComponent.java
public static boolean writeFile(String fileName, String content) throws java.io.IOException { PrintWriter pw = new PrintWriter(new java.io.FileWriter(fileName, false)); // No append try {//from w w w . ja va2s .c o m pw.print(content); if (pw.checkError()) { logger.error("An error occured while openning or writing output file: " + fileName); return false; } } finally { pw.close(); if (pw.checkError()) { logger.error("An error occured while closing output file: " + fileName); return false; } } return true; }
From source file:org.codice.alliance.nsili.mockserver.server.MockNsili.java
private ORB getOrbForServer(int port) throws InvalidName, AdapterInactive, WrongPolicy, ServantNotActive, IOException { System.setProperty("org.omg.CORBA.ORBInitialPort", String.valueOf(port)); final ORB orb = ORB.init(new String[0], null); System.clearProperty("org.omg.CORBA.ORBInitialPort"); POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootPOA.the_POAManager().activate(); org.omg.CORBA.Object objref = rootPOA.servant_to_reference(new LibraryImpl(rootPOA)); //set ior.txt for http web server iorString = orb.object_to_string(objref); //set ior.txt for ftp web server File ftpIorFile = new File(ftpHomeDirectoryPath + "/data/ior.txt"); File ftpDataDirectory = new File(ftpHomeDirectoryPath + "/data"); ftpDataDirectory.mkdirs();//from w w w .j a v a 2s . co m ftpIorFile.createNewFile(); PrintWriter printWriter = new PrintWriter(new FileWriter(ftpIorFile.getPath())); printWriter.print(orb.object_to_string(objref)); if (printWriter.checkError()) { System.out.println("ERROR: Unable to write ior string to ftp server temporary file"); } printWriter.close(); return orb; }
From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeFileUnpackerTest.java
/** * Creates a new source file./*from www .j ava2s .co m*/ * * @param baseDir the base directory * @return the source file * @throws java.io.IOException for any I/O error */ @Override protected File createSourceFile(File baseDir) throws IOException { File source = new File(baseDir, "source.txt"); PrintWriter stream = new PrintWriter(source); for (int i = 0; i < 20000; ++i) { stream.println(i); } assertFalse(stream.checkError()); stream.close(); volume = new File(temporaryFolder.getRoot(), "volume"); FileSpanningOutputStream out = new FileSpanningOutputStream(volume, 8192); FileInputStream in = new FileInputStream(source); IOUtils.copy(in, out); // verify there is more than one volume out.close(); volumeCount = out.getVolumes(); assertTrue(volumeCount > 1); in.close(); return source; }
From source file:org.kalypso.model.wspm.tuhh.core.profile.export.AbstractCsvWriter.java
public final void export(final IProfileFeature[] profiles, final File file, final IProgressMonitor monitor) throws CoreException { PrintWriter writer = null; try {//from w w w . j a v a 2 s . c o m writer = new PrintWriter(file); write(profiles, writer, monitor); writer.flush(); writer.close(); if (writer.checkError()) throw new IOException(); } catch (final IOException e) { final String message = String.format(Messages.getString("CsvSink_1")); //$NON-NLS-1$ final IStatus status = new Status(IStatus.ERROR, KalypsoModelWspmCorePlugin.getID(), message, e); throw new CoreException(status); } finally { IOUtils.closeQuietly(writer); monitor.done(); } }
From source file:org.omegat.util.PreferencesTest.java
/** * Test that if an error is encountered when loading the * preferences file, the original file is backed up. *///from w w w. j a v a2 s .c o m public void testPreferencesBackup() throws Exception { File prefsFile = new File(tmpDir, Preferences.FILE_PREFERENCES); // Write anything that is malformed XML, to force a parsing error. PrintWriter out = new PrintWriter(prefsFile, "UTF-8"); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); out.println("<omegat>"); out.println("<preference version=\"1.0\">"); out.close(); assertFalse(out.checkError()); // Load bad prefs file. new PreferencesImpl(new PreferencesXML(prefsFile, null)); // The actual backup file will have a timestamp in the filename, // so we have to loop through looking for it. File backup = null; for (File f : tmpDir.listFiles()) { String name = f.getName(); if (name.startsWith(prefsFile.getName()) && name.endsWith(".bak")) { backup = f; break; } } assertNotNull(backup); assertTrue(backup.isFile()); TestFilterBase.compareBinary(prefsFile, backup); }