com.kuka.comm.codec.bytebuffer
Class ByteBufferUtils

java.lang.Object
  extended by com.kuka.comm.codec.bytebuffer.ByteBufferUtils

public final class ByteBufferUtils
extends Object

This is a helper class that provides various utility functions for dealing with the ByteBuffer class.

Especially, it contains replacements for the standard ByteBuffer.slice() method, which in its original version ignores the byte order. The slice methods in this helper class will pass the byte order to the newly created view.


Method Summary
static ByteBuffer slice(ByteBuffer bb)
          Provides a view as a subsequence of a ByteBuffer.
static ByteBuffer slice(ByteBuffer bb, int begin)
          Provides a view as a subsequence of a ByteBuffer.
static ByteBuffer slice(ByteBuffer bb, int begin, int end)
          Provides a view as a subsequence of a ByteBuffer.
static ByteBuffer sliceLen(ByteBuffer bb, int begin, int length)
          Provides a view as a subsequence of a ByteBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

slice

public static ByteBuffer slice(ByteBuffer bb,
                               int begin,
                               int end)
Provides a view as a subsequence of a ByteBuffer. It behaves comparable to the standard ByteBuffer.slice() method, but the beginning and end of the slice can be be explicitly provided. The returned ByteBuffer will respect the same byte order as the ByteBuffer from which it has been created.

Parameters:
bb - the byte buffer of which a slice should be created
begin - the position of the first bye of the slice (0 is the first byte)
end - the position of the byte after the slice (the first byte after the end of the slice). The maximum allowed value is the length of bb.
Returns:
the new slice view of the byte buffer

sliceLen

public static ByteBuffer sliceLen(ByteBuffer bb,
                                  int begin,
                                  int length)
Provides a view as a subsequence of a ByteBuffer. It behaves comparable to the standard ByteBuffer.slice() method, but the beginning and the length of the slice can be be explicitly provided. The returned ByteBuffer will respect the same byte order as the ByteBuffer from which it has been created.

Parameters:
bb - the byte buffer of which a slice should be created
begin - the position of the first bye of the slice (0 is the first byte)
length - the length of the slice in bytes
Returns:
the new slice view of the byte buffer

slice

public static ByteBuffer slice(ByteBuffer bb,
                               int begin)
Provides a view as a subsequence of a ByteBuffer. It behaves comparable to the standard ByteBuffer.slice() method, but the beginning of the slice can be be explicitly provided. The slice will extend until the end of the original byte buffer. The returned ByteBuffer will respect the same byte order as the ByteBuffer from which it has been created.

Parameters:
bb - the byte buffer of which a slice should be created
begin - the position of the first bye of the slice (0 is the first byte)
Returns:
the new slice view of the byte buffer

slice

public static ByteBuffer slice(ByteBuffer bb)
Provides a view as a subsequence of a ByteBuffer. It behaves comparable to the standard ByteBuffer.slice() method, except that the returned ByteBuffer will respect the same byte order as the ByteBuffer from which it has been created.

Parameters:
bb - the byte buffer of which a slice should be created
Returns:
the new slice view of the byte buffer


Copyright © 2019. All rights reserved.