Ejemplo n.º 1
0
  /**
   * Read a list of space-separated "flag_extension" sequences and return the list as a array of
   * Strings. An empty list is returned as null. This is an IMAP-ism, and perhaps this method should
   * moved into the IMAP layer.
   */
  public String[] readSimpleList() {
    skipSpaces();

    if (buffer[index] != '(') // not what we expected
    return null;
    index++; // skip '('

    Vector v = new Vector();
    int start;
    for (start = index; buffer[index] != ')'; index++) {
      if (buffer[index] == ' ') { // got one item
        v.addElement(ASCIIUtility.toString(buffer, start, index));
        start = index + 1; // index gets incremented at the top
      }
    }
    if (index > start) // get the last item
    v.addElement(ASCIIUtility.toString(buffer, start, index));
    index++; // skip ')'

    int size = v.size();
    if (size > 0) {
      String[] s = new String[size];
      v.copyInto(s);
      return s;
    } else // empty list
    return null;
  }
Ejemplo n.º 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;
   }
 }