Class ByteBufferUtils


  • public class ByteBufferUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.nio.ByteBuffer EMPTY  
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBufferUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int copy​(java.nio.ByteBuffer from, java.nio.ByteBuffer to)
      Copies data from the provided `from` buffer to the provided `to` buffer.
      static java.nio.ByteBuffer slice​(java.nio.ByteBuffer orig, int begin, int length)  
      • Methods inherited from class java.lang.Object

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

      • EMPTY

        public static final java.nio.ByteBuffer EMPTY
    • Constructor Detail

      • ByteBufferUtils

        public ByteBufferUtils()
    • Method Detail

      • slice

        public static java.nio.ByteBuffer slice​(java.nio.ByteBuffer orig,
                                                int begin,
                                                int length)
      • copy

        public static int copy​(java.nio.ByteBuffer from,
                               java.nio.ByteBuffer to)
        Copies data from the provided `from` buffer to the provided `to` buffer. The data is copied starting from the Buffer.position() of the buffer to its Buffer.limit(). As much data as possible will be copied without going beyond the Buffer.limit() of the `to` buffer. So if the `to` buffer is too small to hold the data in the `from` buffer, only the portion that will fit is copied. The position of the `from` and `to` buffers will be advanced by the amount of data copied.
        Parameters:
        from - the buffer to copy from
        to - the buffer to copy into
        Returns:
        the number of bytes copied