Class ChannelUtil


  • public final class ChannelUtil
    extends java.lang.Object
    The channel util class
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long channelCopy​(java.io.InputStream src, java.io.OutputStream dest)
      This method copies data from the src channel and writes it to the dest channel until EOF on src.
      long channelCopy​(java.io.InputStream src, java.io.OutputStream dest, java.security.MessageDigest messageDigest)
      This method copies data from the src channel and writes it to the dest channel until EOF on src.
      long channelCopy​(java.nio.channels.ReadableByteChannel src, java.nio.channels.WritableByteChannel dest)
      This method copies data from the src channel and writes it to the dest channel until EOF on src.
      static ChannelUtil getInstance()
      Get the instance
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static ChannelUtil getInstance()
        Get the instance
        Returns:
        the instance
      • channelCopy

        public long channelCopy​(java.io.InputStream src,
                                java.io.OutputStream dest)
                         throws java.io.IOException
        This method copies data from the src channel and writes it to the dest channel until EOF on src. This implementation makes use of compact() on the temp buffer to pack down the data if the buffer wasn't fully drained. This may result in data copying, but minimizes system calls. It also requires a cleanup loop to make sure all the data gets sent.
        Parameters:
        src - the source channel
        dest - the destination channel
        Returns:
        the copied bytes
        Throws:
        java.io.IOException - in case of error
      • channelCopy

        public long channelCopy​(java.nio.channels.ReadableByteChannel src,
                                java.nio.channels.WritableByteChannel dest)
                         throws java.io.IOException
        This method copies data from the src channel and writes it to the dest channel until EOF on src. This implementation makes use of compact() on the temp buffer to pack down the data if the buffer wasn't fully drained. This may result in data copying, but minimizes system calls. It also requires a cleanup loop to make sure all the data gets sent.
        Parameters:
        src - the source channel
        dest - the destination channel
        Returns:
        the copied bytes
        Throws:
        java.io.IOException - in case of error
      • channelCopy

        public long channelCopy​(java.io.InputStream src,
                                java.io.OutputStream dest,
                                java.security.MessageDigest messageDigest)
                         throws java.io.IOException
        This method copies data from the src channel and writes it to the dest channel until EOF on src. This implementation makes use of compact() on the temp buffer to pack down the data if the buffer wasn't fully drained. This may result in data copying, but minimizes system calls. It also requires a cleanup loop to make sure all the data gets sent.
        Parameters:
        src - the source channel
        dest - the destination channel
        messageDigest - the message digest
        Returns:
        the copied bytes
        Throws:
        java.io.IOException - in case of error