Home Tutorial Java Corejava Nio ShortBuffer in java, Define the order of byte in short buffer.

 
 

Share on Google+Share on Google+
ShortBuffer in java, Define the order of byte in short buffer.
Posted on: August 16, 2010 at 12:00 AM
Advertisement
In this tutorial, you will see how to define the order of byte in short buffer.

ShortBuffer in java, Define the order of byte in short buffer.

In this tutorial, we will see how to define the order of byte in short buffer.

ShortBuffer API:

The java.nio.ShortBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
static ShortBuffer wrap(short [] array)  The wrap(....) method wrapping an existing short array into short buffer.
 abstract ByteOrder order() The order(..) method returns order of bytes used by
short buffer.

ByteBuffer API:

The java.nio.ByteBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
static ByteBuffer wrap([] array) The wrap(....) method wrapping an existing byte array into byte buffer.
 abstrtact ShortBuffer  asShortBuffer() The asShortBuffer() method returns short buffer based on byte buffer.

  Code

import java.nio.*;
import java.nio.ShortBuffer;

public class ByteOrder{
  public static void main(String[] args) {
    byte[] array=new byte[]{3,4,65};
    ByteBuffer byteBuff=ByteBuffer.wrap(array);
    ShortBuffer shortBuff=byteBuff.asShortBuffer();
System.out.println("Byte order of short buffer : "
  + shortBuff.order
());
    short[] arr=new short[] {3,4,65};
    ShortBuffer shortBuff1=ShortBuffer.wrap(arr);
System.out.println("Byte order of short buffer : "
    + shortBuff1.order
());  
  }
}

Output

C:\>java ByteOrder
Byte order of short buffer : BIG_ENDIAN
Byte order of short buffer : LITTLE_ENDIAN

Download this code

Advertisement

Related Tags for ShortBuffer in java, Define the order of byte in short buffer.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com