List of usage examples for java.io PrintStream close
public void close()
From source file:org.apache.myfaces.util.DebugUtils.java
/** * Be careful, when using this version of traceView: * Some component properties (e.g. getRenderer) assume, that there is a * valid viewRoot set in the FacesContext! * @param additionalMsg//from w w w .ja v a 2 s . co m * @param viewRoot */ private static void traceView(String additionalMsg, UIViewRoot viewRoot) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); if (additionalMsg != null) { ps.println(additionalMsg); } ps.println("========================================"); printView(viewRoot, ps); ps.println("========================================"); ps.close(); log.trace(baos.toString()); }
From source file:Main.java
public static void save(String filename, Document document) throws IOException { PrintStream out = null; try {// w w w . j av a2 s . c om out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8"); //traceNode(document, ""); print(out, document); } catch (Exception ex) { throw new IOException(ex.getLocalizedMessage()); } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } }
From source file:edu.umn.cs.sthadoop.hdfs.KNNJoin.java
static <S extends Shape> void write(Text text, Path outputPath) throws IOException { if (outputPath != null) { PrintStream ps = new PrintStream(new FileOutputStream(outputPath.toString(), true)); ps.print(text);//from w w w . ja v a 2s . c o m ps.println(); ps.close(); } }
From source file:Main.java
public static void save(String filename, Document document) throws IOException { PrintStream out = null; try {// ww w .j a v a 2 s . co m out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8"); // traceNode(document, ""); print(out, document); } catch (Exception ex) { throw new IOException(ex.getLocalizedMessage()); } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } }
From source file:edu.stanford.muse.email.VerifyEmailSetup.java
public static Pair<Boolean, String> run() { PrintStream savedOut = System.out; InputStream savedIn = System.in; try {//from w w w . ja v a2s . c o m // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); session.setDebug(true); String filename = System.getProperty("java.io.tmpdir") + File.separatorChar + "verifyEmailSetup"; PrintStream ps = new PrintStream(new FileOutputStream(filename)); System.setOut(ps); System.setErr(ps); // Get a Store object Store store = null; store = session.getStore("imaps"); store.connect("imap.gmail.com", 993, "checkmuse", ""); // not the real password. unfortunately, the checkmuse a/c will get blocked by google. // Folder folder = store.getFolder("[Gmail]/Sent Mail"); // int totalMessages = folder.getMessageCount(); // System.err.println (totalMessages + " messages!"); ps.close(); String contents = Util.getFileContents(filename); System.out.println(contents); return new Pair<Boolean, String>(Boolean.TRUE, contents); } catch (AuthenticationFailedException e) { /* its ok if auth failed. we only want to check if IMAPS network route is blocked. when network is blocked, we'll get something like javax.mail.MessagingException: No route to host; nested exception is: java.net.NoRouteToHostException: No route to host ... */ log.info("Verification succeeded: " + Util.stackTrace(e)); return new Pair<Boolean, String>(Boolean.TRUE, ""); } catch (Exception e) { log.warn("Verification failed: " + Util.stackTrace(e)); return new Pair<Boolean, String>(Boolean.FALSE, e.toString()); // stack track reveals too much about our code... Util.stackTrace(e)); } finally { System.setOut(savedOut); System.setIn(savedIn); } }
From source file:Main.java
public static int saveToSdCard(String fileName, Bitmap bitmap) { int ret = 0;/*w w w .j a v a 2s.c om*/ PrintStream out = null; if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return -1; } File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + fileName); if (!file.getParentFile().exists()) { file.getParentFile().mkdir(); } try { out = new PrintStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); } catch (FileNotFoundException e) { // TODO Auto-generated catch block ret = -2; } finally { out.flush(); out.close(); if (!bitmap.isRecycled()) bitmap.recycle(); } return ret; }
From source file:com.meetingninja.csse.database.GroupDatabaseAdapter.java
public static Group updateGroup(Group group) throws IOException { ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject();//from w w w .java 2 s .com jgen.writeStringField(Keys.Group.ID, group.getGroupID()); jgen.writeStringField("field", Keys.Group.TITLE); jgen.writeStringField("value", group.getGroupTitle()); jgen.writeEndObject(); jgen.close(); String payloadTitle = json.toString("UTF8"); ps.close(); json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily ps = new PrintStream(json); jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Group members jgen.writeStartObject(); jgen.writeStringField(Keys.Group.ID, group.getGroupID()); jgen.writeStringField("field", Keys.Group.MEMBERS); jgen.writeArrayFieldStart("value"); for (User member : group.getMembers()) { jgen.writeStartObject(); jgen.writeStringField(Keys.User.ID, member.getID()); jgen.writeEndObject(); } jgen.writeEndArray(); jgen.writeEndObject(); jgen.close(); String payloadMembers = json.toString("UTF8"); ps.close(); // Establish connection sendSingleEdit(payloadTitle); String response = sendSingleEdit(payloadMembers); JsonNode groupNode = MAPPER.readTree(response); return parseGroup(groupNode, new Group()); }
From source file:com.meetingninja.csse.database.NotesDatabaseAdapter.java
private static String getEditPayload(String noteID, String field, String value) throws IOException { ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject();//from www . jav a 2 s . c o m jgen.writeStringField(Keys.Note.ID, noteID); jgen.writeStringField("field", field); jgen.writeStringField("value", value); jgen.writeEndObject(); jgen.close(); String payload = json.toString("UTF8"); ps.close(); Log.d("updatenotepayload", payload); return payload; }
From source file:com.meetingninja.csse.database.MeetingDatabaseAdapter.java
private static String getEditPayload(String meetingID, String field, String value) throws IOException { ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject();/*from w w w .j ava 2s.c o m*/ jgen.writeStringField(Keys.Meeting.ID, meetingID); jgen.writeStringField("field", field); jgen.writeStringField("value", value); jgen.writeEndObject(); jgen.close(); String payload = json.toString("UTF8"); ps.close(); return payload; }
From source file:com.meetingninja.csse.database.TaskDatabaseAdapter.java
private static String getEditPayload(String taskID, String field, String value) throws IOException { ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject();// w w w .j a v a 2 s .c o m jgen.writeStringField(Keys.Task.ID, taskID); jgen.writeStringField("field", field); jgen.writeStringField("value", value); jgen.writeEndObject(); jgen.close(); String payload = json.toString("UTF8"); ps.close(); return payload; }