1 |
/* OutputStreamWriter.java -- Writer that converts chars to bytes |
/* OutputStreamWriter.java -- Writer that converts chars to bytes |
2 |
Copyright (C) 1998 Free Software Foundation, Inc. |
Copyright (C) 1998, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
70 |
* <li>More Later |
* <li>More Later |
71 |
* </ul> |
* </ul> |
72 |
* |
* |
|
* @version 0.0 |
|
|
* |
|
73 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
74 |
*/ |
*/ |
75 |
public class OutputStreamWriter extends Writer |
public class OutputStreamWriter extends Writer |
76 |
{ |
{ |
77 |
|
/** |
78 |
/*************************************************************************/ |
* This is the byte-character encoder class that does the writing and |
79 |
|
* translation of characters to bytes before writing to the underlying |
80 |
/** |
* class. |
81 |
* This is the byte-character encoder class that does the writing and |
*/ |
82 |
* translation of characters to bytes before writing to the underlying |
private Encoder out; |
83 |
* class. |
|
84 |
*/ |
/*************************************************************************/ |
85 |
private Encoder out; |
|
86 |
|
/* |
87 |
/*************************************************************************/ |
* Constructors |
88 |
|
*/ |
89 |
/* |
|
90 |
* Constructors |
/** |
91 |
*/ |
* This method initializes a new instance of <code>OutputStreamWriter</code> |
92 |
|
* to write to the specified stream using the default encoding. |
93 |
/** |
* |
94 |
* This method initializes a new instance of <code>OutputStreamWriter</code> |
* @param out The <code>OutputStream</code> to write to |
95 |
* to write to the specified stream using the default encoding. |
*/ |
96 |
* |
public OutputStreamWriter(OutputStream out) |
97 |
* @param out The <code>OutputStream</code> to write to |
{ |
98 |
*/ |
this.out = EncodingManager.getEncoder(out); |
99 |
public |
} |
100 |
OutputStreamWriter(OutputStream out) |
|
101 |
{ |
/*************************************************************************/ |
102 |
this.out = EncodingManager.getEncoder(out); |
|
103 |
} |
/** |
104 |
|
* This method initializes a new instance of <code>OutputStreamWriter</code> |
105 |
/*************************************************************************/ |
* to write to the specified stream using a caller supplied character |
106 |
|
* encoding scheme. Note that due to a deficiency in the Java language |
107 |
/** |
* design, there is no way to determine which encodings are supported. |
108 |
* This method initializes a new instance of <code>OutputStreamWriter</code> |
* |
109 |
* to write to the specified stream using a caller supplied character |
* @param out The <code>OutputStream</code> to write to |
110 |
* encoding scheme. Note that due to a deficiency in the Java language |
* @param encoding_scheme The name of the encoding scheme to use for |
111 |
* design, there is no way to determine which encodings are supported. |
* character to byte translation |
112 |
* |
* |
113 |
* @param out The <code>OutputStream</code> to write to |
* @exception UnsupportedEncodingException If the named encoding is |
114 |
* @param encoding_scheme The name of the encoding scheme to use for character to byte translation |
* not available. |
115 |
* |
*/ |
116 |
* @exception UnsupportedEncodingException If the named encoding is not available. |
public OutputStreamWriter(OutputStream out, String encoding_scheme) |
117 |
*/ |
throws UnsupportedEncodingException |
118 |
public |
{ |
119 |
OutputStreamWriter(OutputStream out, String encoding_scheme) |
this.out = EncodingManager.getEncoder(out, encoding_scheme); |
120 |
throws UnsupportedEncodingException |
} |
121 |
{ |
|
122 |
this.out = EncodingManager.getEncoder(out, encoding_scheme); |
/*************************************************************************/ |
123 |
} |
|
124 |
|
/* |
125 |
/*************************************************************************/ |
* Instance Methods |
126 |
|
*/ |
127 |
/* |
|
128 |
* Instance Methods |
/** |
129 |
*/ |
* This method closes this stream, and the underlying |
130 |
|
* <code>OutputStream</code> |
131 |
/** |
* |
132 |
* This method closes this stream, and the underlying <code>OutputStream</code> |
* @exception IOException If an error occurs |
133 |
* |
*/ |
134 |
* @exception IOException If an error occurs |
public void close() throws IOException |
135 |
*/ |
{ |
136 |
public void |
out.close(); |
137 |
close() throws IOException |
} |
138 |
{ |
|
139 |
out.close(); |
/*************************************************************************/ |
140 |
} |
|
141 |
|
/** |
142 |
/*************************************************************************/ |
* This method flushes any buffered bytes to the underlying output sink. |
143 |
|
* |
144 |
/** |
* @exception IOException If an error occurs |
145 |
* This method flushes any buffered bytes to the underlying output sink. |
*/ |
146 |
* |
public void flush() throws IOException |
147 |
* @exception IOException If an error occurs |
{ |
148 |
*/ |
out.flush(); |
149 |
public void |
} |
150 |
flush() throws IOException |
|
151 |
{ |
/*************************************************************************/ |
152 |
out.flush(); |
|
153 |
} |
/** |
154 |
|
* This method returns the name of the character encoding scheme currently |
155 |
/*************************************************************************/ |
* in use by this stream. If the stream has been closed, then this method |
156 |
|
* may return <code>null</code>. |
157 |
/** |
* |
158 |
* This method returns the name of the character encoding scheme currently |
* @return The encoding scheme name |
159 |
* in use by this stream. If the stream has been closed, then this method |
*/ |
160 |
* may return <code>null</code>. |
public String getEncoding() |
161 |
* |
{ |
162 |
* @return The encoding scheme name |
return(out.getSchemeName()); |
163 |
*/ |
} |
164 |
public String |
|
165 |
getEncoding() |
/*************************************************************************/ |
166 |
{ |
|
167 |
return(out.getSchemeName()); |
/** |
168 |
} |
* This method writes a single character to the output stream. |
169 |
|
* |
170 |
/*************************************************************************/ |
* @param c The char to write, passed as an int. |
171 |
|
* |
172 |
/** |
* @exception IOException If an error occurs |
173 |
* This method writes a single character to the output stream. |
*/ |
174 |
* |
public void write(int c) throws IOException |
175 |
* @param c The char to write, passed as an int. |
{ |
176 |
* |
out.write(c); |
177 |
* @exception IOException If an error occurs |
} |
178 |
*/ |
|
179 |
public void |
/*************************************************************************/ |
180 |
write(int c) throws IOException |
|
181 |
{ |
/** |
182 |
out.write(c); |
* This method writes <code>len</code> characters from the specified |
183 |
} |
* array to the output stream starting at position <code>offset</code> |
184 |
|
* into the array. |
185 |
/*************************************************************************/ |
* |
186 |
|
* @param buf The array of character to write from |
187 |
/** |
* @param offset The offset into the array to start writing chars from |
188 |
* This method writes <code>len</code> characters from the specified |
* @param len The number of chars to write. |
189 |
* array to the output stream starting at position <code>offset</code> |
* |
190 |
* into the array. |
* @exception IOException If an error occurs |
191 |
* |
*/ |
192 |
* @param buf The array of character to write from |
public void write(char[] buf, int offset, int len) throws IOException |
193 |
* @param offset The offset into the array to start writing chars from |
{ |
194 |
* @param len The number of chars to write. |
out.write(buf, offset, len); |
195 |
* |
} |
196 |
* @exception IOException If an error occurs |
|
197 |
*/ |
/*************************************************************************/ |
198 |
public void |
|
199 |
write(char[] buf, int offset, int len) throws IOException |
/** |
200 |
{ |
* This method writes <code>len</code> bytes from the specified |
201 |
out.write(buf, offset, len); |
* <code>String</code> starting at position <code>offset</code> into the |
202 |
} |
* <code>String</code>. |
203 |
|
* |
204 |
/*************************************************************************/ |
* @param str The <code>String</code> to write chars from |
205 |
|
* @param offset The position in the <code>String</code> to start |
206 |
/** |
* writing chars from |
207 |
* This method writes <code>len</code> bytes from the specified |
* @param len The number of chars to write |
208 |
* <code>String</code> starting at position <code>offset</code> into the |
* |
209 |
* <code>String</code>. |
* @exception IOException If an error occurs |
210 |
* |
*/ |
211 |
* @param str The <code>String</code> to write chars from |
public void write(String str, int offset, int len) throws IOException |
212 |
* @param offset The position in the <code>String</code> to start writing chars from |
{ |
213 |
* @param len The number of chars to write |
out.write(str, offset, len); |
214 |
* |
} |
|
* @exception IOException If an error occurs |
|
|
*/ |
|
|
public void |
|
|
write(String str, int offset, int len) throws IOException |
|
|
{ |
|
|
out.write(str, offset, len); |
|
|
} |
|
215 |
|
|
216 |
} // class OutputStreamWriter |
} // class OutputStreamWriter |
217 |
|
|