Coverage Report - org.apache.commons.io.input.XmlStreamReaderException
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlStreamReaderException
100%
14/14
N/A
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.io.input;
 18  
 
 19  
 import java.io.IOException;
 20  
 
 21  
 /**
 22  
  * The XmlStreamReaderException is thrown by the XmlStreamReader constructors if
 23  
  * the charset encoding can not be determined according to the XML 1.0
 24  
  * specification and RFC 3023.
 25  
  * <p>
 26  
  * The exception returns the unconsumed InputStream to allow the application to
 27  
  * do an alternate processing with the stream. Note that the original
 28  
  * InputStream given to the XmlStreamReader cannot be used as that one has been
 29  
  * already read.
 30  
  *
 31  
  * @since 2.0
 32  
  */
 33  
 public class XmlStreamReaderException extends IOException {
 34  
 
 35  
     private static final long serialVersionUID = 1L;
 36  
 
 37  
     private final String bomEncoding;
 38  
 
 39  
     private final String xmlGuessEncoding;
 40  
 
 41  
     private final String xmlEncoding;
 42  
 
 43  
     private final String contentTypeMime;
 44  
 
 45  
     private final String contentTypeEncoding;
 46  
 
 47  
     /**
 48  
      * Creates an exception instance if the charset encoding could not be
 49  
      * determined.
 50  
      * <p>
 51  
      * Instances of this exception are thrown by the XmlStreamReader.
 52  
      *
 53  
      * @param msg message describing the reason for the exception.
 54  
      * @param bomEnc BOM encoding.
 55  
      * @param xmlGuessEnc XML guess encoding.
 56  
      * @param xmlEnc XML prolog encoding.
 57  
      */
 58  
     public XmlStreamReaderException(final String msg, final String bomEnc,
 59  
             final String xmlGuessEnc, final String xmlEnc) {
 60  110
         this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc);
 61  110
     }
 62  
 
 63  
     /**
 64  
      * Creates an exception instance if the charset encoding could not be
 65  
      * determined.
 66  
      * <p>
 67  
      * Instances of this exception are thrown by the XmlStreamReader.
 68  
      *
 69  
      * @param msg message describing the reason for the exception.
 70  
      * @param ctMime MIME type in the content-type.
 71  
      * @param ctEnc encoding in the content-type.
 72  
      * @param bomEnc BOM encoding.
 73  
      * @param xmlGuessEnc XML guess encoding.
 74  
      * @param xmlEnc XML prolog encoding.
 75  
      */
 76  
     public XmlStreamReaderException(final String msg, final String ctMime, final String ctEnc,
 77  
             final String bomEnc, final String xmlGuessEnc, final String xmlEnc) {
 78  724
         super(msg);
 79  724
         contentTypeMime = ctMime;
 80  724
         contentTypeEncoding = ctEnc;
 81  724
         bomEncoding = bomEnc;
 82  724
         xmlGuessEncoding = xmlGuessEnc;
 83  724
         xmlEncoding = xmlEnc;
 84  724
     }
 85  
 
 86  
     /**
 87  
      * Returns the BOM encoding found in the InputStream.
 88  
      *
 89  
      * @return the BOM encoding, null if none.
 90  
      */
 91  
     public String getBomEncoding() {
 92  194
         return bomEncoding;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Returns the encoding guess based on the first bytes of the InputStream.
 97  
      *
 98  
      * @return the encoding guess, null if it couldn't be guessed.
 99  
      */
 100  
     public String getXmlGuessEncoding() {
 101  194
         return xmlGuessEncoding;
 102  
     }
 103  
 
 104  
     /**
 105  
      * Returns the encoding found in the XML prolog of the InputStream.
 106  
      *
 107  
      * @return the encoding of the XML prolog, null if none.
 108  
      */
 109  
     public String getXmlEncoding() {
 110  648
         return xmlEncoding;
 111  
     }
 112  
 
 113  
     /**
 114  
      * Returns the MIME type in the content-type used to attempt determining the
 115  
      * encoding.
 116  
      *
 117  
      * @return the MIME type in the content-type, null if there was not
 118  
      *         content-type or the encoding detection did not involve HTTP.
 119  
      */
 120  
     public String getContentTypeMime() {
 121  192
         return contentTypeMime;
 122  
     }
 123  
 
 124  
     /**
 125  
      * Returns the encoding in the content-type used to attempt determining the
 126  
      * encoding.
 127  
      *
 128  
      * @return the encoding in the content-type, null if there was not
 129  
      *         content-type, no encoding in it or the encoding detection did not
 130  
      *         involve HTTP.
 131  
      */
 132  
     public String getContentTypeEncoding() {
 133  646
         return contentTypeEncoding;
 134  
     }
 135  
 }