Class MaapiInputStream

Object
InputStream
com.tailf.maapi.MaapiInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class MaapiInputStream extends InputStream
Represents configuration data input stream used to download configurations.

This class is returned as result from Maapi.saveConfig(int, java.util.EnumSet, String, Object...) and Maapi.rollbackConfig(int, String, String...).

The application is expected to close the MaapiInputStream after usage, to assure that background socket is closed. The instance return will open a new socket to the end server.

 // String host = "localhost";
 // int port = Conf.PORT for ConfD or Conf.NCS_PORT for NCS
 Socket s = new Socket(host, port);
 Maapi maapi = new Maapi(s);
 maapi.startUserSession("admin",
     InetAddress.getByName("localhost"),
     "maapi",
     new String[] { "admin" },
     MaapiUserSessionFlag.PROTO_TCP);
 int tid = maapi.startTrans(Conf.DB_RUNNING, Conf.MODE_READ_WRITE);

 // Save the entire configuration
 MaapiInputStream in = maapi.saveConfig(tid,
                         EnumSet.of(MaapiConfigFlag.MAAPI_CONFIG_C));

 while ( (bytesRead = is.read (buf, 0, buf.length)) != -1 )
   // do something with the buf..

  is.close();
 maapi.finishTrans(tid);
 s.close();
 
  • Method Details

    • read

      public int read() throws IOException
      read a byte from the input stream or -1 if EOF
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • hasReadAll

      public boolean hasReadAll()
      Checks with the server is the complete configuration is downloaded. This is not performed by reading the stream to EOF but instead a deliberate call to the server.
      Returns:
      boolean true if complete configuration is downloaded