예제 #1
0
 /** Parse a namespace element out of the response. */
 public Namespace(Response r) throws ProtocolException {
   // Namespace_Element = "(" string SP (<"> QUOTED_CHAR <"> / nil)
   //		*(Namespace_Response_Extension) ")"
   if (r.readByte() != '(') throw new ProtocolException("Missing '(' at start of Namespace");
   // first, the prefix
   prefix = BASE64MailboxDecoder.decode(r.readString());
   r.skipSpaces();
   // delimiter is a quoted character or NIL
   if (r.peekByte() == '"') {
     r.readByte();
     delimiter = (char) r.readByte();
     if (delimiter == '\\') delimiter = (char) r.readByte();
     if (r.readByte() != '"') throw new ProtocolException("Missing '\"' at end of QUOTED_CHAR");
   } else {
     String s = r.readAtom();
     if (s == null) throw new ProtocolException("Expected NIL, got null");
     if (!s.equalsIgnoreCase("NIL")) throw new ProtocolException("Expected NIL, got " + s);
     delimiter = 0;
   }
   // at end of Namespace data?
   if (r.peekByte() != ')') {
     // otherwise, must be a Namespace_Response_Extension
     //    Namespace_Response_Extension = SP string SP
     //	    "(" string *(SP string) ")"
     r.skipSpaces();
     r.readString();
     r.skipSpaces();
     r.readStringList();
   }
   if (r.readByte() != ')') throw new ProtocolException("Missing ')' at end of Namespace");
 }
예제 #2
0
 /** Parse out one of the three sets of namespaces. */
 private Namespace[] getNamespaces(Response r) throws ProtocolException {
   r.skipSpaces();
   //    Namespace = nil / "(" 1*( Namespace_Element) ")"
   if (r.peekByte() == '(') {
     Vector v = new Vector();
     r.readByte();
     do {
       Namespace ns = new Namespace(r);
       v.addElement(ns);
     } while (r.peekByte() != ')');
     r.readByte();
     Namespace[] nsa = new Namespace[v.size()];
     v.copyInto(nsa);
     return nsa;
   } else {
     String s = r.readAtom();
     if (s == null) throw new ProtocolException("Expected NIL, got null");
     if (!s.equalsIgnoreCase("NIL")) throw new ProtocolException("Expected NIL, got " + s);
     return null;
   }
 }