XmlReaderException.java
001 package com.sun.syndication.io;
002 
003 
004 import java.io.InputStream;
005 import java.io.IOException;
006 
007 /**
008  * The XmlReaderException is thrown by the XmlReader constructors if the charset encoding can not be
009  * determined according to the XML 1.0 specification and RFC 3023.
010  <p>
011  * The exception returns the unconsumed InputStream to allow the application to do an alternate
012  * processing with the stream. Note that the original InputStream given to the XmlReader cannot be
013  * used as that one has been already read.
014  <p>
015  
016  @author Alejandro Abdelnur
017  @version revision 1.8 taken on 2008-03-06 from Rome (see
018  *          https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java)
019  */
020 public class XmlReaderException extends IOException {
021     private String _bomEncoding;
022     private String _xmlGuessEncoding;
023     private String _xmlEncoding;
024     private String _contentTypeMime;
025     private String _contentTypeEncoding;
026     private InputStream _is;
027 
028     /**
029      * Creates an exception instance if the charset encoding could not be determined.
030      <p>
031      * Instances of this exception are thrown by the XmlReader.
032      <p>
033      
034      @param msg message describing the reason for the exception.
035      @param bomEnc BOM encoding.
036      @param xmlGuessEnc XML guess encoding.
037      @param xmlEnc XML prolog encoding.
038      @param is the unconsumed InputStream.
039      */
040     public XmlReaderException(String msg,String bomEnc,String xmlGuessEnc,String xmlEnc,InputStream is) {
041         this(msg,null,null,bomEnc,xmlGuessEnc,xmlEnc,is);
042     }
043 
044     /**
045      * Creates an exception instance if the charset encoding could not be determined.
046      <p>
047      * Instances of this exception are thrown by the XmlReader.
048      <p>
049      
050      @param msg message describing the reason for the exception.
051      @param ctMime MIME type in the content-type.
052      @param ctEnc encoding in the content-type.
053      @param bomEnc BOM encoding.
054      @param xmlGuessEnc XML guess encoding.
055      @param xmlEnc XML prolog encoding.
056      @param is the unconsumed InputStream.
057      */
058     public XmlReaderException(String msg,String ctMime,String ctEnc,
059                               String bomEnc,String xmlGuessEnc,String xmlEnc,InputStream is) {
060         super(msg);
061         _contentTypeMime = ctMime;
062         _contentTypeEncoding = ctEnc;
063         _bomEncoding = bomEnc;
064         _xmlGuessEncoding = xmlGuessEnc;
065         _xmlEncoding = xmlEnc;
066         _is = is;
067     }
068 
069     /**
070      * Returns the BOM encoding found in the InputStream.
071      <p>
072      
073      @return the BOM encoding, null if none.
074      */
075     public String getBomEncoding() {
076         return _bomEncoding;
077     }
078 
079     /**
080      * Returns the encoding guess based on the first bytes of the InputStream.
081      <p>
082      
083      @return the encoding guess, null if it couldn't be guessed.
084      */
085     public String getXmlGuessEncoding() {
086         return _xmlGuessEncoding;
087     }
088 
089     /**
090      * Returns the encoding found in the XML prolog of the InputStream.
091      <p>
092      
093      @return the encoding of the XML prolog, null if none.
094      */
095     public String getXmlEncoding() {
096         return _xmlEncoding;
097     }
098 
099     /**
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 }