View Javadoc

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