public static CodedInputStream newInstance(ByteBuffer buf){
  if (buf.hasArray()) {
    return newInstance(buf.array(),buf.arrayOffset() + buf.position(),buf.remaining());
  }
 else {
    ByteBuffer temp=buf.duplicate();
    byte[] buffer=new byte[temp.remaining()];
    temp.get(buffer);
    return newInstance(buffer);
  }
}

public static CodedInputStream newInstance ( ByteBuffer buf ) { if ( buf . hasArray ( ) ) { return newInstance ( buf . array ( ) , buf . arrayOffset ( ) + buf . position ( ) , buf . remaining ( ) ) ; } else { ByteBuffer temp = buf . duplicate ( ) ; byte [ ] buffer = new byte [ temp . remaining ( ) ] ; temp . get ( buffer ) ; return newInstance ( buffer ) ; } }
create a new codedinputstream wrapping the given bytebuffer . the data starting from the bytebuffer ' s current position to its limit will be read . the returned codedinputstream may or may not share the underlying data in the bytebuffer , therefore the bytebuffer cannot be changed while the codedinputstream is in use . note that the bytebuffer ' s position won ' t be changed by this function . concurrent calls with the same bytebuffer object are safe if no other thread is trying to alter the bytebuffer ' s status .
