1 19 20 package org.netbeans.core.execution; 21 22 import java.io.Writer ; 23 import java.io.PrintStream ; 24 import java.io.IOException ; 25 26 final class OutputStreamWriter extends Writer { 27 28 private PrintStream out; 29 30 35 public OutputStreamWriter(PrintStream out) { 36 super(out); 37 if (out == null) 38 throw new NullPointerException (); 39 this.out = out; 40 } 41 42 43 private void ensureOpen() throws IOException { 44 if (out == null) 45 throw new IOException (); 46 } 47 48 53 public void write(int c) throws IOException { 54 char cbuf[] = new char[1]; 55 cbuf[0] = (char) c; 56 write(cbuf, 0, 1); 57 } 58 59 68 public void write(char cbuf[], int off, int len) throws IOException { 69 synchronized (lock) { 70 if ((off == 0) && (len == cbuf.length)) { 71 out.print(cbuf); 72 } else { 73 char[] chars = new char[len]; 74 System.arraycopy(cbuf, off, chars, 0, len); 75 out.print(chars); 76 } 77 } 78 } 79 80 89 public void write(String str, int off, int len) throws IOException { 90 char[] chars = new char[len]; 91 str.getChars(off, off + len, chars, 0); 92 out.print(chars); 93 } 94 95 100 public void flush() { 101 synchronized (lock) { 102 if (out == null) 103 return; 104 out.flush(); 105 } 106 } 107 108 113 public void close() { 114 synchronized (lock) { 115 if (out == null) 116 return; 117 flush(); 118 out.close(); 119 out = null; 120 } 121 } 122 123 } 124 | Popular Tags |