public class MaapiOutputStream extends OutputStream
Maapi.loadConfigStream(int, java.util.EnumSet)
.
getLocalSocket()
to retrieve the socket stream reference.
String host = "localhost"; int port = Conf.PORT; 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 |
---|---|
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 boolean hasWriteAll()
getLocalSocket()
to retrieve the stream socket or the method will hang until the socket is
closed.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 void write(int b) throws IOException
write
in class OutputStream
IOException