Package com.tailf.maapi
Class MaapiOutputStream
Object
OutputStream
com.tailf.maapi.MaapiOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Configuration data output stream used to upload configurations.
This class is returned as result from
The application is expected to close the underlying stream socket after usage to assure that background socket is closed use
Maapi.loadConfigStream(int, java.util.EnumSet)
.
The application is expected to close the underlying stream socket after usage to assure that background socket is closed use
getLocalSocket()
to retrieve the socket stream reference.
// 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); MaapiOutputStream outstream = maapi.loadConfigStream(tid, EnumSet.of(MaapiConfigFlag.XML_FORMAT)); FileInputStream fis = new FileInputStream(new File("/tmp/config.xml")); byte[] buf = new byte[128]; int n = -1; while((n = fis.read(buf)) != -1){ outstream.write(buf,0,n); } fis.close(); outstream.getLocalSocket().close(); if(outstream.hasWriteAll()) System.out.println("All data was uploaded successful!"); maapi.finishTrans(tid); s.close();
-
Method Summary
Modifier and TypeMethodDescriptionThis method can be called after a call tohasWriteAll()
to get the error code in casehasWriteAll()
returns false, which is the case when writing to the output stream fails.This method can be called after a call tohasWriteAll()
to get the error message in casehasWriteAll()
returns false, which is the case when writing to the output stream fails.This method is intended to retrieve reference to the underlying stream socket on which the write is performed.boolean
Checks with the server if the complete configuration is uploaded.void
write
(byte[] b, int off, int len) Write a portion of an array of bytes.void
write
(int b) Write a byte from the input stream or -1 if EOFMethods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write
-
Method Details
-
getLocalSocket
This method is intended to retrieve reference to the underlying stream socket on which the write is performed. To call hasWriteAll() the underlying socket must be closed.- Returns:
- The Stream socket that this MaapiOutputStream uses.
-
write
Write a byte from the input stream or -1 if EOF- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
Write a portion of an array of bytes.- Overrides:
write
in classOutputStream
- Parameters:
b
- Buffer of byteoff
- Offset from which to start writing byteslen
- Number of characters to write- Throws:
IOException
-
hasWriteAll
public boolean hasWriteAll()Checks with the server if the complete configuration is uploaded. This is not performed by reading the stream to EOF but instead a deliberate call to the server. NOTE: Prior to calling this method it is important that the stream socket is closed. Use thegetLocalSocket()
to retrieve the stream socket or the method will hang until the socket is closed. If this call returns false, callgetErrorString()
andgetErrorCode()
to get the error message and the error code respectivly.- Returns:
- boolean true if complete configuration is downloaded
-
getErrorString
This method can be called after a call tohasWriteAll()
to get the error message in casehasWriteAll()
returns false, which is the case when writing to the output stream fails. NOTE: This function will only return useful information afterhasWriteAll()
has been called and returned false.- Returns:
- the error string in case of an error when writing to the output stream
-
getErrorCode
This method can be called after a call tohasWriteAll()
to get the error code in casehasWriteAll()
returns false, which is the case when writing to the output stream fails. NOTE: This function will only return useful information afterhasWriteAll()
has been called and returned false.- Returns:
- the error code in case of an error when writing to the output stream
-