1 7 8 package java.io; 9 10 import java.nio.charset.Charset ; 11 import java.nio.charset.CharsetEncoder ; 12 import sun.nio.cs.StreamEncoder; 13 14 15 58 59 public class OutputStreamWriter extends Writer { 60 61 private final StreamEncoder se; 62 63 76 public OutputStreamWriter(OutputStream out, String charsetName) 77 throws UnsupportedEncodingException 78 { 79 super(out); 80 if (charsetName == null) 81 throw new NullPointerException ("charsetName"); 82 se = StreamEncoder.forOutputStreamWriter(out, this, charsetName); 83 } 84 85 90 public OutputStreamWriter(OutputStream out) { 91 super(out); 92 try { 93 se = StreamEncoder.forOutputStreamWriter(out, this, (String )null); 94 } catch (UnsupportedEncodingException e) { 95 throw new Error (e); 96 } 97 } 98 99 111 public OutputStreamWriter(OutputStream out, Charset cs) { 112 super(out); 113 if (cs == null) 114 throw new NullPointerException ("charset"); 115 se = StreamEncoder.forOutputStreamWriter(out, this, cs); 116 } 117 118 130 public OutputStreamWriter(OutputStream out, CharsetEncoder enc) { 131 super(out); 132 if (enc == null) 133 throw new NullPointerException ("charset encoder"); 134 se = StreamEncoder.forOutputStreamWriter(out, this, enc); 135 } 136 137 157 public String getEncoding() { 158 return se.getEncoding(); 159 } 160 161 162 163 168 void flushBuffer() throws IOException { 169 se.flushBuffer(); 170 } 171 172 177 public void write(int c) throws IOException { 178 se.write(c); 179 } 180 181 190 public void write(char cbuf[], int off, int len) throws IOException { 191 se.write(cbuf, off, len); 192 } 193 194 203 public void write(String str, int off, int len) throws IOException { 204 se.write(str, off, len); 205 } 206 207 212 public void flush() throws IOException { 213 se.flush(); 214 } 215 216 221 public void close() throws IOException { 222 se.close(); 223 } 224 225 } 226 | Popular Tags |