List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file) throws FileNotFoundException
From source file:TheReplacements.java
public static void write(String fileName, String text) throws IOException { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName))); out.print(text);/*from ww w . jav a 2s.co m*/ out.close(); }
From source file:eu.optimis.ip.gui.client.resources.DbServerThread.java
public DbServerThread(PropertiesConfiguration dbConfig) { if (server == null) { server = new Server(); try {/* w w w . ja va2 s. co m*/ server.setLogWriter(new PrintWriter(new FileOutputStream(dbConfig.getString("logFile"), true))); } catch (FileNotFoundException ex) { Logger.getLogger(Accounting.class.getName()).log(Level.WARNING, "Log file not found. Using System.out"); server.setLogWriter(new PrintWriter(System.out)); } server.setSilent(false); server.setDatabaseName(0, dbConfig.getString("databaseName")); server.setDatabasePath(0, dbConfig.getString("databasePath")); server.setNoSystemExit(true); } }
From source file:RegisterTest.java
/** * Test of processRequest method, of class Register. * @throws java.lang.Exception//from www. j a va 2s . c om */ @Test public void testProcessRequest() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getParameter("uid")).thenReturn("me"); when(request.getParameter("pass")).thenReturn("secret"); PrintWriter writer = new PrintWriter("testregister.txt"); when(response.getWriter()).thenReturn(writer); Register instance = new Register(); instance.doPost(request, response); verify(request, atLeast(1)).getParameter("name"); // only if you want to verify username was called... writer.flush(); // it may not have been flushed yet... assertTrue(FileUtils.readFileToString(new File("testregister.txt"), "UTF-8") .contains("You are sucessfully registered")); }
From source file:mobisocial.musubi.ui.util.FeedHTML.java
public static void writeObj(FileOutputStream fo, Context context, IdentitiesManager identitiesManager, MObject object) {//from ww w . j av a 2 s .co m //TODO: it would be better to put the export code inside the obj handlers MIdentity ident = identitiesManager.getIdentityForId(object.identityId_); if (ident == null) return; PrintWriter w = new PrintWriter(fo); w.print("<div>"); w.print("<div style=\"float:left\">"); w.print("<img src=\"data:image/jpeg;base64,"); Bitmap thumb = UiUtil.safeGetContactThumbnail(context, identitiesManager, ident); ByteArrayOutputStream bos = new ByteArrayOutputStream(); thumb.compress(CompressFormat.JPEG, 90, bos); w.print(Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT)); w.print("\">"); w.print("</div>"); w.print("<div>"); w.print("<h6>"); w.print(UiUtil.safeNameForIdentity(ident)); w.print("</h6>"); try { if (object.type_.equals(StatusObj.TYPE)) { w.print(new JSONObject(object.json_).getString(StatusObj.TEXT)); } else if (object.type_.equals(PictureObj.TYPE)) { w.print("<img src=\"data:image/jpeg;base64,"); w.print(Base64.encodeToString(object.raw_, Base64.DEFAULT)); w.print("\">"); } else { throw new RuntimeException("unsupported type " + object.type_); } } catch (Throwable t) { Log.e("HTML EXPORT", "failed to process obj", t); w.print("<i>only visibile in musubi</i>"); } w.print("</div>"); w.print("</div>"); w.print("</body>"); w.print("</html>"); w.flush(); }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.logging.FileLoggerDestination.java
protected void log(final String message) throws LoggerException { try {/*ww w. j av a2 s . co m*/ if (this.writer == null) { //noinspection IOResourceOpenedButNotSafelyClosed this.writer = new PrintWriter(new BufferedWriter(new FileWriter(filename, append))); } writer.append(message); writer.flush(); } catch (IOException ioe) { throw new LoggerException(ioe); } finally { IOUtils.closeQuietly(writer); this.writer = null; } }
From source file:examples.nntp.ExtendedNNTPOps.java
public ExtendedNNTPOps() { client = new NNTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); }
From source file:gt.dakaik.rest.impl.TokenImpl.java
public boolean validaTokenUsuarioOperaciones(String sToken, int idUsuario) { boolean bResult = false; try {//from w w w.j a va 2 s . com List<UserSession> list2 = rs.findByToken(sToken); if (list2.size() == 1) { bResult = list2.get(0).getIdUser() == idUsuario; } } catch (Exception e) { StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); String err = errors.toString(); eLog.error(err); } return bResult; }
From source file:TakeAttendanceTest.java
/** * Test of processRequest method, of class TakeAttendance. *//* w w w . jav a 2 s .c om*/ @Test public void testProcessRequest() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getParameter("asname")).thenReturn("1301010"); when(request.getParameter("day")).thenReturn("Anubhav"); when(request.getParameter("uids")).thenReturn("Attendee"); PrintWriter writer = new PrintWriter("testtakeattendance.txt"); when(response.getWriter()).thenReturn(writer); TakeAttendance instance = new TakeAttendance(); instance.doPost(request, response); verify(request, atLeast(1)).getParameter("asname"); writer.flush(); // it may not have been flushed yet... assertTrue(FileUtils.readFileToString(new File("testtakeattendance.txt"), "UTF-8") .contains("Attendance Added")); }
From source file:com.sap.prd.mobile.ios.mios.OTAManagerTest.java
@Test public void testOtaUrlIsNull() throws Exception { OTAManager otaManager = new OTAManager(null, "", "", "", "", "", "", null); Assert.assertFalse(otaManager.generateOtaHTML()); CharArrayWriter charWriter = new CharArrayWriter(); try {/* ww w. j av a2 s. co m*/ otaManager.writeOtaHtml(new PrintWriter(charWriter)); assertTrue(charWriter.size() == 0); } finally { closeQuietly(charWriter); } }
From source file:com.ifeng.computing.data.DataFactoryTest.java
@Test public void genEventLogData() { String fileName = TDateUtils.getTime("yyMMddHHmmss"); PrintWriter pw = null;/*w w w .ja v a2 s. c o m*/ try { pw = new PrintWriter(new File("src\\test\\eventlog-" + fileName + ".json")); Random random = new Random(); for (int i = 0; i < MAX_ITEM_SIZE; i++) { int id = (random.nextInt(100) + 1); EventLogDataDocument doc = EventLogDataDocument.Factory.newInstance(); EventLogData data = EventLogData.Factory.newInstance(); doc.setEventLogData(data); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(new File("src\\test\\VideoModel.json"), doc); //pw.append(""+id+" ------- ------------ -------------"); pw.println(); } } /*catch (JsonGenerationException e) { log.error(e.getMessage(), e); } catch (JsonMappingException e) { log.error(e.getMessage(), e); }*/ catch (IOException e) { log.error(e.getMessage(), e); } finally { if (pw != null) { pw.flush(); pw.close(); } } }