001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.io.input; 018 019 import java.io.IOException; 020 021 /** 022 * The XmlStreamReaderException is thrown by the XmlStreamReader constructors if 023 * the charset encoding can not be determined according to the XML 1.0 024 * specification and RFC 3023. 025 * <p> 026 * The exception returns the unconsumed InputStream to allow the application to 027 * do an alternate processing with the stream. Note that the original 028 * InputStream given to the XmlStreamReader cannot be used as that one has been 029 * already read. 030 * 031 * @author Alejandro Abdelnur 032 * @version $Id: XmlStreamReaderException.java 1004112 2010-10-04 04:48:25Z niallp $ 033 * @since Commons IO 2.0 034 */ 035 public class XmlStreamReaderException extends IOException { 036 037 private static final long serialVersionUID = 1L; 038 039 private final String bomEncoding; 040 041 private final String xmlGuessEncoding; 042 043 private final String xmlEncoding; 044 045 private final String contentTypeMime; 046 047 private final String contentTypeEncoding; 048 049 /** 050 * Creates an exception instance if the charset encoding could not be 051 * determined. 052 * <p> 053 * Instances of this exception are thrown by the XmlStreamReader. 054 * 055 * @param msg message describing the reason for the exception. 056 * @param bomEnc BOM encoding. 057 * @param xmlGuessEnc XML guess encoding. 058 * @param xmlEnc XML prolog encoding. 059 */ 060 public XmlStreamReaderException(String msg, String bomEnc, 061 String xmlGuessEnc, String xmlEnc) { 062 this(msg, null, null, bomEnc, xmlGuessEnc, xmlEnc); 063 } 064 065 /** 066 * Creates an exception instance if the charset encoding could not be 067 * determined. 068 * <p> 069 * Instances of this exception are thrown by the XmlStreamReader. 070 * 071 * @param msg message describing the reason for the exception. 072 * @param ctMime MIME type in the content-type. 073 * @param ctEnc encoding in the content-type. 074 * @param bomEnc BOM encoding. 075 * @param xmlGuessEnc XML guess encoding. 076 * @param xmlEnc XML prolog encoding. 077 */ 078 public XmlStreamReaderException(String msg, String ctMime, String ctEnc, 079 String bomEnc, String xmlGuessEnc, String xmlEnc) { 080 super(msg); 081 contentTypeMime = ctMime; 082 contentTypeEncoding = ctEnc; 083 bomEncoding = bomEnc; 084 xmlGuessEncoding = xmlGuessEnc; 085 xmlEncoding = xmlEnc; 086 } 087 088 /** 089 * Returns the BOM encoding found in the InputStream. 090 * 091 * @return the BOM encoding, null if none. 092 */ 093 public String getBomEncoding() { 094 return bomEncoding; 095 } 096 097 /** 098 * Returns the encoding guess based on the first bytes of the InputStream. 099 * 100 * @return the encoding guess, null if it couldn't be guessed. 101 */ 102 public String getXmlGuessEncoding() { 103 return xmlGuessEncoding; 104 } 105 106 /** 107 * Returns the encoding found in the XML prolog of the InputStream. 108 * 109 * @return the encoding of the XML prolog, null if none. 110 */ 111 public String getXmlEncoding() { 112 return xmlEncoding; 113 } 114 115 /** 116 * Returns the MIME type in the content-type used to attempt determining the 117 * encoding. 118 * 119 * @return the MIME type in the content-type, null if there was not 120 * content-type or the encoding detection did not involve HTTP. 121 */ 122 public String getContentTypeMime() { 123 return contentTypeMime; 124 } 125 126 /** 127 * Returns the encoding in the content-type used to attempt determining the 128 * encoding. 129 * 130 * @return the encoding in the content-type, null if there was not 131 * content-type, no encoding in it or the encoding detection did not 132 * involve HTTP. 133 */ 134 public String getContentTypeEncoding() { 135 return contentTypeEncoding; 136 } 137 }