List of usage examples for java.io FilterWriter FilterWriter
protected FilterWriter(Writer out)
From source file:Main.java
public static void main(String[] args) throws Exception { Writer w = new StringWriter(6); FilterWriter fw = new FilterWriter(w) { };//from www .ja v a2 s . c o m fw.write(65); fw.flush(); String s = w.toString(); System.out.print(s); }
From source file:Main.java
public static void main(String[] args) throws Exception { Writer w = new StringWriter(6); FilterWriter fw = new FilterWriter(w) { };//from w ww .j a va 2 s . c o m fw.write(65); String s = w.toString(); System.out.println(s); }
From source file:Main.java
public static void main(String[] args) throws Exception { Writer w = new StringWriter(6); FilterWriter fw = new FilterWriter(w) { };/* w ww . j ava2 s. c o m*/ fw.write(65); fw.write(66); fw.write(67); String s = w.toString(); System.out.print(s); }
From source file:Main.java
public static void main(String[] args) throws Exception { String str = "from java2s.com"; Writer w = new StringWriter(6); FilterWriter fw = new FilterWriter(w) { };// ww w . j ava2 s .c o m fw.write(str, 5, 7); String s = w.toString(); System.out.print(s); }
From source file:Main.java
public static void main(String[] args) throws Exception { char[] cbuf = { 'A', 'B', 'C', 'D', 'E', 'F' }; Writer w = new StringWriter(6); FilterWriter fw = new FilterWriter(w) { };//from www .ja va 2 s . com fw.write(cbuf, 2, 4); String s = w.toString(); System.out.print(s); }
From source file:com.google.gdt.eclipse.designer.hosted.tdt.log.LogSupport.java
public LogSupport(int type, Object hmsImpl, IJavaProject javaProject) throws Exception { if ("true".equalsIgnoreCase(System.getProperty(WBP_TESTING_TIME))) { this.logger = ReflectionUtils.invokeMethod(hmsImpl, "createLogger(java.io.PrintWriter,int)", null, type);/* w ww. ja v a 2 s. com*/ this.writer = null; } else { // prepare directory to write log files to String logDir = HostedModeSupport.getTemporaryDirectoryName(javaProject); // prepare logger Writer rotatingWriter = RotatingFileWriter.getInstance(logDir + File.separator + ".gwt-log", 10, 3); this.writer = new PrintWriter(new FilterWriter(rotatingWriter) { private String buffer = new String(); @Override public void write(String message, int off, int len) throws IOException { super.write(message, off, len); int eolIndex = message.indexOf(LINE_SEPARATOR); if (eolIndex != -1) { buffer += message.substring(0, eolIndex); if (buffer.indexOf(ERROR_TYPE_LABEL) != -1) { m_errors += buffer + LINE_SEPARATOR; } buffer = message.substring(eolIndex + 1); } else { buffer += message; } } }); this.logger = ReflectionUtils.invokeMethod(hmsImpl, "createLogger(java.io.PrintWriter,int)", writer, type); } }
From source file:com.google.gdt.eclipse.designer.hosted.tdz.log.LogSupport.java
public LogSupport(TreeLogger.Type type, IJavaProject javaProject) throws Exception { if ("true".equalsIgnoreCase(System.getProperty(WBP_TESTING_TIME))) { m_logger = TreeLogger.NULL;//from ww w. j a v a 2 s .c o m m_writer = null; } else { // prepare directory to write log files to String logDir = HostedModeSupport.getTemporaryDirectoryName(javaProject); // prepare logger Writer rotatingWriter = RotatingFileWriter.getInstance(logDir + File.separator + ".gwt-log", 10, 3); m_writer = new PrintWriter(new FilterWriter(rotatingWriter) { private String m_buffer = new String(); @Override public void write(String message, int off, int len) throws IOException { super.write(message, off, len); int eolIndex = message.indexOf(LINE_SEPARATOR); if (eolIndex != -1) { m_buffer += message.substring(0, eolIndex); if (m_buffer.indexOf(ERROR_TYPE_LABEL) != -1) { m_errors += m_buffer + LINE_SEPARATOR; } m_buffer = message.substring(eolIndex + 1); } else { m_buffer += message; } } }); m_logger = new PrintWriterTreeLogger(m_writer); ((AbstractTreeLogger) m_logger).setMaxDetail(type); } }
From source file:com.tek42.perforce.parse.AbstractPerforceTemplate.java
/** * Handles the IO for opening a process, writing to it, flushing, closing, and then handling any errors. * /*from ww w.java 2s . c o m*/ * @param object The perforce object to save * @param builder The builder responsible for saving the object * @throws PerforceException If there is any errors thrown from perforce */ @SuppressWarnings("unchecked") protected void saveToPerforce(Object object, Builder builder) throws PerforceException { boolean loop = false; boolean attemptLogin = true; //StringBuilder response = new StringBuilder(); do { int mesgIndex = -1;//, count = 0; Executor p4 = depot.getExecFactory().newExecutor(); String debugCmd = ""; try { String cmds[] = getExtraParams(builder.getSaveCmd(getP4Exe(), object)); // for exception reporting... for (String cm : cmds) { debugCmd += cm + " "; } // back to our regularly scheduled programming... p4.exec(cmds); BufferedReader reader = p4.getReader(); // Maintain a log of what was sent to p4 on std input final StringBuilder log = new StringBuilder(); // Conditional use of std input for saving the perforce entity if (builder.requiresStandardInput()) { BufferedWriter writer = p4.getWriter(); Writer fwriter = new FilterWriter(writer) { public void write(String str) throws IOException { log.append(str); out.write(str); } }; builder.save(object, fwriter); fwriter.flush(); fwriter.close(); } String line; StringBuilder error = new StringBuilder(); StringBuilder info = new StringBuilder(); int exitCode = 0; while ((line = reader.readLine()) != null) { // Check for authentication errors... if (mesgIndex == -1) mesgIndex = checkAuthnErrors(line); if (mesgIndex != -1) { error.append(line); } else if (line.startsWith("error")) { if (!line.trim().equals("") && (line.indexOf("up-to-date") < 0) && (line.indexOf("no file(s) to resolve") < 0)) { error.append(line.substring(6)); } } else if (line.startsWith("exit")) { exitCode = Integer.parseInt(line.substring(line.indexOf(" ") + 1, line.length())); } else { if (line.indexOf(":") > -1) info.append(line.substring(line.indexOf(":"))); else info.append(line); } } reader.close(); loop = false; // If we failed to execute because of an authentication issue, try a p4 login. if (mesgIndex == 1 || mesgIndex == 2 || mesgIndex == 6 || mesgIndex == 9) { if (attemptLogin) { // password is unset means that perforce isn't using the environment var P4PASSWD // Instead it is using tickets. We must attempt to login via p4 login, then // retry this cmd. p4.close(); trustIfSSL(); login(); loop = true; attemptLogin = false; mesgIndex = -1; // cancel this error for now continue; } } if (mesgIndex != -1 || exitCode != 0) { if (error.length() != 0) { error.append("\nFor Command: ").append(debugCmd); if (log.length() > 0) { error.append("\nWith Data:\n===================\n"); error.append(log); error.append("\n===================\n"); } throw new PerforceException(error.toString()); } throw new PerforceException(info.toString()); } } catch (IOException e) { throw new PerforceException("Failed to open connection to perforce", e); } finally { try { p4.getWriter().close(); } catch (IOException e) { //failed to close pipe, but we can't do much about that } try { p4.getReader().close(); } catch (IOException e) { //failed to close pipe, but we can't do much about that } p4.close(); } } while (loop); }