public class MaapiOutputStream extends OutputStream
Maapi.loadConfigStream(int, java.util.EnumSet)
.
MaapiOutputStream.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();
Modifier and Type | Method and Description |
---|---|
ErrorCode |
getErrorCode()
This method can be called after a call to
MaapiOutputStream.hasWriteAll() to get the error code in case
MaapiOutputStream.hasWriteAll() returns false, which is the case when writing to
the output stream fails. |
String |
getErrorString()
This method can be called after a call to
MaapiOutputStream.hasWriteAll() to get the error message in case
MaapiOutputStream.hasWriteAll() returns false, which is the case when writing to
the output stream fails. |
Socket |
getLocalSocket()
This method is intended to retrieve reference to the underlying
stream socket on which the write is performed.
|
boolean |
hasWriteAll()
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 EOF
|
close, flush, write
public Socket getLocalSocket()
public void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
b
- Buffer of byteoff
- Offset from which to start writing byteslen
- Number of characters to writeIOException
public boolean hasWriteAll()
getLocalSocket()
to retrieve the stream socket or the method will hang until the socket is
closed.
If this call returns false, call MaapiOutputStream.getErrorString()
and
MaapiOutputStream.getErrorCode()
to get the error message and the
error code respectivly.public String getErrorString()
MaapiOutputStream.hasWriteAll()
to get the error message in case
MaapiOutputStream.hasWriteAll()
returns false, which is the case when writing to
the output stream fails.
NOTE: This function will only return useful information after
MaapiOutputStream.hasWriteAll()
has been called and returned false.public ErrorCode getErrorCode()
MaapiOutputStream.hasWriteAll()
to get the error code in case
MaapiOutputStream.hasWriteAll()
returns false, which is the case when writing to
the output stream fails.
NOTE: This function will only return useful information after
MaapiOutputStream.hasWriteAll()
has been called and returned false.