Smart CODE
Your on-line guide to the generated code

Input and Output Streams

The C and C++ InputStream/OutputStream software is intended for thin-client interfaces and applications that need access to Internet resources. It has been modelled on the Java(TM) java.io classes, to facilitate the transition to Java, and to maintain a common API across all targets.

Note that the C and C++ implementations are sufficient for their purpose, and anything written to these interfaces should transfer easily to Java. They are not full implementations of the Java API, and are not intended for recoding Java applications in C.

Overview of Language Differences
LanguageUsageComments
Java

     import java.io.*;

     void myinput( InputStream i)
     {
	DataInputStream d = new DataInputStream( i);
	String s;
	while (( s = d.readLine()) != nil)
		System.out.println(s);
     }

     void myoutput( OutputStream o)
     {
	PrintWriter pw = new PrintWriter( o);
	pw.println("Hallo World");
     }
  • The DataInputStream readLine method is deprecated after JDK1.0.
  • C++
    
         #include "Ustreams.h"
    
         void
         myclass::myinput( InputStream * i)
         {
    	DataInputStream * d = new DataInputStream( i);
    	char * s;
    
    	while ((s = d->readLine()) != (char*)0)
    		printf("%s\n", s);
    
    	delete d;
         }
    
         void
         myclass::myoutput( OutputStream * o)
         {
    	PrintWriter * pw = new PrintWriter( o);
    	pw->println( "Hallo World");
    
    	delete pw;
         }
  • The objects are pointers
    (URL * u and u->openStream())
  • They must be deleted. They are NOT garbage collected.
  • C
    
         #include "Ustreams.h"
    
         void
         myinput( InputStream * i)
         {
    	DataInputStream * d = newDataInputStream(i);
    	char * s;
    
    	while ((s = (*d->readLine)( d)) != (char*)0)
    		printf("%s\n", s);
    
    	(*d->delete)( d);
         }
    
         void
         myoutput( OutputStream * o)
         {
    	PrintWriter * pw = newPrintWriter( o);
    
    	(*o->println)( o,"Hallo World");
    
    	(*o->delete) ( o);
         }
  • The objects are pointers
    (URL * u)
  • Constructors are functions of the form newType()
  • Public methods are function pointers in the object. The object itself MUST be the first argument of the call,eg
    (*d->delete)( d);
  • They must be deleted. They are NOT garbage collected.
  • A similar example for Input and Output streams shows how the data might be processed inthe above example.

    SYNOPSIS

    
    #include <Ustreams.h>
    
    

    InputStream(abstract)

    (StdInputStream)


    FileInputStream

    BufferedInputStream


    DataInputStream

    InputData

    OutputStream(abstract)

    (StdOutputStream)


    FileOutputStream



    TempFileOutputStream

    BufferedOutputStream

    PrintWriter

    DESCRIPTION

    BufferedInputStream

    BufferedInputStream access the input stream through large reads that fill an input buffer. The default buffer size is 5012 bytes. It decouples the amount you need to read, from the amount actually taken off disk.

    Constructor/s
    C++

    C
    BufferedInputStream *
    newBufferedInputStreamSized( InputStream * i, int bufsize)
    
    BufferedInputStream *
    newBufferedInputStream( InputStream * i)
    
    Public Methods
  • close
  • read/readChar
  • skip
  • BufferedInputStream is used internally by DataInputStream and by InputData.

    BufferedOutputStream

    BufferedOutputStream allows you to write to an output buffer that flushes to the outout file descriptor when the buffer is full,or when you explicitly call the flush() method.

    Constructor/s
    C++

    C
    BufferedOutputStream *
    newBufferedOutputStreamSized( OutputStream * o, int bufsize)
    
    BufferedOutputStream *
    newBufferedOutputStream( OutputStream * o)
    
    Public Methods
  • close
  • flush
  • write
  • DataInputStream

    DataInputStream is a stub version of the Java DataInputStream that provides the single readLine() method. Applications that need a full DataInputStream implementation may take this as a starting point.

    Constructor/s
    C++

    C
    DataInputStream *
    newDataInputStream( InputStream * i)
    
    Public Methods
  • readLine
  • FileInputStream

    FileInputStream opens a stream on a disk file for reading.

    Constructor/s
    C++

    C
    FileInputStream *
    newFileInputStream( char * filename)
    
    Public Methods
  • close
  • read/readChar
  • skip
  • FileOutputStream

    FileOutputStream opens a stream for writing to a disk file. By default it will truncate and overwrite an existing file. It can be configured to append to the file or to provide a random access (read/write) stream.

    Constructor/s
    C++

    C
    FileOutputStream *
    newFileOutputStreamFull( char * f, int a, int rw)
    
    FileOutputStream *
    newFileOutputStream( char * f)
    
    Public Methods
  • close
  • flush
  • write
  • InputData'

    InputData is the one public class for which there is no Java equivalent. InputData reads in a stream completely into a buffer of the right size, which can then be passed as a data pointer to some handler.

    Constructor/s
    C++

    C
    InputData *
    newInputData( InputStream* i)
    
    Public Methods
  • getData()
    C version: getData(InputData*)
  • getSize()
    C version: getData(InputData*)
  • InputStream

    InputStream is an abstract class which defines the interfaces for the primary input methods.
  • int available()
    return non-zero if there is anything left to read on the stream.
    C version: available(InputStream*)
  • void close()
    closes the stream
    C version: close(InputStream*)
  • int read()
    reads a character from the stream.
    C version: readChar(InputStream*)
  • int read( char * buf, int size)
    reads size bytes from the stream into buf.
    C version: read(InputStream*, char*, int)
  • void skip( int count)
    skips over count bytes in the stream
    C version: skip(InputStream*, int)
  • OutputStream

    OutputStream is an abstract class which defines the interfaces for the primary output methods.
  • void close()
    closes the stream
    C version: close( OutputStream*)
  • void flush()
    flushes the stream (after writing any buffers)
    C version: flush( OutputStream*)
  • int write ( char * buf, int len)
    writes len bytes from buf to the output stream.
    C version: write( OutputStream*, char *, int)
  • StdInputStream

    StdInputStream is an internal class that implements the abstract InputStream in terms of file-descriptor (standard) I/O

    Constructor/s
    C++

    C
    StdInputStream *
    newStdInputStream( int i)
    
    StdInputStream *
    newStdInputStream_anon()
    
    Public Methods
  • close
  • read/readChar
  • skip
  • StdOutputStream

    StdOutputStream is an internal class that implements the abstract OutputStream in terms of file-descriptor (standard) I/O

    Constructor/s
    C++

    C
    StdOutputStream *
    newStdOutputStream( int i)
    
    StdOutputStream *
    newStdOutputStream_anon()
    
    Public Methods
  • close
  • flush
  • write
  • TempFileOutputStream

    TempFileOutputStream is an internal class used to save the HTTP OutputStream locally until the user closes it. This stream cannot be sent to the server until its content-length is known.

    Constructor/s
    C++

    C
    TempFileOutputStream *
    newTempFileOutputStream()
    
    Public Methods
  • close
  • flush
  • write
  • copy
  • PrintWriter

    PrintWriter

    is a stub version of the Java PrintWriter class, and is used to string-serialize the group data before it sent to and from the server.

    Constructor/s
    C++

    C
    PrintWriter *
    newPrintWriter( OutputStream * o)
    
    Public Methods
  • println
  • print
  • (C only) printlnInt
  • SEE ALSO

    URLs