FileDocCategorySizeDatePackage
PersistString.javaAPI DocExample2911Sat Sep 12 03:01:00 BST 1998borland.samples.apps.chess.client

PersistString

public class PersistString extends Object
re-invent the wheel: Concatenate an array of Strings in such a way that they can hold any data and be parsed back into the array of strings they were created from Simplifies passing multiparameter messages between client and server

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.Stringconcat(java.lang.String[] data)

    String retVal = "";
    for (int i=0;i < data.length && data[i] != null ;i++)
       retVal = retVal + i + "\"" + PersistString.padQuotes(data[i])+ "\"" ;
    return  retVal;
  
static java.lang.StringpadQuotes(java.lang.String data)

    int index = 0 ;
    int oldIndex = 0;
    while (index >= 0) {
      index = data.indexOf('\"",oldIndex);
      if (index > 0) {
        data = data.substring(0,index) + "\"" + data.substring(index );
        //System.out.println ("Found a quote in the data " + data);
        oldIndex = index + 2;
      }
    }
    return data;
  
public static java.lang.String[]parse(java.lang.String infoData)

    Vector output = new Vector(10);
    StringReader stream = new StringReader(infoData);
    //StringBufferInputStream stream  = new StringBufferInputStream(infoData);
    //StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(stream, 1000));
    StreamTokenizer st = new StreamTokenizer(stream);

    try {
      st.nextToken();
      while(true) {
        String data = null;
        while (st.nextToken() == '"") {
          if (data == null)
            data = st.sval;
          else
            data = data + "\"" + st.sval;
        }
        output.addElement(data);
        if (st.ttype == StreamTokenizer.TT_EOF)
          break;
      }
    }
    catch (Exception e) {
      System.out.println("PersistStream error " + e);
    }
    String [] outputArray = new String [output.size()];
    for (int i=0;i<output.size();i++)
      outputArray[i] = (String) output.elementAt(i);
    return outputArray;