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.ByteChannelThe 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.newInputStreamandChannels.newOutputStreamrespectively.
-
-
Field Summary
Fields Modifier and Type Field Description static intVIR_STREAM_NONBLOCK
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intabort()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 voidcloseStream()protected 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(java.nio.ByteBuffer buffer)intreceive(byte[] data)Receives data from the stream into the buffer provided.protected intreceive(java.nio.ByteBuffer buffer)intreceiveAll(Libvirt.VirStreamSinkFunc handler)Batch receive methodintremoveCallback()Remove an event callback from the streamintsend(byte[] data)Write a series of bytes to the stream.protected intsend(java.nio.ByteBuffer buffer)intsendAll(Libvirt.VirStreamSourceFunc handler)Batch send methodintupdateCallback(int events)Changes the set of events to monitor for a stream.intwrite(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 LibvirtExceptionRequest 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 LibvirtExceptionRegister 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:
finalizein classjava.lang.Object- Throws:
LibvirtException
-
finish
public int finish() throws LibvirtExceptionIndicate that there is no further data is to be transmitted on the stream.- Returns:
- ignore (always 0)
- Throws:
LibvirtException
-
free
public int free() throws LibvirtExceptionDecrement 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 LibvirtExceptionReceives 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:
readin interfacejava.nio.channels.ReadableByteChannel- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer buffer) throws java.io.IOException- Specified by:
writein 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin 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 LibvirtExceptionRemove an event callback from the stream- Returns:
- ignore (always 0)
- Throws:
LibvirtException- See Also:
- Libvirt Docs
-
send
public int send(byte[] data) throws LibvirtExceptionWrite 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 LibvirtExceptionChanges 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
-
-