Using predefined stream classes

The DataBlade® API provides several predefined stream classes that you can access with the stream I/O interface.

To use a predefined stream class in your UDR:

  1. Open a stream with the appropriate type-specific stream-open function.
    The following table shows the predefined stream classes that the DataBlade API provides and their associated stream-open functions.
    Predefined stream class Stream-open function
    File stream mi_stream_open_fio()
    String stream mi_stream_open_str()
    Varying-length-data stream mi_stream_open_mi_lvarchar()

    The mistrmtype.h header file declares these predefined stream-open functions.

  2. Access the open stream with the appropriate stream I/O function.

    Generic stream I/O functions lists the stream I/O functions that the DataBlade API provides.

For example, the following code fragment reads 26 bytes of data from a string stream into a user-defined buffer named buf:
#define STRING_SIZE = 80

MI_STREAM *strm_desc;
mi_integer nbytes;
char buf[200];
char string_txt[STRING_SIZE] = 
   "A stream is a generic term for some object that can be\
 written to or read from."

strm_desc = mi_stream_open_str(NULL, string_txt, STRING_SIZE);
   if ( (nbytes = mi_stream_read(strm_desc, buf, 26)) != 26 )
      /* error in read */
mi_stream_close(strm_desc);
After this code fragment completes, the buf user-defined buffer contains the following character string:
A stream is a generic term

The following sections provide additional details on each of the predefined DataBlade API stream classes.