Package com.tailf.maapi
Class MaapiInputStream
Object
InputStream
com.tailf.maapi.MaapiInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
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",
"maapi",
new String[] { "admin" },
new SocketAddress(InetAddress.getLocalHost(), 0));
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 Summary
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Method Details
-
read
read a byte from the input stream or -1 if EOF- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- 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
-