com.nativelibs4java.util
Class NIOUtils

java.lang.Object
  extended by com.nativelibs4java.util.NIOUtils

public class NIOUtils
extends Object

NIO Buffer util methods

Author:
ochafik

Constructor Summary
NIOUtils()
           
 
Method Summary
static
<B extends Buffer>
B
directBuffer(int size, ByteOrder order, Class<B> bufferClass)
          Creates a direct buffer of the specified size (in elements) and type..
static ByteBuffer directBytes(int size, ByteOrder order)
          Creates a direct byte buffer of the specified size (in elements) and a native byte order
static CharBuffer directChars(int size, ByteOrder order)
          Creates a direct char buffer of the specified size (in elements) and a native byte order
static ByteBuffer directCopy(Buffer b, ByteOrder order)
           
static CharBuffer directCopy(CharBuffer b, ByteOrder order)
           
static DoubleBuffer directCopy(DoubleBuffer b, ByteOrder order)
           
static FloatBuffer directCopy(FloatBuffer b, ByteOrder order)
           
static IntBuffer directCopy(IntBuffer b, ByteOrder order)
           
static LongBuffer directCopy(LongBuffer b, ByteOrder order)
           
static ShortBuffer directCopy(ShortBuffer b, ByteOrder order)
           
static DoubleBuffer directDoubles(int size, ByteOrder order)
          Creates a direct double buffer of the specified size (in elements) and a native byte order
static FloatBuffer directFloats(int size, ByteOrder order)
          Creates a direct float buffer of the specified size (in elements) and a native byte order
static IntBuffer directInts(int size, ByteOrder order)
          Creates a direct int buffer of the specified size (in elements) and a native byte order
static LongBuffer directLongs(int size, ByteOrder order)
          Creates a direct lpng buffer of the specified size (in elements) and a native byte order
static ShortBuffer directShorts(int size, ByteOrder order)
          Creates a direct short buffer of the specified size (in elements) and a native byte order
static
<B extends Buffer,V>
V
get(B buffer, int position)
           
static
<B extends Buffer>
Object
getArray(B buffer)
           
static Class<? extends Buffer> getBufferClass(Class<?> primitiveClass)
           
static ByteOrder getByteOrder(Buffer buffer)
           
static int getComponentSizeInBytes(Buffer b)
          Get the size in bytes of a primitive component of a buffer
static Class<?> getPrimitiveClass(Class<? extends Buffer> bufferClass)
           
static long getSizeInBytes(Buffer b)
          Get the size in bytes of a buffer
static
<B extends Buffer>
B
indirectBuffer(int size, Class<B> bufferClass)
          Creates a indirect buffer of the specified size (in elements) and type..
static
<B extends Buffer,V>
void
put(B buffer, int position, V value)
           
static void put(Buffer input, Buffer output)
          Bulk-copy all of the input buffer into the output buffer
static void put(Buffer input, ByteBuffer outputBytes)
          Bulk-copy all of the input buffer into the output buffer
static void put(ByteBuffer inputBytes, Buffer output)
          Bulk-copy all input bytes into output buffer
static
<B extends Buffer>
B
wrapArray(Object a)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NIOUtils

public NIOUtils()
Method Detail

getBufferClass

public static Class<? extends Buffer> getBufferClass(Class<?> primitiveClass)

getPrimitiveClass

public static Class<?> getPrimitiveClass(Class<? extends Buffer> bufferClass)

put

public static void put(Buffer input,
                       Buffer output)
Bulk-copy all of the input buffer into the output buffer

Parameters:
input -
output -

put

public static void put(Buffer input,
                       ByteBuffer outputBytes)
Bulk-copy all of the input buffer into the output buffer

Parameters:
input -
outputBytes -

put

public static void put(ByteBuffer inputBytes,
                       Buffer output)
Bulk-copy all input bytes into output buffer

Parameters:
inputBytes -
output -

directCopy

public static IntBuffer directCopy(IntBuffer b,
                                   ByteOrder order)

directCopy

public static LongBuffer directCopy(LongBuffer b,
                                    ByteOrder order)

directCopy

public static ShortBuffer directCopy(ShortBuffer b,
                                     ByteOrder order)

directCopy

public static CharBuffer directCopy(CharBuffer b,
                                    ByteOrder order)

directCopy

public static DoubleBuffer directCopy(DoubleBuffer b,
                                      ByteOrder order)

directCopy

public static FloatBuffer directCopy(FloatBuffer b,
                                     ByteOrder order)

directCopy

public static ByteBuffer directCopy(Buffer b,
                                    ByteOrder order)

directInts

public static IntBuffer directInts(int size,
                                   ByteOrder order)
Creates a direct int buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
view on new direct buffer

directLongs

public static LongBuffer directLongs(int size,
                                     ByteOrder order)
Creates a direct lpng buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
view on new direct buffer

directShorts

public static ShortBuffer directShorts(int size,
                                       ByteOrder order)
Creates a direct short buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
view on new direct buffer

directBytes

public static ByteBuffer directBytes(int size,
                                     ByteOrder order)
Creates a direct byte buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
new direct buffer

directFloats

public static FloatBuffer directFloats(int size,
                                       ByteOrder order)
Creates a direct float buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
view on new direct buffer

directChars

public static CharBuffer directChars(int size,
                                     ByteOrder order)
Creates a direct char buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
view on new direct buffer

directDoubles

public static DoubleBuffer directDoubles(int size,
                                         ByteOrder order)
Creates a direct double buffer of the specified size (in elements) and a native byte order

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
Returns:
view on new direct buffer

directBuffer

public static <B extends Buffer> B directBuffer(int size,
                                                ByteOrder order,
                                                Class<B> bufferClass)
Creates a direct buffer of the specified size (in elements) and type..

Parameters:
size - size of the buffer in elements
order - byte order of the direct buffer
bufferClass - type of the buffer. Must be one of IntBuffer.class, LongBuffer.class, ShortBuffer.class, ByteBuffer.class, DoubleBuffer.class, FloatBuffer.class
Returns:
view on new direct buffer

indirectBuffer

public static <B extends Buffer> B indirectBuffer(int size,
                                                  Class<B> bufferClass)
Creates a indirect buffer of the specified size (in elements) and type..

Parameters:
size - size of the buffer in elements
bufferClass - type of the buffer. Must be one of IntBuffer.class, LongBuffer.class, ShortBuffer.class, ByteBuffer.class, DoubleBuffer.class, FloatBuffer.class
Returns:
view on new direct buffer

getSizeInBytes

public static long getSizeInBytes(Buffer b)
Get the size in bytes of a buffer


getComponentSizeInBytes

public static int getComponentSizeInBytes(Buffer b)
Get the size in bytes of a primitive component of a buffer


put

public static <B extends Buffer,V> void put(B buffer,
                                            int position,
                                            V value)

get

public static <B extends Buffer,V> V get(B buffer,
                                         int position)

getArray

public static <B extends Buffer> Object getArray(B buffer)

wrapArray

public static <B extends Buffer> B wrapArray(Object a)

getByteOrder

public static ByteOrder getByteOrder(Buffer buffer)


Copyright © 2009-2013. All Rights Reserved.