Package org.libvirt
Class Stream
- java.lang.Object
-
- org.libvirt.Stream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.WritableByteChannel
public class Stream extends java.lang.Object implements java.nio.channels.ByteChannel
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
andChannels.newOutputStream
respectively.
-
-
Field Summary
Fields Modifier and Type Field Description static int
VIR_STREAM_NONBLOCK
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
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
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 methodint
removeCallback()
Remove an event callback from the streamint
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 methodint
updateCallback(int events)
Changes the set of events to monitor for a stream.int
write(java.nio.ByteBuffer buffer)
-
-
-
Field Detail
-
VIR_STREAM_NONBLOCK
public static final int VIR_STREAM_NONBLOCK
- See Also:
- Constant Field Values
-
-
Method Detail
-
isEOF
protected boolean isEOF()
-
abort
public int abort() throws LibvirtException
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
public int addCallback(int events, Libvirt.VirStreamEventCallback cb) throws LibvirtException
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:
- Libvirt Docs
-
finalize
protected void finalize() throws LibvirtException
- Overrides:
finalize
in classjava.lang.Object
- Throws:
LibvirtException
-
finish
public int finish() throws LibvirtException
Indicate that there is no further data is to be transmitted on the stream.- Returns:
- ignore (always 0)
- Throws:
LibvirtException
-
free
public int free() throws LibvirtException
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
public int receive(byte[] data) throws LibvirtException
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
protected int receive(java.nio.ByteBuffer buffer) throws LibvirtException
- Throws:
LibvirtException
-
read
public int read(java.nio.ByteBuffer buffer) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer buffer) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Throws:
java.io.IOException
-
closeStream
protected void closeStream() throws LibvirtException
- Throws:
LibvirtException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
receiveAll
public int receiveAll(Libvirt.VirStreamSinkFunc handler) throws LibvirtException
Batch receive method- Parameters:
handler
- the callback handler- Returns:
- ignore (always 0)
- Throws:
LibvirtException
- See Also:
- virStreamRecvAll
-
removeCallback
public int removeCallback() throws LibvirtException
Remove an event callback from the stream- Returns:
- ignore (always 0)
- Throws:
LibvirtException
- See Also:
- Libvirt Docs
-
send
public int send(byte[] data) throws LibvirtException
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
protected int send(java.nio.ByteBuffer buffer) throws LibvirtException
- Throws:
LibvirtException
-
sendAll
public int sendAll(Libvirt.VirStreamSourceFunc handler) throws LibvirtException
Batch send method- Parameters:
handler
- the callback handler- Returns:
- ignore (always 0)
- Throws:
LibvirtException
- See Also:
- Libvirt Documentation
-
updateCallback
public int updateCallback(int events) throws LibvirtException
Changes the set of events to monitor for a stream.- Parameters:
events
- the events to monitor- Returns:
- ignore (always 0)
- Throws:
LibvirtException
- See Also:
- Libvirt Docs
-
-