Package org.libvirt

Class 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 and Channels.newOutputStream respectively.

    • 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 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)  
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • 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
      • read

        public int read​(java.nio.ByteBuffer buffer)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer buffer)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • 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
      • 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