Hi,
the attached patch makes fields of OutputStreamWriter that can be final,
final.
Thanks,
Ian
--- java/io/OutputStreamWriter.java 2007-10-12 13:01:47.0 +0100
+++ java/io/OutputStreamWriter.java 2007-10-19 15:46:37.0 +0100
@@ -91,17 +91,17 @@
/**
* The charset encoder.
*/
- private CharsetEncoder encoder;
+ private final CharsetEncoder encoder;
/**
* java.io canonical name of the encoding.
*/
- private String encodingName;
+ private final String encodingName;
/**
* Buffer output before character conversion as it has costly overhead.
*/
- private CharBuffer outputBuffer;
+ private final CharBuffer outputBuffer;
private final static int BUFFER_SIZE = 1024;
/**
@@ -120,8 +120,10 @@
public OutputStreamWriter (OutputStream out, String encoding_scheme)
throws UnsupportedEncodingException
{
+CharsetEncoder encoder;
+String encodingName;
this.out = out;
- outputBuffer = CharBuffer.allocate(BUFFER_SIZE);
+outputBuffer = CharBuffer.allocate(BUFFER_SIZE);
try
{
@@ -130,42 +132,44 @@
{
encodingName = "ISO8859_1";
encoder = null;
- return;
}
-
- /*
-* Workaround for encodings with a byte-order-mark.
-* We only want to write it once per stream.
-*/
- try
- {
- if(encoding_scheme.equalsIgnoreCase("UnicodeBig") ||
- encoding_scheme.equalsIgnoreCase("UTF-16") ||
- encoding_scheme.equalsIgnoreCase("UTF16"))
+ else
+ {
+ /*
+* Workaround for encodings with a byte-order-mark.
+* We only want to write it once per stream.
+*/
+try
+ {
+ if(encoding_scheme.equalsIgnoreCase("UnicodeBig") ||
+encoding_scheme.equalsIgnoreCase("UTF-16") ||
+encoding_scheme.equalsIgnoreCase("UTF16"))
+ {
+ encoding_scheme = "UTF-16BE";
+out.write((byte)0xFE);
+out.write((byte)0xFF);
+ }
+ else if(encoding_scheme.equalsIgnoreCase("UnicodeLittle"))
+ {
+ encoding_scheme = "UTF-16LE";
+ out.write((byte)0xFF);
+ out.write((byte)0xFE);
+ }
+ }
+ catch(IOException ioe)
{
- encoding_scheme = "UTF-16BE";
- out.write((byte)0xFE);
- out.write((byte)0xFF);
- }
- else if(encoding_scheme.equalsIgnoreCase("UnicodeLittle")){
- encoding_scheme = "UTF-16LE";
- out.write((byte)0xFF);
- out.write((byte)0xFE);
- }
- }
- catch(IOException ioe)
- {
- }
+ }
- Charset cs = EncodingHelper.getCharset(encoding_scheme);
- if(cs == null)
- throw new UnsupportedEncodingException("Encoding "+encoding_scheme+
-" unknown");
- encoder = cs.newEncoder();
- encodingName = EncodingHelper.getOldCanonical(cs.name());
-
- encoder.onMalformedInput(CodingErrorAction.REPLACE);
- encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ Charset cs = EncodingHelper.getCharset(encoding_scheme);
+ if(cs == null)
+ throw new UnsupportedEncodingException("Encoding
"+encoding_scheme+
+" unknown");
+encoder = cs.newEncoder();
+ encodingName = EncodingHelper.getOldCanonical(cs.name());
+
+ encoder.onMalformedInput(CodingErrorAction.REPLACE);
+ encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ }
}
catch(RuntimeException e)
{
@@ -174,6 +178,8 @@
encoder = null;
encodingName = "ISO8859_1";
}
+this.encoder = encoder;
+this.encodingName = encodingName;
}
/**
@@ -184,8 +190,10 @@
*/
public OutputStreamWriter (OutputStream out)
{
+CharsetEncoder encoder;
+String encodingName;
this.out = out;
- outputBuffer = CharBuffer.allocate(BUFFER_SIZE);
+outputBuffer = CharBuffer.allocate(BUFFER_SIZE);
try
{
String encoding = System.getProperty("file.encoding");
@@ -204,6 +212,8 @@
encoder.onMalformedInput(CodingErrorAction.REPLACE);
encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
}
+this.encoder = encoder;
+this.encodingName = encodingName;
}
/**