| 1 | package com.sun.syndication.io; |
| 2 | |
| 3 | |
| 4 | import java.io.InputStream; |
| 5 | import java.io.IOException; |
| 6 | |
| 7 | /** |
| 8 | * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be |
| 9 | * determined according to the XML 1.0 specification and RFC 3023. |
| 10 | * <p> |
| 11 | * The exception returns the unconsumed InputStream to allow the application to do an alternate |
| 12 | * processing with the stream. Note that the original InputStream given to the XmlReader cannot be |
| 13 | * used as that one has been already read. |
| 14 | * <p> |
| 15 | * |
| 16 | * @author Alejandro Abdelnur |
| 17 | * @version revision 1.8 taken on 2008-03-06 from Rome (see |
| 18 | * https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) |
| 19 | */ |
| 20 | public class XmlReaderException extends IOException { |
| 21 | private String _bomEncoding; |
| 22 | private String _xmlGuessEncoding; |
| 23 | private String _xmlEncoding; |
| 24 | private String _contentTypeMime; |
| 25 | private String _contentTypeEncoding; |
| 26 | private InputStream _is; |
| 27 | |
| 28 | /** |
| 29 | * Creates an exception instance if the charset encoding could not be determined. |
| 30 | * <p> |
| 31 | * Instances of this exception are thrown by the XmlReader. |
| 32 | * <p> |
| 33 | * |
| 34 | * @param msg message describing the reason for the exception. |
| 35 | * @param bomEnc BOM encoding. |
| 36 | * @param xmlGuessEnc XML guess encoding. |
| 37 | * @param xmlEnc XML prolog encoding. |
| 38 | * @param is the unconsumed InputStream. |
| 39 | */ |
| 40 | public XmlReaderException(String msg,String bomEnc,String xmlGuessEnc,String xmlEnc,InputStream is) { |
| 41 | this(msg,null,null,bomEnc,xmlGuessEnc,xmlEnc,is); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates an exception instance if the charset encoding could not be determined. |
| 46 | * <p> |
| 47 | * Instances of this exception are thrown by the XmlReader. |
| 48 | * <p> |
| 49 | * |
| 50 | * @param msg message describing the reason for the exception. |
| 51 | * @param ctMime MIME type in the content-type. |
| 52 | * @param ctEnc encoding in the content-type. |
| 53 | * @param bomEnc BOM encoding. |
| 54 | * @param xmlGuessEnc XML guess encoding. |
| 55 | * @param xmlEnc XML prolog encoding. |
| 56 | * @param is the unconsumed InputStream. |
| 57 | */ |
| 58 | public XmlReaderException(String msg,String ctMime,String ctEnc, |
| 59 | String bomEnc,String xmlGuessEnc,String xmlEnc,InputStream is) { |
| 60 | super(msg); |
| 61 | _contentTypeMime = ctMime; |
| 62 | _contentTypeEncoding = ctEnc; |
| 63 | _bomEncoding = bomEnc; |
| 64 | _xmlGuessEncoding = xmlGuessEnc; |
| 65 | _xmlEncoding = xmlEnc; |
| 66 | _is = is; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns the BOM encoding found in the InputStream. |
| 71 | * <p> |
| 72 | * |
| 73 | * @return the BOM encoding, null if none. |
| 74 | */ |
| 75 | public String getBomEncoding() { |
| 76 | return _bomEncoding; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the encoding guess based on the first bytes of the InputStream. |
| 81 | * <p> |
| 82 | * |
| 83 | * @return the encoding guess, null if it couldn't be guessed. |
| 84 | */ |
| 85 | public String getXmlGuessEncoding() { |
| 86 | return _xmlGuessEncoding; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the encoding found in the XML prolog of the InputStream. |
| 91 | * <p> |
| 92 | * |
| 93 | * @return the encoding of the XML prolog, null if none. |
| 94 | */ |
| 95 | public String getXmlEncoding() { |
| 96 | return _xmlEncoding; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns the MIME type in the content-type used to attempt determining the encoding. |
| 101 | * <p> |
| 102 | * |
| 103 | * @return the MIME type in the content-type, null if there was not content-type or the encoding |
| 104 | * detection did not involve HTTP. |
| 105 | */ |
| 106 | public String getContentTypeMime() { |
| 107 | return _contentTypeMime; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the encoding in the content-type used to attempt determining the encoding. |
| 112 | * <p> |
| 113 | * |
| 114 | * @return the encoding in the content-type, null if there was not content-type, no encoding in |
| 115 | * it or the encoding detection did not involve HTTP. |
| 116 | */ |
| 117 | public String getContentTypeEncoding() { |
| 118 | return _contentTypeEncoding; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Returns the unconsumed InputStream to allow the application to do an alternate encoding |
| 123 | * detection on the InputStream. |
| 124 | * <p> |
| 125 | * |
| 126 | * @return the unconsumed InputStream. |
| 127 | */ |
| 128 | public InputStream getInputStream() { |
| 129 | return _is; |
| 130 | } |
| 131 | } |