Coverage Report - org.codehaus.plexus.util.ReaderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ReaderFactory
18%
2/11
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.FileInputStream;
 24  
 import java.io.FileNotFoundException;
 25  
 import java.io.FileReader;
 26  
 import java.io.IOException;
 27  
 import java.io.InputStream;
 28  
 import java.io.InputStreamReader;
 29  
 import java.io.Reader;
 30  
 import java.io.UnsupportedEncodingException;
 31  
 import java.net.URL;
 32  
 import java.nio.charset.Charset;
 33  
 
 34  
 import org.codehaus.plexus.util.xml.XmlStreamReader;
 35  
 
 36  
 /**
 37  
  * Utility to create Readers from streams, with explicit encoding choice: platform default,
 38  
  * XML, or specified.
 39  
  * 
 40  
  * @author <a href="mailto:hboutemy@codehaus.org">Herve Boutemy</a>
 41  
  * @see Charset
 42  
  * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 43  
  * @version $Id: ReaderFactory.java 630430 2008-02-23 13:16:25Z olamy $
 44  
  * @since 1.4.3
 45  
  * @deprecated TO BE REMOVED from here when plexus-utils is upgraded to 1.4.5+ (and prerequisite upgraded to Maven 2.0.6)
 46  
  */
 47  0
 public class ReaderFactory
 48  
 {
 49  
     /**
 50  
      * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
 51  
      * Every implementation of the Java platform is required to support this character encoding.
 52  
      * @see Charset
 53  
      */
 54  
     public static final String ISO_8859_1 = "ISO-8859-1";
 55  
 
 56  
     /**
 57  
      * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
 58  
      * Every implementation of the Java platform is required to support this character encoding.
 59  
      * @see Charset
 60  
      */
 61  
     public static final String US_ASCII = "US-ASCII";
 62  
 
 63  
     /**
 64  
      * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
 65  
      * order accepted on input, big-endian used on output).
 66  
      * Every implementation of the Java platform is required to support this character encoding.
 67  
      * @see Charset
 68  
      */
 69  
     public static final String UTF_16 = "UTF-16";
 70  
 
 71  
     /**
 72  
      * Sixteen-bit Unicode Transformation Format, big-endian byte order.
 73  
      * Every implementation of the Java platform is required to support this character encoding.
 74  
      * @see Charset
 75  
      */
 76  
     public static final String UTF_16BE = "UTF-16BE";
 77  
 
 78  
     /**
 79  
      * Sixteen-bit Unicode Transformation Format, little-endian byte order.
 80  
      * Every implementation of the Java platform is required to support this character encoding.
 81  
      * @see Charset
 82  
      */
 83  
     public static final String UTF_16LE = "UTF-16LE";
 84  
 
 85  
     /**
 86  
      * Eight-bit Unicode Transformation Format.
 87  
      * Every implementation of the Java platform is required to support this character encoding.
 88  
      * @see Charset
 89  
      */
 90  
     public static final String UTF_8 = "UTF-8";
 91  
 
 92  
     /**
 93  
      * The <code>file.encoding</code> System Property.
 94  
      */
 95  1
     public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
 96  
     
 97  
     /**
 98  
      * Create a new Reader with XML encoding detection rules.
 99  
      * @see XmlStreamReader
 100  
      */
 101  
     public static XmlStreamReader newXmlReader( InputStream in )
 102  
     throws IOException
 103  
     {
 104  0
         return new XmlStreamReader( in );
 105  
     }
 106  
 
 107  
     /**
 108  
      * Create a new Reader with XML encoding detection rules.
 109  
      * @see XmlStreamReader
 110  
      */
 111  
     public static XmlStreamReader newXmlReader( File file )
 112  
     throws IOException
 113  
     {
 114  30
         return new XmlStreamReader( file );
 115  
     }
 116  
     
 117  
     /**
 118  
      * Create a new Reader with XML encoding detection rules.
 119  
      * @see XmlStreamReader
 120  
      */
 121  
     public static XmlStreamReader newXmlReader( URL url )
 122  
     throws IOException
 123  
     {
 124  0
         return new XmlStreamReader( url );
 125  
     }
 126  
 
 127  
     /**
 128  
      * Create a new Reader with default plaform encoding.
 129  
      */
 130  
     public static Reader newPlatformReader( InputStream in )
 131  
     {
 132  0
         return new InputStreamReader( in );
 133  
     }
 134  
 
 135  
     /**
 136  
      * Create a new Reader with default plaform encoding.
 137  
      */
 138  
     public static Reader newPlatformReader( File file )
 139  
     throws FileNotFoundException
 140  
     {
 141  0
         return new FileReader( file );
 142  
     }
 143  
 
 144  
     /**
 145  
      * Create a new Reader with default plaform encoding.
 146  
      */
 147  
     public static Reader newPlatformReader( URL url )
 148  
     throws IOException
 149  
     {
 150  0
         return new InputStreamReader( url.openStream() );
 151  
     }
 152  
 
 153  
     /**
 154  
      * Create a new Reader with specified encoding.
 155  
      * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 156  
      */
 157  
     public static Reader newReader( InputStream in, String encoding )
 158  
     throws UnsupportedEncodingException
 159  
     {
 160  0
         return new InputStreamReader( in, encoding );
 161  
     }
 162  
 
 163  
     /**
 164  
      * Create a new Reader with specified encoding.
 165  
      * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 166  
      */
 167  
     public static Reader newReader( File file, String encoding )
 168  
     throws FileNotFoundException, UnsupportedEncodingException
 169  
     {
 170  0
         return new InputStreamReader( new FileInputStream(file), encoding );
 171  
     }
 172  
 
 173  
     /**
 174  
      * Create a new Reader with specified encoding.
 175  
      * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
 176  
      */
 177  
     public static Reader newReader( URL url, String encoding )
 178  
     throws IOException
 179  
     {
 180  0
         return new InputStreamReader( url.openStream(), encoding );
 181  
     }
 182  
 }