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
-
Method Summary
Modifier and TypeMethodDescriptionint
abort()
Request that the in progress data transfer be cancelled abnormally before the end of the stream has been reachedint
addCallback
(int events, Libvirt.VirStreamEventCallback cb) Register a callback to be notified when a stream becomes writable, or readable.void
close()
protected void
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
(ByteBuffer buffer) int
receive
(byte[] data) Receives data from the stream into the buffer provided.protected int
receive
(ByteBuffer buffer) int
receiveAll
(Libvirt.VirStreamSinkFunc handler) Batch receive methodint
Remove an event callback from the streamint
send
(byte[] data) Write a series of bytes to the stream.protected int
send
(ByteBuffer buffer) int
sendAll
(Libvirt.VirStreamSourceFunc handler) Batch send methodint
updateCallback
(int events) Changes the set of events to monitor for a stream.int
write
(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:
finalize
in 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:
read
in interfaceReadableByteChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
IOException
-
closeStream
- Throws:
LibvirtException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in 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:
-