Message3296

Author colinhevans
Recipients colinhevans
Date 2008-06-20.19:33:45
SpamBayes Score 0.15934242
Marked as misclassified No
Message-id <1213990428.23.0.566781119454.issue1061@psf.upfronthosting.co.za>
In-reply-to
Content
here's the code that is required:

    private static class ReaderWrapper extends FileWrapper {
        Reader istream;

        public ReaderWrapper(Reader r) {
            istream = r;
        }

        public String read(int n) throws IOException {
            if (n == 0)
                // nothing to do
                return "";
            if (n < 0) {
                // read until we hit EOF
                char buf[] = new char[1024];
                StringBuffer sbuf = new StringBuffer();
                for (int read=0; read >= 0; read=istream.read(buf))
                    sbuf.append(buf, 0, read);
                return sbuf.toString();
            }
            // read the next chunk available, but make sure it's at least
            // one byte so as not to trip the `empty string' return value
            // test done by the caller
            //int avail = istream.available();
            //n = (n > avail) ? n : avail;
            char buf[] = new char[n];
            int read = istream.read(buf);
            if (read < 0)
                // EOF encountered
                return "";
            return new String(buf);
        }

        public int read() throws IOException {
            return istream.read();
        }

        public int available() throws IOException {
            return 0;
        }

        public void close() throws IOException {
            istream.close();
        }

        public Object __tojava__(Class cls) throws IOException {
            if (InputStream.class.isAssignableFrom(cls))
                return istream;
            return null;
        }
    }
History
Date User Action Args
2008-06-20 19:33:48colinhevanssetspambayes_score: 0.159342 -> 0.15934242
messageid: <1213990428.23.0.566781119454.issue1061@psf.upfronthosting.co.za>
2008-06-20 19:33:48colinhevanssetspambayes_score: 0.159342 -> 0.159342
recipients: + colinhevans
2008-06-20 19:33:47colinhevanslinkissue1061 messages
2008-06-20 19:33:46colinhevanscreate