Package org.libvirt
Class Stream
java.lang.Object
org.libvirt.Stream
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteChannel,Channel,ReadableByteChannel,WritableByteChannel
The Stream class is used to transfer data between a libvirt daemon
and a client.
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.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintabort()Request that the in progress data transfer be cancelled abnormally before the end of the stream has been reachedintaddCallback(int events, Libvirt.VirStreamEventCallback cb) Register a callback to be notified when a stream becomes writable, or readable.voidclose()protected voidprotected voidfinalize()intfinish()Indicate that there is no further data is to be transmitted on the stream.intfree()Decrement the reference count on a stream, releasing the stream object if the reference count has hit zero.protected booleanisEOF()booleanisOpen()intread(ByteBuffer buffer) intreceive(byte[] data) Receives data from the stream into the buffer provided.protected intreceive(ByteBuffer buffer) intreceiveAll(Libvirt.VirStreamSinkFunc handler) Batch receive methodintRemove an event callback from the streamintsend(byte[] data) Write a series of bytes to the stream.protected intsend(ByteBuffer buffer) intsendAll(Libvirt.VirStreamSourceFunc handler) Batch send methodintupdateCallback(int events) Changes the set of events to monitor for a stream.intwrite(ByteBuffer buffer)
-
Field Details
-
VIR_STREAM_NONBLOCK
public static final int VIR_STREAM_NONBLOCK- See Also:
-
-
Method Details
-
isEOF
protected boolean isEOF() -
abort
Request that the in progress data transfer be cancelled abnormally before the end of the stream has been reached- Returns:
- ignore (always 0)
- Throws:
LibvirtException
-
addCallback
Register a callback to be notified when a stream becomes writable, or readable.- Parameters:
events- the events to monitorcb- the callback method- Returns:
- ignore (always 0)
- Throws:
LibvirtException- See Also:
-
finalize
- Overrides:
finalizein classObject- Throws:
LibvirtException
-
finish
Indicate that there is no further data is to be transmitted on the stream.- Returns:
- ignore (always 0)
- Throws:
LibvirtException
-
free
Decrement the reference count on a stream, releasing the stream object if the reference count has hit zero.- Returns:
- ignore (always 0)
- Throws:
LibvirtException
-
receive
Receives data from the stream into the buffer provided.- Parameters:
data- buffer to put the data into- Returns:
- the number of bytes read, -1 on error, -2 if the buffer is empty
- Throws:
LibvirtException
-
receive
- Throws:
LibvirtException
-
read
- Specified by:
readin interfaceReadableByteChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
closeStream
- Throws:
LibvirtException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isOpen
public boolean isOpen() -
receiveAll
Batch receive method- Parameters:
handler- the callback handler- Returns:
- ignore (always 0)
- Throws:
LibvirtException- See Also:
-
removeCallback
Remove an event callback from the stream- Returns:
- ignore (always 0)
- Throws:
LibvirtException- See Also:
-
send
Write a series of bytes to the stream.- Parameters:
data- the data to write- Returns:
- the number of bytes written, -1 on error, -2 if the buffer is full
- Throws:
LibvirtException
-
send
- Throws:
LibvirtException
-
sendAll
Batch send method- Parameters:
handler- the callback handler- Returns:
- ignore (always 0)
- Throws:
LibvirtException- See Also:
-
updateCallback
Changes the set of events to monitor for a stream.- Parameters:
events- the events to monitor- Returns:
- ignore (always 0)
- Throws:
LibvirtException- See Also:
-