Back to index

moin  1.9.0~rc2
Public Member Functions | Private Member Functions | Private Attributes
CH.ifa.draw.util.StorableInput Class Reference

An input stream that can be used to resurrect Storable objects. More...

Collaboration diagram for CH.ifa.draw.util.StorableInput:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StorableInput (InputStream stream)
 Initializes a Storable input with the given input stream.
Storable readStorable () throws IOException
 Reads and resurrects a Storable object from the input stream.
boolean testForNumber () throws IOException
 Determine if the next input token is a valid number or not.
String readString () throws IOException
 Reads a string from the input stream.
int readInt () throws IOException
 Reads an int from the input stream.
Color readColor () throws IOException
 Reads a color from the input stream.
double readDouble () throws IOException
 Reads a double from the input stream.
boolean readBoolean () throws IOException
 Reads a boolean from the input stream.

Private Member Functions

Object makeInstance (String className) throws IOException
void map (Storable storable)
Storable retrieve (int ref)

Private Attributes

StreamTokenizer fTokenizer
Vector fMap

Detailed Description

An input stream that can be used to resurrect Storable objects.

StorableInput preserves the object identity of the stored objects.

See also:
Storable
StorableOutput

Definition at line 20 of file StorableInput.java.


Constructor & Destructor Documentation

CH.ifa.draw.util.StorableInput.StorableInput ( InputStream  stream) [inline]

Initializes a Storable input with the given input stream.

Definition at line 29 of file StorableInput.java.

                                             {
        Reader r = new BufferedReader(new InputStreamReader(stream));
        fTokenizer = new StreamTokenizer(r);
        fMap = new Vector();
    }

Member Function Documentation

Object CH.ifa.draw.util.StorableInput.makeInstance ( String  className) throws IOException [inline, private]

Definition at line 121 of file StorableInput.java.

                                                                     {
        try {
            Class cl = Class.forName(className);
            return cl.newInstance();
        } catch (NoSuchMethodError e) {
            throw new IOException("Class " + className
                + " does not seem to have a no-arg constructor");
        } catch (ClassNotFoundException e) {
            throw new IOException("No class: " + className);
        } catch (InstantiationException e) {
            throw new IOException("Cannot instantiate: " + className);
        } catch (IllegalAccessException e) {
            throw new IOException("Class (" + className + ") not accessible");
        }
    }

Here is the caller graph for this function:

void CH.ifa.draw.util.StorableInput.map ( Storable  storable) [inline, private]

Definition at line 137 of file StorableInput.java.

                                        {
        if (!fMap.contains(storable))
            fMap.addElement(storable);
    }

Here is the caller graph for this function:

boolean CH.ifa.draw.util.StorableInput.readBoolean ( ) throws IOException [inline]

Reads a boolean from the input stream.

Definition at line 112 of file StorableInput.java.

                                                    {
        int token = fTokenizer.nextToken();
        if (token == StreamTokenizer.TT_NUMBER)
            return ((int) fTokenizer.nval) == 1;

        String msg = "Integer expected in line: " + fTokenizer.lineno();
        throw new IOException(msg);
    }
Color CH.ifa.draw.util.StorableInput.readColor ( ) throws IOException [inline]

Reads a color from the input stream.

Definition at line 93 of file StorableInput.java.

                                                {
        return new Color(readInt(), readInt(), readInt());
    }

Here is the call graph for this function:

double CH.ifa.draw.util.StorableInput.readDouble ( ) throws IOException [inline]

Reads a double from the input stream.

Definition at line 100 of file StorableInput.java.

                                                  {
        int token = fTokenizer.nextToken();
        if (token == StreamTokenizer.TT_NUMBER)
            return fTokenizer.nval;

        String msg = "Double expected in line: " + fTokenizer.lineno();
        throw new IOException(msg);
    }
int CH.ifa.draw.util.StorableInput.readInt ( ) throws IOException [inline]

Reads an int from the input stream.

Definition at line 81 of file StorableInput.java.

                                            {
        int token = fTokenizer.nextToken();
        if (token == StreamTokenizer.TT_NUMBER)
            return (int) fTokenizer.nval;

        String msg = "Integer expected in line: " + fTokenizer.lineno();
        throw new IOException(msg);
    }

Here is the caller graph for this function:

Storable CH.ifa.draw.util.StorableInput.readStorable ( ) throws IOException [inline]

Reads and resurrects a Storable object from the input stream.

Definition at line 38 of file StorableInput.java.

                                                      {
        Storable storable;
        String s = readString();

        if (s.equals("NULL"))
            return null;

        if (s.equals("REF")) {
            int ref = readInt();
            return (Storable) retrieve(ref);
        }

        storable = (Storable) makeInstance(s);
        map(storable);
        storable.read(this);
        return storable;
    }

Here is the call graph for this function:

String CH.ifa.draw.util.StorableInput.readString ( ) throws IOException [inline]

Reads a string from the input stream.

Definition at line 68 of file StorableInput.java.

                                                  {
        int token = fTokenizer.nextToken();
        if (token == StreamTokenizer.TT_WORD || token == '"') {
            return fTokenizer.sval;
        }

        String msg = "String expected in line: " + fTokenizer.lineno();
        throw new IOException(msg);
    }

Here is the caller graph for this function:

Storable CH.ifa.draw.util.StorableInput.retrieve ( int  ref) [inline, private]

Definition at line 142 of file StorableInput.java.

                                       {
        return (Storable) fMap.elementAt(ref);
    }

Here is the caller graph for this function:

boolean CH.ifa.draw.util.StorableInput.testForNumber ( ) throws IOException [inline]

Determine if the next input token is a valid number or not.

Definition at line 59 of file StorableInput.java.

                                                      {
        int token = fTokenizer.nextToken();
       fTokenizer.pushBack();
        return (token == StreamTokenizer.TT_NUMBER);
    }

Member Data Documentation

Definition at line 24 of file StorableInput.java.

StreamTokenizer CH.ifa.draw.util.StorableInput.fTokenizer [private]

Definition at line 23 of file StorableInput.java.


The documentation for this class was generated from the following file: