Class Response

  • Direct Known Subclasses:
    IMAPResponse

    public class Response
    extends java.lang.Object
    This class represents a response obtained from the input stream of an IMAP server.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String ASTRING_CHAR_DELIM
      An ASTRING_CHAR is any CHAR delimited by: SPACE | CTL | '(' | ')' | '{' | '%' | '*' | '"' | '\' (CTL is handled in readDelimString.)
      private static java.lang.String ATOM_CHAR_DELIM
      An ATOM is any CHAR delimited by: SPACE | CTL | '(' | ')' | '{' | '%' | '*' | '"' | '\' | ']' (CTL is handled in readDelimString.)
      static int BAD  
      protected byte[] buffer  
      static int BYE  
      static int CONTINUATION  
      protected java.lang.Exception ex  
      private static int increment  
      protected int index  
      static int NO  
      static int OK  
      protected int pindex  
      protected int size  
      static int SYNTHETIC  
      protected java.lang.String tag  
      static int TAG_MASK  
      static int TAGGED  
      protected int type  
      static int TYPE_MASK  
      static int UNTAGGED  
      protected boolean utf8  
    • Constructor Summary

      Constructors 
      Constructor Description
      Response​(Protocol p)
      Read a new Response from the given Protocol
      Response​(Response r)
      Copy constructor.
      Response​(java.lang.String s)  
      Response​(java.lang.String s, boolean supportsUtf8)
      Constructor for testing.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Response byeResponse​(java.lang.Exception ex)
      Return a Response object that looks like a BYE protocol response.
      java.lang.Exception getException()
      Return the exception for a synthetic BYE response.
      java.lang.String getRest()
      Return the rest of the response as a string, usually used to return the arbitrary message text after a NO response.
      java.lang.String getTag()
      Return the tag, if this is a tagged statement.
      int getType()  
      boolean isBAD()  
      boolean isBYE()  
      boolean isContinuation()  
      boolean isNextNonSpace​(char c)
      Skip past any spaces.
      boolean isNO()  
      boolean isOK()  
      boolean isSynthetic()  
      boolean isTagged()  
      boolean isUnTagged()  
      private void parse()  
      private java.lang.Object parseString​(boolean parseAtoms, boolean returnString)
      Generic parsing routine that can parse out a Quoted-String, Literal or Atom and return the parsed token as a String or a ByteArray.
      byte peekByte()  
      java.lang.String readAtom()
      Extract an ATOM, starting at the current position.
      java.lang.String readAtomString()
      Extract an ASTRING, starting at the current position and return as a String.
      java.lang.String[] readAtomStringList()  
      byte readByte()
      Return the next byte from this Statement.
      ByteArray readByteArray()
      Extract a NSTRING, starting at the current position.
      java.io.ByteArrayInputStream readBytes()
      Extract a NSTRING, starting at the current position.
      private java.lang.String readDelimString​(java.lang.String delim)
      Extract a string stopping at control characters or any character in delim.
      long readLong()
      Extract a long number, starting at the current position.
      int readNumber()
      Extract an integer, starting at the current position.
      java.lang.String readString()
      Extract a NSTRING, starting at the current position.
      java.lang.String readString​(char delim)
      Read a string as an arbitrary sequence of characters, stopping at the delimiter Used to read part of a response code inside [].
      java.lang.String[] readStringList()  
      private java.lang.String[] readStringList​(boolean atom)  
      void reset()
      Reset pointer to beginning of response.
      void skip​(int count)  
      void skipSpaces()  
      void skipToken()
      Skip to the next space, for use in error recovery while parsing.
      boolean supportsUtf8()
      Does the server support UTF-8?
      java.lang.String toString()  
      private java.lang.String toString​(byte[] buffer, int start, int end)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • index

        protected int index
      • pindex

        protected int pindex
      • size

        protected int size
      • buffer

        protected byte[] buffer
      • type

        protected int type
      • tag

        protected java.lang.String tag
      • ex

        protected java.lang.Exception ex
        Since:
        JavaMail 1.5.4
      • utf8

        protected boolean utf8
      • ATOM_CHAR_DELIM

        private static java.lang.String ATOM_CHAR_DELIM
        An ATOM is any CHAR delimited by: SPACE | CTL | '(' | ')' | '{' | '%' | '*' | '"' | '\' | ']' (CTL is handled in readDelimString.)
      • ASTRING_CHAR_DELIM

        private static java.lang.String ASTRING_CHAR_DELIM
        An ASTRING_CHAR is any CHAR delimited by: SPACE | CTL | '(' | ')' | '{' | '%' | '*' | '"' | '\' (CTL is handled in readDelimString.)
    • Constructor Detail

      • Response

        public Response​(java.lang.String s)
      • Response

        public Response​(java.lang.String s,
                        boolean supportsUtf8)
        Constructor for testing.
        Parameters:
        s - the response string
        supportsUtf8 - allow UTF-8 in response?
        Since:
        JavaMail 1.6.0
      • Response

        public Response​(Protocol p)
                 throws java.io.IOException,
                        ProtocolException
        Read a new Response from the given Protocol
        Parameters:
        p - the Protocol object
        Throws:
        java.io.IOException - for I/O errors
        ProtocolException - for protocol failures
      • Response

        public Response​(Response r)
        Copy constructor.
        Parameters:
        r - the Response to copy
    • Method Detail

      • byeResponse

        public static Response byeResponse​(java.lang.Exception ex)
        Return a Response object that looks like a BYE protocol response. Include the details of the exception in the response string.
        Parameters:
        ex - the exception
        Returns:
        the synthetic Response object
      • supportsUtf8

        public boolean supportsUtf8()
        Does the server support UTF-8?
        Returns:
        true if the server supports UTF-8
        Since:
        JavaMail 1.6.0
      • parse

        private void parse()
      • skipSpaces

        public void skipSpaces()
      • isNextNonSpace

        public boolean isNextNonSpace​(char c)
        Skip past any spaces. If the next non-space character is c, consume it and return true. Otherwise stop at that point and return false.
        Parameters:
        c - the character to look for
        Returns:
        true if the character is found
      • skipToken

        public void skipToken()
        Skip to the next space, for use in error recovery while parsing.
      • skip

        public void skip​(int count)
      • peekByte

        public byte peekByte()
      • readByte

        public byte readByte()
        Return the next byte from this Statement.
        Returns:
        the next byte
      • readAtom

        public java.lang.String readAtom()
        Extract an ATOM, starting at the current position. Updates the internal index to beyond the Atom.
        Returns:
        an Atom
      • readDelimString

        private java.lang.String readDelimString​(java.lang.String delim)
        Extract a string stopping at control characters or any character in delim.
      • readString

        public java.lang.String readString​(char delim)
        Read a string as an arbitrary sequence of characters, stopping at the delimiter Used to read part of a response code inside [].
        Parameters:
        delim - the delimiter character
        Returns:
        the string
      • readStringList

        public java.lang.String[] readStringList()
      • readAtomStringList

        public java.lang.String[] readAtomStringList()
      • readStringList

        private java.lang.String[] readStringList​(boolean atom)
      • readNumber

        public int readNumber()
        Extract an integer, starting at the current position. Updates the internal index to beyond the number. Returns -1 if a number was not found.
        Returns:
        a number
      • readLong

        public long readLong()
        Extract a long number, starting at the current position. Updates the internal index to beyond the number. Returns -1 if a long number was not found.
        Returns:
        a long
      • readString

        public java.lang.String readString()
        Extract a NSTRING, starting at the current position. Return it as a String. The sequence 'NIL' is returned as null NSTRING := QuotedString | Literal | "NIL"
        Returns:
        a String
      • readBytes

        public java.io.ByteArrayInputStream readBytes()
        Extract a NSTRING, starting at the current position. Return it as a ByteArrayInputStream. The sequence 'NIL' is returned as null NSTRING := QuotedString | Literal | "NIL"
        Returns:
        a ByteArrayInputStream
      • readByteArray

        public ByteArray readByteArray()
        Extract a NSTRING, starting at the current position. Return it as a ByteArray. The sequence 'NIL' is returned as null NSTRING := QuotedString | Literal | "NIL"
        Returns:
        a ByteArray
      • readAtomString

        public java.lang.String readAtomString()
        Extract an ASTRING, starting at the current position and return as a String. An ASTRING can be a QuotedString, a Literal or an Atom (plus ']'). Any errors in parsing returns null ASTRING := QuotedString | Literal | 1*ASTRING_CHAR
        Returns:
        a String
      • parseString

        private java.lang.Object parseString​(boolean parseAtoms,
                                             boolean returnString)
        Generic parsing routine that can parse out a Quoted-String, Literal or Atom and return the parsed token as a String or a ByteArray. Errors or NIL data will return null.
      • toString

        private java.lang.String toString​(byte[] buffer,
                                          int start,
                                          int end)
      • getType

        public int getType()
      • isContinuation

        public boolean isContinuation()
      • isTagged

        public boolean isTagged()
      • isUnTagged

        public boolean isUnTagged()
      • isOK

        public boolean isOK()
      • isNO

        public boolean isNO()
      • isBAD

        public boolean isBAD()
      • isBYE

        public boolean isBYE()
      • isSynthetic

        public boolean isSynthetic()
      • getTag

        public java.lang.String getTag()
        Return the tag, if this is a tagged statement.
        Returns:
        tag of this tagged statement
      • getRest

        public java.lang.String getRest()
        Return the rest of the response as a string, usually used to return the arbitrary message text after a NO response.
        Returns:
        the rest of the response
      • getException

        public java.lang.Exception getException()
        Return the exception for a synthetic BYE response.
        Returns:
        the exception
        Since:
        JavaMail 1.5.4
      • reset

        public void reset()
        Reset pointer to beginning of response.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object