Coverage Report - org.codehaus.plexus.util.WriterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
WriterFactory
25%
2/8
N/A
1
 
 1  
 package org.codehaus.plexus.util;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.FileNotFoundException;
 24  
 import java.io.FileOutputStream;
 25  
 import java.io.FileWriter;
 26  
 import java.io.IOException;
 27  
 import java.io.OutputStream;
 28  
 import java.io.OutputStreamWriter;
 29  
 import java.io.UnsupportedEncodingException;
 30  
 import java.io.Writer;
 31  
 import java.nio.charset.Charset;
 32  
 
 33  
 import org.codehaus.plexus.util.xml.XmlStreamWriter;
 34  
 
 35  
 /**
 36  
  * Utility to create Writers, with explicit encoding choice: platform default,
 37  
  * XML, or specified.
 38  
  * 
 39  
  * @author <a href="mailto:hboutemy@codehaus.org">Herve Boutemy</a>
 40  
  * @see Charset
 41  
  * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 42  
  * @version $Id: WriterFactory.java 630430 2008-02-23 13:16:25Z olamy $
 43  
  * @since 1.4.4
 44  
  * @deprecated TO BE REMOVED from here when plexus-utils is upgraded to 1.4.5+ (and prerequisite upgraded to Maven 2.0.6)
 45  
  */
 46  0
 public class WriterFactory
 47  
 {
 48  
     /**
 49  
      * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
 50  
      * Every implementation of the Java platform is required to support this character encoding.
 51  
      * @see Charset
 52  
      */
 53  
     public static final String ISO_8859_1 = "ISO-8859-1";
 54  
 
 55  
     /**
 56  
      * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
 57  
      * Every implementation of the Java platform is required to support this character encoding.
 58  
      * @see Charset
 59  
      */
 60  
     public static final String US_ASCII = "US-ASCII";
 61  
 
 62  
     /**
 63  
      * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
 64  
      * order accepted on input, big-endian used on output).
 65  
      * Every implementation of the Java platform is required to support this character encoding.
 66  
      * @see Charset
 67  
      */
 68  
     public static final String UTF_16 = "UTF-16";
 69  
 
 70  
     /**
 71  
      * Sixteen-bit Unicode Transformation Format, big-endian byte order.
 72  
      * Every implementation of the Java platform is required to support this character encoding.
 73  
      * @see Charset
 74  
      */
 75  
     public static final String UTF_16BE = "UTF-16BE";
 76  
 
 77  
     /**
 78  
      * Sixteen-bit Unicode Transformation Format, little-endian byte order.
 79  
      * Every implementation of the Java platform is required to support this character encoding.
 80  
      * @see Charset
 81  
      */
 82  
     public static final String UTF_16LE = "UTF-16LE";
 83  
 
 84  
     /**
 85  
      * Eight-bit Unicode Transformation Format.
 86  
      * Every implementation of the Java platform is required to support this character encoding.
 87  
      * @see Charset
 88  
      */
 89  
     public static final String UTF_8 = "UTF-8";
 90  
 
 91  
     /**
 92  
      * The <code>file.encoding</code> System Property.
 93  
      */
 94  1
     public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
 95  
     
 96  
     /**
 97  
      * Create a new Writer with XML encoding detection rules.
 98  
      * @see XmlStreamWriter
 99  
      */
 100  
     public static XmlStreamWriter newXmlWriter( OutputStream out )
 101  
     throws IOException
 102  
     {
 103  0
         return new XmlStreamWriter( out );
 104  
     }
 105  
 
 106  
     /**
 107  
      * Create a new Writer with XML encoding detection rules.
 108  
      * @see XmlStreamWriter
 109  
      */
 110  
     public static XmlStreamWriter newXmlWriter( File file )
 111  
     throws IOException
 112  
     {
 113  5
         return new XmlStreamWriter( file );
 114  
     }
 115  
 
 116  
     /**
 117  
      * Create a new Writer with default plaform encoding.
 118  
      */
 119  
     public static Writer newPlatformWriter( OutputStream out )
 120  
     {
 121  0
         return new OutputStreamWriter( out );
 122  
     }
 123  
 
 124  
     /**
 125  
      * Create a new Writer with default plaform encoding.
 126  
      */
 127  
     public static Writer newPlatformWriter( File file )
 128  
     throws IOException
 129  
     {
 130  0
         return new FileWriter( file );
 131  
     }
 132  
 
 133  
     /**
 134  
      * Create a new Writer with specified encoding.
 135  
      * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 136  
      */
 137  
     public static Writer newWriter( OutputStream out, String encoding )
 138  
     throws UnsupportedEncodingException
 139  
     {
 140  0
         return new OutputStreamWriter( out, encoding );
 141  
     }
 142  
 
 143  
     /**
 144  
      * Create a new Writer with specified encoding.
 145  
      * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 146  
      */
 147  
     public static Writer newWriter( File file, String encoding )
 148  
     throws UnsupportedEncodingException, FileNotFoundException
 149  
     {
 150  0
         return newWriter( new FileOutputStream(file), encoding );
 151  
     }
 152  
 }