[1594] in java-interest

home help back first fref pref prev next nref lref last post

RE: Java learning materials

daemon@ATHENA.MIT.EDU (Andrew Gilmartin)
Fri Sep 8 17:18:11 1995

Date: Fri, 8 Sep 95 14:35:29 EDT
To: Nelson Yu <nyu@gpu.srv.ualberta.ca>
From: ajg@cadre.com (Andrew Gilmartin)
Cc: java-interest@java.sun.com

> I find C++'s style natural(oxymoron?) and Java's reverts me back to the >
low-level days of using C for string handling.

I use code similar to the following to provide a uniform interface to
streaming objects. (I am away from my java-desk so am coding from the
hip....) It does not have the chaining interface of C++, but I do think it
is as readable.

-- Andrew Gilmartin (ajg@brainiac.com)

interface Streamable {
        public void read( InputStream in );
        public void write( OutputStream out );
}

class string extends String implements Streamable {
        public void read( InputStream in ) {
                ... // someone else writes this or you use DataInputStream
        }
        public void write( OutputStream out ) {
                ...
        }
}

class User implements Streamable {
        string name_;
        string id_;
        public void read( InputStream in ) {
                name_ = (new string())( in ); // not sure about the syntax here
                id_ = (new string())( in );
                ...
        }
        public void write( OutputStream out ) {
                name_.write( out );
                id_.write( out );
                ...
        }
}

... {
        InputStream in = new FileInputStream( "/usr/..." );
        User user = (new User())( in );
}

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post