Coverage Report - org.apache.maven.shared.utils.xml.XmlStreamReader
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlStreamReader
32%
9/28
0%
0/2
1.077
 
 1  
 package org.apache.maven.shared.utils.xml;
 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.IOException;
 25  
 import java.io.InputStream;
 26  
 import java.io.Reader;
 27  
 import java.net.URL;
 28  
 import java.net.URLConnection;
 29  
 import java.util.regex.Pattern;
 30  
 
 31  
 public class XmlStreamReader
 32  
         extends Reader
 33  
 {
 34  
     private final org.apache.commons.io.input.XmlStreamReader reader;
 35  
 
 36  1
     private static String _staticDefaultEncoding = null;
 37  
 
 38  
     public static void setDefaultEncoding( String encoding )
 39  
     {
 40  0
         _staticDefaultEncoding = encoding;
 41  0
     }
 42  
 
 43  
     public static String getDefaultEncoding()
 44  
     {
 45  0
         return _staticDefaultEncoding;
 46  
     }
 47  
 
 48  
     public XmlStreamReader( File file )
 49  
             throws IOException
 50  
     {
 51  0
         this( new FileInputStream( file ) );
 52  0
     }
 53  
 
 54  
     public XmlStreamReader( InputStream is )
 55  
             throws IOException
 56  
     {
 57  23
         this( is, true );
 58  23
     }
 59  
 
 60  
     public XmlStreamReader( InputStream is, boolean lenient )
 61  
             throws IOException, XmlStreamReaderException
 62  23
     {
 63  23
         reader = new org.apache.commons.io.input.XmlStreamReader( is, lenient, _staticDefaultEncoding );
 64  23
     }
 65  
 
 66  
     public XmlStreamReader( URL url )
 67  
             throws IOException
 68  
     {
 69  0
         this( url.openConnection() );
 70  0
     }
 71  
 
 72  
     public XmlStreamReader( URLConnection conn )
 73  
             throws IOException
 74  0
     {
 75  0
         reader = new org.apache.commons.io.input.XmlStreamReader( conn, _staticDefaultEncoding );
 76  0
     }
 77  
 
 78  
     public XmlStreamReader( InputStream is, String httpContentType )
 79  
             throws IOException
 80  
     {
 81  0
         this( is, httpContentType, true );
 82  0
     }
 83  
 
 84  
     public XmlStreamReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding )
 85  
             throws IOException, XmlStreamReaderException
 86  0
     {
 87  0
         reader = new org.apache.commons.io.input.XmlStreamReader( is, httpContentType, lenient,
 88  
                 ( defaultEncoding == null )
 89  
                         ? _staticDefaultEncoding
 90  
                         : defaultEncoding );
 91  0
     }
 92  
 
 93  
     public XmlStreamReader( InputStream is, String httpContentType, boolean lenient )
 94  
             throws IOException, XmlStreamReaderException
 95  
     {
 96  0
         this( is, httpContentType, lenient, null );
 97  0
     }
 98  
 
 99  
     public String getEncoding()
 100  
     {
 101  23
         return reader.getEncoding();
 102  
     }
 103  
 
 104  
     public int read( char[] buf, int offset, int len )
 105  
             throws IOException
 106  
     {
 107  46
         return reader.read( buf, offset, len );
 108  
     }
 109  
 
 110  
     public void close()
 111  
             throws IOException
 112  
     {
 113  0
         reader.close();
 114  0
     }
 115  
 
 116  1
     static final Pattern ENCODING_PATTERN =
 117  
             Pattern.compile( "<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))", Pattern.MULTILINE );
 118  
 }