avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: avalon-logkit/src/java/org/apache/log/output/io StreamTarget.java
Date Tue, 15 Apr 2003 16:02:17 GMT
leif        2003/04/15 09:02:17

  Modified:    src/java/org/apache/log/output/io StreamTarget.java
  Log:
  The encoding feature added in the last commit broke logging for Japanese and
  other encodings which contain characters not in the US_ASCII character set.
  Modified so that the default encoding is used if an encoding is not specified.
  
  Revision  Changes    Path
  1.10      +20 -7     avalon-logkit/src/java/org/apache/log/output/io/StreamTarget.java
  
  Index: StreamTarget.java
  ===================================================================
  RCS file: /home/cvs/avalon-logkit/src/java/org/apache/log/output/io/StreamTarget.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StreamTarget.java	26 Feb 2003 08:23:02 -0000	1.9
  +++ StreamTarget.java	15 Apr 2003 16:02:17 -0000	1.10
  @@ -67,13 +67,10 @@
   public class StreamTarget
       extends AbstractOutputTarget
   {
  -    ///Default character encoding
  -    private static final String DEFAULT_ENCODING = "US-ASCII";
  -
  -    ///OutputStream we are writing to
  +    /** OutputStream we are writing to. */
       private OutputStream m_outputStream;
   
  -    //The encoding to use when creating byte array for string
  +    /** The encoding to use when creating byte array for string, may be null. */
       private String m_encoding;
   
       /**
  @@ -81,6 +78,8 @@
        *
        * @param outputStream the OutputStream to write to
        * @param formatter the Formatter to use
  +     * @param encoding Desired encoding to use when writing to the log, null
  +     *                 implies the default system encoding.
        */
       public StreamTarget( final OutputStream outputStream,
                            final Formatter formatter,
  @@ -105,7 +104,12 @@
       public StreamTarget( final OutputStream outputStream,
                            final Formatter formatter )
       {
  -        this( outputStream, formatter, DEFAULT_ENCODING );
  +        // We can get the default system encoding by calling the following
  +        //  method, but it is not a standard API so we work around it by
  +        //  allowing encoding to be null.
  +        //    sun.io.Converters.getDefaultEncodingName();
  +        
  +        this( outputStream, formatter, null );
       }
   
       /**
  @@ -144,7 +148,16 @@
   
           try
           {
  -            outputStream.write( data.getBytes( m_encoding ) );
  +            byte[] bytes;
  +            if ( m_encoding == null )
  +            {
  +                bytes = data.getBytes();
  +            }
  +            else
  +            {
  +                bytes = data.getBytes( m_encoding );
  +            }
  +            outputStream.write( bytes );
               outputStream.flush();
           }
           catch( final IOException ioe )
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message