public class Stream
extends java.lang.Object
implements java.nio.channels.ByteChannel
It implements the ByteChannel interface.
Basic usage:
ByteBuffer buf = ByteBuffer.allocate(1024);
Stream str = conn.streamNew(0);
... // open the stream e.g. calling Domain.screenshot
while (str.read(buf) != -1) {
buf.flip();
... // do something with the data
buf.compact();
}
If you want to use this class as an InputStream or OutputStream,
convert it using the Channels.newInputStream
and Channels.newOutputStream
respectively.
Modifier and Type | Field and Description |
---|---|
static int |
VIR_STREAM_NONBLOCK |
Modifier and Type | Method and Description |
---|---|
int |
abort()
Request that the in progress data transfer be cancelled abnormally before
the end of the stream has been reached
|
int |
addCallback(int events,
Libvirt.VirStreamEventCallback cb)
Register a callback to be notified when a stream becomes writable, or
readable.
|
void |
close() |
protected void |
closeStream() |
protected void |
finalize() |
int |
finish()
Indicate that there is no further data is to be transmitted on the
stream.
|
int |
free()
Decrement the reference count on a stream, releasing the stream object if
the reference count has hit zero.
|
protected boolean |
isEOF() |
boolean |
isOpen() |
int |
read(java.nio.ByteBuffer buffer) |
int |
receive(byte[] data)
Receives data from the stream into the buffer provided.
|
protected int |
receive(java.nio.ByteBuffer buffer) |
int |
receiveAll(Libvirt.VirStreamSinkFunc handler)
Batch receive method
|
int |
removeCallback()
Remove an event callback from the stream
|
int |
send(byte[] data)
Write a series of bytes to the stream.
|
protected int |
send(java.nio.ByteBuffer buffer) |
int |
sendAll(Libvirt.VirStreamSourceFunc handler)
Batch send method
|
int |
updateCallback(int events)
Changes the set of events to monitor for a stream.
|
int |
write(java.nio.ByteBuffer buffer) |
public static final int VIR_STREAM_NONBLOCK
protected boolean isEOF()
public int abort() throws LibvirtException
LibvirtException
public int addCallback(int events, Libvirt.VirStreamEventCallback cb) throws LibvirtException
events
- the events to monitorcb
- the callback methodLibvirtException
protected void finalize() throws LibvirtException
finalize
in class java.lang.Object
LibvirtException
public int finish() throws LibvirtException
LibvirtException
public int free() throws LibvirtException
LibvirtException
public int receive(byte[] data) throws LibvirtException
data
- buffer to put the data intoLibvirtException
protected int receive(java.nio.ByteBuffer buffer) throws LibvirtException
LibvirtException
public int read(java.nio.ByteBuffer buffer) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
java.io.IOException
public int write(java.nio.ByteBuffer buffer) throws java.io.IOException
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
protected void closeStream() throws LibvirtException
LibvirtException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public int receiveAll(Libvirt.VirStreamSinkFunc handler) throws LibvirtException
handler
- the callback handlerLibvirtException
public int removeCallback() throws LibvirtException
LibvirtException
public int send(byte[] data) throws LibvirtException
data
- the data to writeLibvirtException
protected int send(java.nio.ByteBuffer buffer) throws LibvirtException
LibvirtException
public int sendAll(Libvirt.VirStreamSourceFunc handler) throws LibvirtException
handler
- the callback handlerLibvirtException
public int updateCallback(int events) throws LibvirtException
events
- the events to monitorLibvirtException