| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| XmlStreamReaderException |
|
| 1.0;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 | * @version $Id: XmlStreamReaderException.java 1415850 2012-11-30 20:51:39Z ggregory $ | |
| 32 | * @since 2.0 | |
| 33 | */ | |
| 34 | public class XmlStreamReaderException extends IOException { | |
| 35 | ||
| 36 | private static final long serialVersionUID = 1L; | |
| 37 | ||
| 38 | private final String bomEncoding; | |
| 39 | ||
| 40 | private final String xmlGuessEncoding; | |
| 41 | ||
| 42 | private final String xmlEncoding; | |
| 43 | ||
| 44 | private final String contentTypeMime; | |
| 45 | ||
| 46 | private final String contentTypeEncoding; | |
| 47 | ||
| 48 | /** | |
| 49 | * Creates an exception instance if the charset encoding could not be | |
| 50 | * determined. | |
| 51 | * <p> | |
| 52 | * Instances of this exception are thrown by the XmlStreamReader. | |
| 53 | * | |
| 54 | * @param msg message describing the reason for the exception. | |
| 55 | * @param bomEnc BOM encoding. | |
| 56 | * @param xmlGuessEnc XML guess encoding. | |
| 57 | * @param xmlEnc XML prolog encoding. | |
| 58 | */ | |
| 59 | public XmlStreamReaderException(final String msg, final String bomEnc, | |
| 60 | final String xmlGuessEnc, final String xmlEnc) { | |
| 61 | 55 | this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc); |
| 62 | 55 | } |
| 63 | ||
| 64 | /** | |
| 65 | * Creates an exception instance if the charset encoding could not be | |
| 66 | * determined. | |
| 67 | * <p> | |
| 68 | * Instances of this exception are thrown by the XmlStreamReader. | |
| 69 | * | |
| 70 | * @param msg message describing the reason for the exception. | |
| 71 | * @param ctMime MIME type in the content-type. | |
| 72 | * @param ctEnc encoding in the content-type. | |
| 73 | * @param bomEnc BOM encoding. | |
| 74 | * @param xmlGuessEnc XML guess encoding. | |
| 75 | * @param xmlEnc XML prolog encoding. | |
| 76 | */ | |
| 77 | public XmlStreamReaderException(final String msg, final String ctMime, final String ctEnc, | |
| 78 | final String bomEnc, final String xmlGuessEnc, final String xmlEnc) { | |
| 79 | 362 | super(msg); |
| 80 | 362 | contentTypeMime = ctMime; |
| 81 | 362 | contentTypeEncoding = ctEnc; |
| 82 | 362 | bomEncoding = bomEnc; |
| 83 | 362 | xmlGuessEncoding = xmlGuessEnc; |
| 84 | 362 | xmlEncoding = xmlEnc; |
| 85 | 362 | } |
| 86 | ||
| 87 | /** | |
| 88 | * Returns the BOM encoding found in the InputStream. | |
| 89 | * | |
| 90 | * @return the BOM encoding, null if none. | |
| 91 | */ | |
| 92 | public String getBomEncoding() { | |
| 93 | 97 | return bomEncoding; |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Returns the encoding guess based on the first bytes of the InputStream. | |
| 98 | * | |
| 99 | * @return the encoding guess, null if it couldn't be guessed. | |
| 100 | */ | |
| 101 | public String getXmlGuessEncoding() { | |
| 102 | 97 | return xmlGuessEncoding; |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Returns the encoding found in the XML prolog of the InputStream. | |
| 107 | * | |
| 108 | * @return the encoding of the XML prolog, null if none. | |
| 109 | */ | |
| 110 | public String getXmlEncoding() { | |
| 111 | 324 | return xmlEncoding; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Returns the MIME type in the content-type used to attempt determining the | |
| 116 | * encoding. | |
| 117 | * | |
| 118 | * @return the MIME type in the content-type, null if there was not | |
| 119 | * content-type or the encoding detection did not involve HTTP. | |
| 120 | */ | |
| 121 | public String getContentTypeMime() { | |
| 122 | 96 | return contentTypeMime; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Returns the encoding in the content-type used to attempt determining the | |
| 127 | * encoding. | |
| 128 | * | |
| 129 | * @return the encoding in the content-type, null if there was not | |
| 130 | * content-type, no encoding in it or the encoding detection did not | |
| 131 | * involve HTTP. | |
| 132 | */ | |
| 133 | public String getContentTypeEncoding() { | |
| 134 | 323 | return contentTypeEncoding; |
| 135 | } | |
| 136 | } |