hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [18/19] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Thu, 27 Apr 2017 22:53:25 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/f9332e6e/apidocs/src-html/org/apache/hadoop/hbase/util/ByteBufferUtils.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/util/ByteBufferUtils.html b/apidocs/src-html/org/apache/hadoop/hbase/util/ByteBufferUtils.html
index 5b83354..a4090da 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/util/ByteBufferUtils.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/util/ByteBufferUtils.html
@@ -709,373 +709,370 @@
 <span class="sourceLineNo">701</span>  }<a name="line.701"></a>
 <span class="sourceLineNo">702</span><a name="line.702"></a>
 <span class="sourceLineNo">703</span>  static int compareToUnsafe(Object obj1, long o1, int l1, Object obj2, long o2, int l2) {<a name="line.703"></a>
-<span class="sourceLineNo">704</span>    final int minLength = Math.min(l1, l2);<a name="line.704"></a>
-<span class="sourceLineNo">705</span>    final int minWords = minLength / Bytes.SIZEOF_LONG;<a name="line.705"></a>
-<span class="sourceLineNo">706</span><a name="line.706"></a>
-<span class="sourceLineNo">707</span>    /*<a name="line.707"></a>
-<span class="sourceLineNo">708</span>     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a time is no slower than<a name="line.708"></a>
-<span class="sourceLineNo">709</span>     * comparing 4 bytes at a time even on 32-bit. On the other hand, it is substantially faster on<a name="line.709"></a>
-<span class="sourceLineNo">710</span>     * 64-bit.<a name="line.710"></a>
-<span class="sourceLineNo">711</span>     */<a name="line.711"></a>
-<span class="sourceLineNo">712</span>    int j = minWords &lt;&lt; 3; // Same as minWords * SIZEOF_LONG<a name="line.712"></a>
-<span class="sourceLineNo">713</span>    for (int i = 0; i &lt; j; i += Bytes.SIZEOF_LONG) {<a name="line.713"></a>
-<span class="sourceLineNo">714</span>      long lw = UnsafeAccess.theUnsafe.getLong(obj1, o1 + i);<a name="line.714"></a>
-<span class="sourceLineNo">715</span>      long rw = UnsafeAccess.theUnsafe.getLong(obj2, o2 + i);<a name="line.715"></a>
-<span class="sourceLineNo">716</span>      long diff = lw ^ rw;<a name="line.716"></a>
-<span class="sourceLineNo">717</span>      if (diff != 0) {<a name="line.717"></a>
-<span class="sourceLineNo">718</span>        return lessThanUnsignedLong(lw, rw) ? -1 : 1;<a name="line.718"></a>
-<span class="sourceLineNo">719</span>      }<a name="line.719"></a>
-<span class="sourceLineNo">720</span>    }<a name="line.720"></a>
-<span class="sourceLineNo">721</span>    int offset = j;<a name="line.721"></a>
-<span class="sourceLineNo">722</span><a name="line.722"></a>
-<span class="sourceLineNo">723</span>    if (minLength - offset &gt;= Bytes.SIZEOF_INT) {<a name="line.723"></a>
-<span class="sourceLineNo">724</span>      int il = UnsafeAccess.theUnsafe.getInt(obj1, o1 + offset);<a name="line.724"></a>
-<span class="sourceLineNo">725</span>      int ir = UnsafeAccess.theUnsafe.getInt(obj2, o2 + offset);<a name="line.725"></a>
-<span class="sourceLineNo">726</span>      if (il != ir) {<a name="line.726"></a>
-<span class="sourceLineNo">727</span>        return lessThanUnsignedInt(il, ir) ? -1 : 1;<a name="line.727"></a>
-<span class="sourceLineNo">728</span>      }<a name="line.728"></a>
-<span class="sourceLineNo">729</span>      offset += Bytes.SIZEOF_INT;<a name="line.729"></a>
-<span class="sourceLineNo">730</span>    }<a name="line.730"></a>
-<span class="sourceLineNo">731</span>    if (minLength - offset &gt;= Bytes.SIZEOF_SHORT) {<a name="line.731"></a>
-<span class="sourceLineNo">732</span>      short sl = UnsafeAccess.theUnsafe.getShort(obj1, o1 + offset);<a name="line.732"></a>
-<span class="sourceLineNo">733</span>      short sr = UnsafeAccess.theUnsafe.getShort(obj2, o2 + offset);<a name="line.733"></a>
-<span class="sourceLineNo">734</span>      if (sl != sr) {<a name="line.734"></a>
-<span class="sourceLineNo">735</span>        return lessThanUnsignedShort(sl, sr) ? -1 : 1;<a name="line.735"></a>
-<span class="sourceLineNo">736</span>      }<a name="line.736"></a>
-<span class="sourceLineNo">737</span>      offset += Bytes.SIZEOF_SHORT;<a name="line.737"></a>
-<span class="sourceLineNo">738</span>    }<a name="line.738"></a>
-<span class="sourceLineNo">739</span>    if (minLength - offset == 1) {<a name="line.739"></a>
-<span class="sourceLineNo">740</span>      int a = (UnsafeAccess.theUnsafe.getByte(obj1, o1 + offset) &amp; 0xff);<a name="line.740"></a>
-<span class="sourceLineNo">741</span>      int b = (UnsafeAccess.theUnsafe.getByte(obj2, o2 + offset) &amp; 0xff);<a name="line.741"></a>
-<span class="sourceLineNo">742</span>      if (a != b) {<a name="line.742"></a>
-<span class="sourceLineNo">743</span>        return a - b;<a name="line.743"></a>
-<span class="sourceLineNo">744</span>      }<a name="line.744"></a>
-<span class="sourceLineNo">745</span>    }<a name="line.745"></a>
-<span class="sourceLineNo">746</span>    return l1 - l2;<a name="line.746"></a>
-<span class="sourceLineNo">747</span>  }<a name="line.747"></a>
-<span class="sourceLineNo">748</span><a name="line.748"></a>
-<span class="sourceLineNo">749</span>  /*<a name="line.749"></a>
-<span class="sourceLineNo">750</span>   * Both values are passed as is read by Unsafe. When platform is Little Endian, have to convert<a name="line.750"></a>
-<span class="sourceLineNo">751</span>   * to corresponding Big Endian value and then do compare. We do all writes in Big Endian format.<a name="line.751"></a>
-<span class="sourceLineNo">752</span>   */<a name="line.752"></a>
-<span class="sourceLineNo">753</span>  private static boolean lessThanUnsignedLong(long x1, long x2) {<a name="line.753"></a>
-<span class="sourceLineNo">754</span>    if (UnsafeAccess.littleEndian) {<a name="line.754"></a>
-<span class="sourceLineNo">755</span>      x1 = Long.reverseBytes(x1);<a name="line.755"></a>
-<span class="sourceLineNo">756</span>      x2 = Long.reverseBytes(x2);<a name="line.756"></a>
-<span class="sourceLineNo">757</span>    }<a name="line.757"></a>
-<span class="sourceLineNo">758</span>    return (x1 + Long.MIN_VALUE) &lt; (x2 + Long.MIN_VALUE);<a name="line.758"></a>
-<span class="sourceLineNo">759</span>  }<a name="line.759"></a>
-<span class="sourceLineNo">760</span><a name="line.760"></a>
-<span class="sourceLineNo">761</span>  /*<a name="line.761"></a>
-<span class="sourceLineNo">762</span>   * Both values are passed as is read by Unsafe. When platform is Little Endian, have to convert<a name="line.762"></a>
-<span class="sourceLineNo">763</span>   * to corresponding Big Endian value and then do compare. We do all writes in Big Endian format.<a name="line.763"></a>
-<span class="sourceLineNo">764</span>   */<a name="line.764"></a>
-<span class="sourceLineNo">765</span>  private static boolean lessThanUnsignedInt(int x1, int x2) {<a name="line.765"></a>
-<span class="sourceLineNo">766</span>    if (UnsafeAccess.littleEndian) {<a name="line.766"></a>
-<span class="sourceLineNo">767</span>      x1 = Integer.reverseBytes(x1);<a name="line.767"></a>
-<span class="sourceLineNo">768</span>      x2 = Integer.reverseBytes(x2);<a name="line.768"></a>
-<span class="sourceLineNo">769</span>    }<a name="line.769"></a>
-<span class="sourceLineNo">770</span>    return (x1 &amp; 0xffffffffL) &lt; (x2 &amp; 0xffffffffL);<a name="line.770"></a>
-<span class="sourceLineNo">771</span>  }<a name="line.771"></a>
-<span class="sourceLineNo">772</span><a name="line.772"></a>
-<span class="sourceLineNo">773</span>  /*<a name="line.773"></a>
-<span class="sourceLineNo">774</span>   * Both values are passed as is read by Unsafe. When platform is Little Endian, have to convert<a name="line.774"></a>
-<span class="sourceLineNo">775</span>   * to corresponding Big Endian value and then do compare. We do all writes in Big Endian format.<a name="line.775"></a>
-<span class="sourceLineNo">776</span>   */<a name="line.776"></a>
-<span class="sourceLineNo">777</span>  private static boolean lessThanUnsignedShort(short x1, short x2) {<a name="line.777"></a>
-<span class="sourceLineNo">778</span>    if (UnsafeAccess.littleEndian) {<a name="line.778"></a>
-<span class="sourceLineNo">779</span>      x1 = Short.reverseBytes(x1);<a name="line.779"></a>
-<span class="sourceLineNo">780</span>      x2 = Short.reverseBytes(x2);<a name="line.780"></a>
-<span class="sourceLineNo">781</span>    }<a name="line.781"></a>
-<span class="sourceLineNo">782</span>    return (x1 &amp; 0xffff) &lt; (x2 &amp; 0xffff);<a name="line.782"></a>
-<span class="sourceLineNo">783</span>  }<a name="line.783"></a>
-<span class="sourceLineNo">784</span><a name="line.784"></a>
-<span class="sourceLineNo">785</span>  /**<a name="line.785"></a>
-<span class="sourceLineNo">786</span>   * Reads a short value at the given buffer's offset.<a name="line.786"></a>
-<span class="sourceLineNo">787</span>   * @param buffer<a name="line.787"></a>
-<span class="sourceLineNo">788</span>   * @param offset<a name="line.788"></a>
-<span class="sourceLineNo">789</span>   * @return short value at offset<a name="line.789"></a>
-<span class="sourceLineNo">790</span>   */<a name="line.790"></a>
-<span class="sourceLineNo">791</span>  public static short toShort(ByteBuffer buffer, int offset) {<a name="line.791"></a>
-<span class="sourceLineNo">792</span>    if (UNSAFE_UNALIGNED) {<a name="line.792"></a>
-<span class="sourceLineNo">793</span>      return UnsafeAccess.toShort(buffer, offset);<a name="line.793"></a>
-<span class="sourceLineNo">794</span>    } else {<a name="line.794"></a>
-<span class="sourceLineNo">795</span>      return buffer.getShort(offset);<a name="line.795"></a>
-<span class="sourceLineNo">796</span>    }<a name="line.796"></a>
-<span class="sourceLineNo">797</span>  }<a name="line.797"></a>
-<span class="sourceLineNo">798</span><a name="line.798"></a>
-<span class="sourceLineNo">799</span>  /**<a name="line.799"></a>
-<span class="sourceLineNo">800</span>   * Reads an int value at the given buffer's current position. Also advances the buffer's position<a name="line.800"></a>
-<span class="sourceLineNo">801</span>   */<a name="line.801"></a>
-<span class="sourceLineNo">802</span>  public static int toInt(ByteBuffer buffer) {<a name="line.802"></a>
-<span class="sourceLineNo">803</span>    if (UNSAFE_UNALIGNED) {<a name="line.803"></a>
-<span class="sourceLineNo">804</span>      int i = UnsafeAccess.toInt(buffer, buffer.position());<a name="line.804"></a>
-<span class="sourceLineNo">805</span>      buffer.position(buffer.position() + Bytes.SIZEOF_INT);<a name="line.805"></a>
-<span class="sourceLineNo">806</span>      return i;<a name="line.806"></a>
-<span class="sourceLineNo">807</span>    } else {<a name="line.807"></a>
-<span class="sourceLineNo">808</span>      return buffer.getInt();<a name="line.808"></a>
-<span class="sourceLineNo">809</span>    }<a name="line.809"></a>
-<span class="sourceLineNo">810</span>  }<a name="line.810"></a>
-<span class="sourceLineNo">811</span><a name="line.811"></a>
-<span class="sourceLineNo">812</span>  /**<a name="line.812"></a>
-<span class="sourceLineNo">813</span>   * Reads an int value at the given buffer's offset.<a name="line.813"></a>
-<span class="sourceLineNo">814</span>   * @param buffer<a name="line.814"></a>
-<span class="sourceLineNo">815</span>   * @param offset<a name="line.815"></a>
-<span class="sourceLineNo">816</span>   * @return int value at offset<a name="line.816"></a>
-<span class="sourceLineNo">817</span>   */<a name="line.817"></a>
-<span class="sourceLineNo">818</span>  public static int toInt(ByteBuffer buffer, int offset) {<a name="line.818"></a>
-<span class="sourceLineNo">819</span>    if (UNSAFE_UNALIGNED) {<a name="line.819"></a>
-<span class="sourceLineNo">820</span>      return UnsafeAccess.toInt(buffer, offset);<a name="line.820"></a>
-<span class="sourceLineNo">821</span>    } else {<a name="line.821"></a>
-<span class="sourceLineNo">822</span>      return buffer.getInt(offset);<a name="line.822"></a>
-<span class="sourceLineNo">823</span>    }<a name="line.823"></a>
-<span class="sourceLineNo">824</span>  }<a name="line.824"></a>
-<span class="sourceLineNo">825</span><a name="line.825"></a>
-<span class="sourceLineNo">826</span>  /**<a name="line.826"></a>
-<span class="sourceLineNo">827</span>   * Converts a ByteBuffer to an int value<a name="line.827"></a>
-<span class="sourceLineNo">828</span>   *<a name="line.828"></a>
-<span class="sourceLineNo">829</span>   * @param buf The ByteBuffer<a name="line.829"></a>
-<span class="sourceLineNo">830</span>   * @param offset Offset to int value<a name="line.830"></a>
-<span class="sourceLineNo">831</span>   * @param length Number of bytes used to store the int value.<a name="line.831"></a>
-<span class="sourceLineNo">832</span>   * @return the int value<a name="line.832"></a>
-<span class="sourceLineNo">833</span>   * @throws IllegalArgumentException<a name="line.833"></a>
-<span class="sourceLineNo">834</span>   *           if there's not enough bytes left in the buffer after the given offset<a name="line.834"></a>
-<span class="sourceLineNo">835</span>   */<a name="line.835"></a>
-<span class="sourceLineNo">836</span>  public static int readAsInt(ByteBuffer buf, int offset, final int length) {<a name="line.836"></a>
-<span class="sourceLineNo">837</span>    if (offset + length &gt; buf.limit()) {<a name="line.837"></a>
-<span class="sourceLineNo">838</span>      throw new IllegalArgumentException("offset (" + offset + ") + length (" + length<a name="line.838"></a>
-<span class="sourceLineNo">839</span>          + ") exceed the" + " limit of the buffer: " + buf.limit());<a name="line.839"></a>
-<span class="sourceLineNo">840</span>    }<a name="line.840"></a>
-<span class="sourceLineNo">841</span>    int n = 0;<a name="line.841"></a>
-<span class="sourceLineNo">842</span>    for(int i = offset; i &lt; (offset + length); i++) {<a name="line.842"></a>
-<span class="sourceLineNo">843</span>      n &lt;&lt;= 8;<a name="line.843"></a>
-<span class="sourceLineNo">844</span>      n ^= toByte(buf, i) &amp; 0xFF;<a name="line.844"></a>
-<span class="sourceLineNo">845</span>    }<a name="line.845"></a>
-<span class="sourceLineNo">846</span>    return n;<a name="line.846"></a>
-<span class="sourceLineNo">847</span>  }<a name="line.847"></a>
-<span class="sourceLineNo">848</span><a name="line.848"></a>
-<span class="sourceLineNo">849</span>  /**<a name="line.849"></a>
-<span class="sourceLineNo">850</span>   * Reads a long value at the given buffer's offset.<a name="line.850"></a>
-<span class="sourceLineNo">851</span>   * @param buffer<a name="line.851"></a>
-<span class="sourceLineNo">852</span>   * @param offset<a name="line.852"></a>
-<span class="sourceLineNo">853</span>   * @return long value at offset<a name="line.853"></a>
-<span class="sourceLineNo">854</span>   */<a name="line.854"></a>
-<span class="sourceLineNo">855</span>  public static long toLong(ByteBuffer buffer, int offset) {<a name="line.855"></a>
-<span class="sourceLineNo">856</span>    if (UNSAFE_UNALIGNED) {<a name="line.856"></a>
-<span class="sourceLineNo">857</span>      return UnsafeAccess.toLong(buffer, offset);<a name="line.857"></a>
-<span class="sourceLineNo">858</span>    } else {<a name="line.858"></a>
-<span class="sourceLineNo">859</span>      return buffer.getLong(offset);<a name="line.859"></a>
-<span class="sourceLineNo">860</span>    }<a name="line.860"></a>
-<span class="sourceLineNo">861</span>  }<a name="line.861"></a>
-<span class="sourceLineNo">862</span><a name="line.862"></a>
-<span class="sourceLineNo">863</span>  /**<a name="line.863"></a>
-<span class="sourceLineNo">864</span>   * Put an int value out to the given ByteBuffer's current position in big-endian format.<a name="line.864"></a>
-<span class="sourceLineNo">865</span>   * This also advances the position in buffer by int size.<a name="line.865"></a>
-<span class="sourceLineNo">866</span>   * @param buffer the ByteBuffer to write to<a name="line.866"></a>
-<span class="sourceLineNo">867</span>   * @param val int to write out<a name="line.867"></a>
-<span class="sourceLineNo">868</span>   */<a name="line.868"></a>
-<span class="sourceLineNo">869</span>  public static void putInt(ByteBuffer buffer, int val) {<a name="line.869"></a>
-<span class="sourceLineNo">870</span>    if (UNSAFE_UNALIGNED) {<a name="line.870"></a>
-<span class="sourceLineNo">871</span>      int newPos = UnsafeAccess.putInt(buffer, buffer.position(), val);<a name="line.871"></a>
-<span class="sourceLineNo">872</span>      buffer.position(newPos);<a name="line.872"></a>
-<span class="sourceLineNo">873</span>    } else {<a name="line.873"></a>
-<span class="sourceLineNo">874</span>      buffer.putInt(val);<a name="line.874"></a>
-<span class="sourceLineNo">875</span>    }<a name="line.875"></a>
-<span class="sourceLineNo">876</span>  }<a name="line.876"></a>
-<span class="sourceLineNo">877</span><a name="line.877"></a>
-<span class="sourceLineNo">878</span>  public static int putInt(ByteBuffer buffer, int index, int val) {<a name="line.878"></a>
-<span class="sourceLineNo">879</span>    if (UNSAFE_UNALIGNED) {<a name="line.879"></a>
-<span class="sourceLineNo">880</span>      return UnsafeAccess.putInt(buffer, index, val);<a name="line.880"></a>
-<span class="sourceLineNo">881</span>    }<a name="line.881"></a>
-<span class="sourceLineNo">882</span>    buffer.putInt(index, val);<a name="line.882"></a>
-<span class="sourceLineNo">883</span>    return index + Bytes.SIZEOF_INT;<a name="line.883"></a>
-<span class="sourceLineNo">884</span>  }<a name="line.884"></a>
-<span class="sourceLineNo">885</span><a name="line.885"></a>
-<span class="sourceLineNo">886</span>  /**<a name="line.886"></a>
-<span class="sourceLineNo">887</span>   * Reads a double value at the given buffer's offset.<a name="line.887"></a>
-<span class="sourceLineNo">888</span>   * @param buffer<a name="line.888"></a>
-<span class="sourceLineNo">889</span>   * @param offset offset where double is<a name="line.889"></a>
-<span class="sourceLineNo">890</span>   * @return double value at offset<a name="line.890"></a>
-<span class="sourceLineNo">891</span>   */<a name="line.891"></a>
-<span class="sourceLineNo">892</span>  public static double toDouble(ByteBuffer buffer, int offset) {<a name="line.892"></a>
-<span class="sourceLineNo">893</span>    return Double.longBitsToDouble(toLong(buffer, offset));<a name="line.893"></a>
-<span class="sourceLineNo">894</span>  }<a name="line.894"></a>
-<span class="sourceLineNo">895</span><a name="line.895"></a>
-<span class="sourceLineNo">896</span>  /**<a name="line.896"></a>
-<span class="sourceLineNo">897</span>   * Reads a BigDecimal value at the given buffer's offset.<a name="line.897"></a>
-<span class="sourceLineNo">898</span>   * @param buffer<a name="line.898"></a>
-<span class="sourceLineNo">899</span>   * @param offset<a name="line.899"></a>
-<span class="sourceLineNo">900</span>   * @return BigDecimal value at offset<a name="line.900"></a>
-<span class="sourceLineNo">901</span>   */<a name="line.901"></a>
-<span class="sourceLineNo">902</span>  public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) {<a name="line.902"></a>
-<span class="sourceLineNo">903</span>    if (buffer == null || length &lt; Bytes.SIZEOF_INT + 1 ||<a name="line.903"></a>
-<span class="sourceLineNo">904</span>      (offset + length &gt; buffer.limit())) {<a name="line.904"></a>
-<span class="sourceLineNo">905</span>      return null;<a name="line.905"></a>
-<span class="sourceLineNo">906</span>    }<a name="line.906"></a>
-<span class="sourceLineNo">907</span><a name="line.907"></a>
-<span class="sourceLineNo">908</span>    int scale = toInt(buffer, offset);<a name="line.908"></a>
-<span class="sourceLineNo">909</span>    byte[] tcBytes = new byte[length - Bytes.SIZEOF_INT];<a name="line.909"></a>
-<span class="sourceLineNo">910</span>    copyFromBufferToArray(tcBytes, buffer, offset + Bytes.SIZEOF_INT, 0, length - Bytes.SIZEOF_INT);<a name="line.910"></a>
-<span class="sourceLineNo">911</span>    return new BigDecimal(new BigInteger(tcBytes), scale);<a name="line.911"></a>
-<span class="sourceLineNo">912</span>  }<a name="line.912"></a>
-<span class="sourceLineNo">913</span><a name="line.913"></a>
-<span class="sourceLineNo">914</span>  /**<a name="line.914"></a>
-<span class="sourceLineNo">915</span>   * Put a short value out to the given ByteBuffer's current position in big-endian format.<a name="line.915"></a>
-<span class="sourceLineNo">916</span>   * This also advances the position in buffer by short size.<a name="line.916"></a>
-<span class="sourceLineNo">917</span>   * @param buffer the ByteBuffer to write to<a name="line.917"></a>
-<span class="sourceLineNo">918</span>   * @param val short to write out<a name="line.918"></a>
-<span class="sourceLineNo">919</span>   */<a name="line.919"></a>
-<span class="sourceLineNo">920</span>  public static void putShort(ByteBuffer buffer, short val) {<a name="line.920"></a>
-<span class="sourceLineNo">921</span>    if (UNSAFE_UNALIGNED) {<a name="line.921"></a>
-<span class="sourceLineNo">922</span>      int newPos = UnsafeAccess.putShort(buffer, buffer.position(), val);<a name="line.922"></a>
-<span class="sourceLineNo">923</span>      buffer.position(newPos);<a name="line.923"></a>
-<span class="sourceLineNo">924</span>    } else {<a name="line.924"></a>
-<span class="sourceLineNo">925</span>      buffer.putShort(val);<a name="line.925"></a>
-<span class="sourceLineNo">926</span>    }<a name="line.926"></a>
-<span class="sourceLineNo">927</span>  }<a name="line.927"></a>
-<span class="sourceLineNo">928</span><a name="line.928"></a>
-<span class="sourceLineNo">929</span>  public static int putShort(ByteBuffer buffer, int index, short val) {<a name="line.929"></a>
-<span class="sourceLineNo">930</span>    if (UNSAFE_UNALIGNED) {<a name="line.930"></a>
-<span class="sourceLineNo">931</span>      return UnsafeAccess.putShort(buffer, index, val);<a name="line.931"></a>
-<span class="sourceLineNo">932</span>    }<a name="line.932"></a>
-<span class="sourceLineNo">933</span>    buffer.putShort(index, val);<a name="line.933"></a>
-<span class="sourceLineNo">934</span>    return index + Bytes.SIZEOF_SHORT;<a name="line.934"></a>
-<span class="sourceLineNo">935</span>  }<a name="line.935"></a>
-<span class="sourceLineNo">936</span><a name="line.936"></a>
-<span class="sourceLineNo">937</span>  public static int putAsShort(ByteBuffer buf, int index, int val) {<a name="line.937"></a>
-<span class="sourceLineNo">938</span>    buf.put(index + 1, (byte) val);<a name="line.938"></a>
-<span class="sourceLineNo">939</span>    val &gt;&gt;= 8;<a name="line.939"></a>
-<span class="sourceLineNo">940</span>    buf.put(index, (byte) val);<a name="line.940"></a>
-<span class="sourceLineNo">941</span>    return index + Bytes.SIZEOF_SHORT;<a name="line.941"></a>
-<span class="sourceLineNo">942</span>  }<a name="line.942"></a>
-<span class="sourceLineNo">943</span><a name="line.943"></a>
-<span class="sourceLineNo">944</span>  /**<a name="line.944"></a>
-<span class="sourceLineNo">945</span>   * Put a long value out to the given ByteBuffer's current position in big-endian format.<a name="line.945"></a>
-<span class="sourceLineNo">946</span>   * This also advances the position in buffer by long size.<a name="line.946"></a>
-<span class="sourceLineNo">947</span>   * @param buffer the ByteBuffer to write to<a name="line.947"></a>
-<span class="sourceLineNo">948</span>   * @param val long to write out<a name="line.948"></a>
-<span class="sourceLineNo">949</span>   */<a name="line.949"></a>
-<span class="sourceLineNo">950</span>  public static void putLong(ByteBuffer buffer, long val) {<a name="line.950"></a>
-<span class="sourceLineNo">951</span>    if (UNSAFE_UNALIGNED) {<a name="line.951"></a>
-<span class="sourceLineNo">952</span>      int newPos = UnsafeAccess.putLong(buffer, buffer.position(), val);<a name="line.952"></a>
-<span class="sourceLineNo">953</span>      buffer.position(newPos);<a name="line.953"></a>
-<span class="sourceLineNo">954</span>    } else {<a name="line.954"></a>
-<span class="sourceLineNo">955</span>      buffer.putLong(val);<a name="line.955"></a>
-<span class="sourceLineNo">956</span>    }<a name="line.956"></a>
-<span class="sourceLineNo">957</span>  }<a name="line.957"></a>
-<span class="sourceLineNo">958</span><a name="line.958"></a>
-<span class="sourceLineNo">959</span>  public static int putLong(ByteBuffer buffer, int index, long val) {<a name="line.959"></a>
-<span class="sourceLineNo">960</span>    if (UNSAFE_UNALIGNED) {<a name="line.960"></a>
-<span class="sourceLineNo">961</span>      return UnsafeAccess.putLong(buffer, index, val);<a name="line.961"></a>
-<span class="sourceLineNo">962</span>    }<a name="line.962"></a>
-<span class="sourceLineNo">963</span>    buffer.putLong(index, val);<a name="line.963"></a>
-<span class="sourceLineNo">964</span>    return index + Bytes.SIZEOF_LONG;<a name="line.964"></a>
-<span class="sourceLineNo">965</span>  }<a name="line.965"></a>
-<span class="sourceLineNo">966</span><a name="line.966"></a>
-<span class="sourceLineNo">967</span>  /**<a name="line.967"></a>
-<span class="sourceLineNo">968</span>   * Copies the bytes from given array's offset to length part into the given buffer. Puts the bytes<a name="line.968"></a>
-<span class="sourceLineNo">969</span>   * to buffer's current position. This also advances the position in the 'out' buffer by 'length'<a name="line.969"></a>
-<span class="sourceLineNo">970</span>   * @param out<a name="line.970"></a>
-<span class="sourceLineNo">971</span>   * @param in<a name="line.971"></a>
-<span class="sourceLineNo">972</span>   * @param inOffset<a name="line.972"></a>
-<span class="sourceLineNo">973</span>   * @param length<a name="line.973"></a>
-<span class="sourceLineNo">974</span>   */<a name="line.974"></a>
-<span class="sourceLineNo">975</span>  public static void copyFromArrayToBuffer(ByteBuffer out, byte[] in, int inOffset, int length) {<a name="line.975"></a>
-<span class="sourceLineNo">976</span>    if (out.hasArray()) {<a name="line.976"></a>
-<span class="sourceLineNo">977</span>      System.arraycopy(in, inOffset, out.array(), out.arrayOffset() + out.position(), length);<a name="line.977"></a>
-<span class="sourceLineNo">978</span>      // Move the position in out by length<a name="line.978"></a>
-<span class="sourceLineNo">979</span>      out.position(out.position() + length);<a name="line.979"></a>
-<span class="sourceLineNo">980</span>    } else if (UNSAFE_AVAIL) {<a name="line.980"></a>
-<span class="sourceLineNo">981</span>      UnsafeAccess.copy(in, inOffset, out, out.position(), length);<a name="line.981"></a>
-<span class="sourceLineNo">982</span>      // Move the position in out by length<a name="line.982"></a>
-<span class="sourceLineNo">983</span>      out.position(out.position() + length);<a name="line.983"></a>
-<span class="sourceLineNo">984</span>    } else {<a name="line.984"></a>
-<span class="sourceLineNo">985</span>      out.put(in, inOffset, length);<a name="line.985"></a>
-<span class="sourceLineNo">986</span>    }<a name="line.986"></a>
-<span class="sourceLineNo">987</span>  }<a name="line.987"></a>
-<span class="sourceLineNo">988</span><a name="line.988"></a>
-<span class="sourceLineNo">989</span>  /**<a name="line.989"></a>
-<span class="sourceLineNo">990</span>   * Copies bytes from given array's offset to length part into the given buffer. Puts the bytes<a name="line.990"></a>
-<span class="sourceLineNo">991</span>   * to buffer's given position. This doesn't affact the position of buffer.<a name="line.991"></a>
-<span class="sourceLineNo">992</span>   * @param out<a name="line.992"></a>
-<span class="sourceLineNo">993</span>   * @param in<a name="line.993"></a>
-<span class="sourceLineNo">994</span>   * @param inOffset<a name="line.994"></a>
-<span class="sourceLineNo">995</span>   * @param length<a name="line.995"></a>
-<span class="sourceLineNo">996</span>   */<a name="line.996"></a>
-<span class="sourceLineNo">997</span>  public static void copyFromArrayToBuffer(ByteBuffer out, int outOffset, byte[] in, int inOffset,<a name="line.997"></a>
-<span class="sourceLineNo">998</span>      int length) {<a name="line.998"></a>
-<span class="sourceLineNo">999</span>    if (out.hasArray()) {<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>      System.arraycopy(in, inOffset, out.array(), out.arrayOffset() + outOffset, length);<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>    } else if (UNSAFE_AVAIL) {<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>      UnsafeAccess.copy(in, inOffset, out, outOffset, length);<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>    } else {<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>      ByteBuffer outDup = out.duplicate();<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>      outDup.position(outOffset);<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>      outDup.put(in, inOffset, length);<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>    }<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>  }<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span><a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>  /**<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>   * Copies specified number of bytes from given offset of 'in' ByteBuffer to<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>   * the array. This doesn't affact the position of buffer.<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>   * @param out<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>   * @param in<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>   * @param sourceOffset<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span>   * @param destinationOffset<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>   * @param length<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>   */<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>  public static void copyFromBufferToArray(byte[] out, ByteBuffer in, int sourceOffset,<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>      int destinationOffset, int length) {<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>    if (in.hasArray()) {<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>      System.arraycopy(in.array(), sourceOffset + in.arrayOffset(), out, destinationOffset, length);<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>    } else if (UNSAFE_AVAIL) {<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>      UnsafeAccess.copy(in, sourceOffset, out, destinationOffset, length);<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>    } else {<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>      ByteBuffer inDup = in.duplicate();<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>      inDup.position(sourceOffset);<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>      inDup.get(out, destinationOffset, length);<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>    }<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>  }<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span><a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>  /**<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>   * Similar to  {@link Arrays#copyOfRange(byte[], int, int)}<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>   * @param original the buffer from which the copy has to happen<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>   * @param from the starting index<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>   * @param to the ending index<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>   * @return a byte[] created out of the copy<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>   */<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>  public static byte[] copyOfRange(ByteBuffer original, int from, int to) {<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>    int newLength = to - from;<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>    if (newLength &lt; 0) throw new IllegalArgumentException(from + " &gt; " + to);<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>    byte[] copy = new byte[newLength];<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>    ByteBufferUtils.copyFromBufferToArray(copy, original, from, 0, newLength);<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>    return copy;<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>  }<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span><a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>  // For testing purpose<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>  public static String toStringBinary(final ByteBuffer b, int off, int len) {<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>    StringBuilder result = new StringBuilder();<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>    // Just in case we are passed a 'len' that is &gt; buffer length...<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>    if (off &gt;= b.capacity())<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>      return result.toString();<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>    if (off + len &gt; b.capacity())<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>      len = b.capacity() - off;<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>    for (int i = off; i &lt; off + len; ++i) {<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>      int ch = b.get(i) &amp; 0xFF;<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>      if ((ch &gt;= '0' &amp;&amp; ch &lt;= '9') || (ch &gt;= 'A' &amp;&amp; ch &lt;= 'Z') || (ch &gt;= 'a' &amp;&amp; ch &lt;= 'z')<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>          || " `~!@#$%^&amp;*()-_=+[]{}|;:'\",.&lt;&gt;/?".indexOf(ch) &gt;= 0) {<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>        result.append((char) ch);<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>      } else {<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>        result.append(String.format("\\x%02X", ch));<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>      }<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>    }<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>    return result.toString();<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>  }<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span><a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>  public static String toStringBinary(final ByteBuffer b) {<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>    return toStringBinary(b, 0, b.capacity());<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>  }<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>}<a name="line.1070"></a>
+<span class="sourceLineNo">704</span>    final int stride = 8;<a name="line.704"></a>
+<span class="sourceLineNo">705</span>    final int minLength = Math.min(l1, l2);<a name="line.705"></a>
+<span class="sourceLineNo">706</span>    int strideLimit = minLength &amp; ~(stride - 1);<a name="line.706"></a>
+<span class="sourceLineNo">707</span>    int i;<a name="line.707"></a>
+<span class="sourceLineNo">708</span><a name="line.708"></a>
+<span class="sourceLineNo">709</span>    /*<a name="line.709"></a>
+<span class="sourceLineNo">710</span>     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a time is no slower than<a name="line.710"></a>
+<span class="sourceLineNo">711</span>     * comparing 4 bytes at a time even on 32-bit. On the other hand, it is substantially faster on<a name="line.711"></a>
+<span class="sourceLineNo">712</span>     * 64-bit.<a name="line.712"></a>
+<span class="sourceLineNo">713</span>     */<a name="line.713"></a>
+<span class="sourceLineNo">714</span>    for (i = 0; i &lt; strideLimit; i += stride) {<a name="line.714"></a>
+<span class="sourceLineNo">715</span>      long lw = UnsafeAccess.theUnsafe.getLong(obj1, o1 + (long) i);<a name="line.715"></a>
+<span class="sourceLineNo">716</span>      long rw = UnsafeAccess.theUnsafe.getLong(obj2, o2 + (long) i);<a name="line.716"></a>
+<span class="sourceLineNo">717</span>      if (lw != rw) {<a name="line.717"></a>
+<span class="sourceLineNo">718</span>        if (!UnsafeAccess.littleEndian) {<a name="line.718"></a>
+<span class="sourceLineNo">719</span>          return ((lw + Long.MIN_VALUE) &lt; (rw + Long.MIN_VALUE)) ? -1 : 1;<a name="line.719"></a>
+<span class="sourceLineNo">720</span>        }<a name="line.720"></a>
+<span class="sourceLineNo">721</span><a name="line.721"></a>
+<span class="sourceLineNo">722</span>        /*<a name="line.722"></a>
+<span class="sourceLineNo">723</span>         * We want to compare only the first index where left[index] != right[index]. This<a name="line.723"></a>
+<span class="sourceLineNo">724</span>         * corresponds to the least significant nonzero byte in lw ^ rw, since lw and rw are<a name="line.724"></a>
+<span class="sourceLineNo">725</span>         * little-endian. Long.numberOfTrailingZeros(diff) tells us the least significant<a name="line.725"></a>
+<span class="sourceLineNo">726</span>         * nonzero bit, and zeroing out the first three bits of L.nTZ gives us the shift to get<a name="line.726"></a>
+<span class="sourceLineNo">727</span>         * that least significant nonzero byte. This comparison logic is based on UnsignedBytes<a name="line.727"></a>
+<span class="sourceLineNo">728</span>         * from guava v21<a name="line.728"></a>
+<span class="sourceLineNo">729</span>         */<a name="line.729"></a>
+<span class="sourceLineNo">730</span>        int n = Long.numberOfTrailingZeros(lw ^ rw) &amp; ~0x7;<a name="line.730"></a>
+<span class="sourceLineNo">731</span>        return ((int) ((lw &gt;&gt;&gt; n) &amp; 0xFF)) - ((int) ((rw &gt;&gt;&gt; n) &amp; 0xFF));<a name="line.731"></a>
+<span class="sourceLineNo">732</span>      }<a name="line.732"></a>
+<span class="sourceLineNo">733</span>    }<a name="line.733"></a>
+<span class="sourceLineNo">734</span><a name="line.734"></a>
+<span class="sourceLineNo">735</span>    // The epilogue to cover the last (minLength % stride) elements.<a name="line.735"></a>
+<span class="sourceLineNo">736</span>    for (; i &lt; minLength; i++) {<a name="line.736"></a>
+<span class="sourceLineNo">737</span>      int il = (UnsafeAccess.theUnsafe.getByte(obj1, o1 + i) &amp; 0xFF);<a name="line.737"></a>
+<span class="sourceLineNo">738</span>      int ir = (UnsafeAccess.theUnsafe.getByte(obj2, o2 + i) &amp; 0xFF);<a name="line.738"></a>
+<span class="sourceLineNo">739</span>      if (il != ir) {<a name="line.739"></a>
+<span class="sourceLineNo">740</span>        return il - ir;<a name="line.740"></a>
+<span class="sourceLineNo">741</span>      }<a name="line.741"></a>
+<span class="sourceLineNo">742</span>    }<a name="line.742"></a>
+<span class="sourceLineNo">743</span>    return l1 - l2;<a name="line.743"></a>
+<span class="sourceLineNo">744</span>  }<a name="line.744"></a>
+<span class="sourceLineNo">745</span><a name="line.745"></a>
+<span class="sourceLineNo">746</span>  /*<a name="line.746"></a>
+<span class="sourceLineNo">747</span>   * Both values are passed as is read by Unsafe. When platform is Little Endian, have to convert<a name="line.747"></a>
+<span class="sourceLineNo">748</span>   * to corresponding Big Endian value and then do compare. We do all writes in Big Endian format.<a name="line.748"></a>
+<span class="sourceLineNo">749</span>   */<a name="line.749"></a>
+<span class="sourceLineNo">750</span>  private static boolean lessThanUnsignedLong(long x1, long x2) {<a name="line.750"></a>
+<span class="sourceLineNo">751</span>    if (UnsafeAccess.littleEndian) {<a name="line.751"></a>
+<span class="sourceLineNo">752</span>      x1 = Long.reverseBytes(x1);<a name="line.752"></a>
+<span class="sourceLineNo">753</span>      x2 = Long.reverseBytes(x2);<a name="line.753"></a>
+<span class="sourceLineNo">754</span>    }<a name="line.754"></a>
+<span class="sourceLineNo">755</span>    return (x1 + Long.MIN_VALUE) &lt; (x2 + Long.MIN_VALUE);<a name="line.755"></a>
+<span class="sourceLineNo">756</span>  }<a name="line.756"></a>
+<span class="sourceLineNo">757</span><a name="line.757"></a>
+<span class="sourceLineNo">758</span>  /*<a name="line.758"></a>
+<span class="sourceLineNo">759</span>   * Both values are passed as is read by Unsafe. When platform is Little Endian, have to convert<a name="line.759"></a>
+<span class="sourceLineNo">760</span>   * to corresponding Big Endian value and then do compare. We do all writes in Big Endian format.<a name="line.760"></a>
+<span class="sourceLineNo">761</span>   */<a name="line.761"></a>
+<span class="sourceLineNo">762</span>  private static boolean lessThanUnsignedInt(int x1, int x2) {<a name="line.762"></a>
+<span class="sourceLineNo">763</span>    if (UnsafeAccess.littleEndian) {<a name="line.763"></a>
+<span class="sourceLineNo">764</span>      x1 = Integer.reverseBytes(x1);<a name="line.764"></a>
+<span class="sourceLineNo">765</span>      x2 = Integer.reverseBytes(x2);<a name="line.765"></a>
+<span class="sourceLineNo">766</span>    }<a name="line.766"></a>
+<span class="sourceLineNo">767</span>    return (x1 &amp; 0xffffffffL) &lt; (x2 &amp; 0xffffffffL);<a name="line.767"></a>
+<span class="sourceLineNo">768</span>  }<a name="line.768"></a>
+<span class="sourceLineNo">769</span><a name="line.769"></a>
+<span class="sourceLineNo">770</span>  /*<a name="line.770"></a>
+<span class="sourceLineNo">771</span>   * Both values are passed as is read by Unsafe. When platform is Little Endian, have to convert<a name="line.771"></a>
+<span class="sourceLineNo">772</span>   * to corresponding Big Endian value and then do compare. We do all writes in Big Endian format.<a name="line.772"></a>
+<span class="sourceLineNo">773</span>   */<a name="line.773"></a>
+<span class="sourceLineNo">774</span>  private static boolean lessThanUnsignedShort(short x1, short x2) {<a name="line.774"></a>
+<span class="sourceLineNo">775</span>    if (UnsafeAccess.littleEndian) {<a name="line.775"></a>
+<span class="sourceLineNo">776</span>      x1 = Short.reverseBytes(x1);<a name="line.776"></a>
+<span class="sourceLineNo">777</span>      x2 = Short.reverseBytes(x2);<a name="line.777"></a>
+<span class="sourceLineNo">778</span>    }<a name="line.778"></a>
+<span class="sourceLineNo">779</span>    return (x1 &amp; 0xffff) &lt; (x2 &amp; 0xffff);<a name="line.779"></a>
+<span class="sourceLineNo">780</span>  }<a name="line.780"></a>
+<span class="sourceLineNo">781</span><a name="line.781"></a>
+<span class="sourceLineNo">782</span>  /**<a name="line.782"></a>
+<span class="sourceLineNo">783</span>   * Reads a short value at the given buffer's offset.<a name="line.783"></a>
+<span class="sourceLineNo">784</span>   * @param buffer<a name="line.784"></a>
+<span class="sourceLineNo">785</span>   * @param offset<a name="line.785"></a>
+<span class="sourceLineNo">786</span>   * @return short value at offset<a name="line.786"></a>
+<span class="sourceLineNo">787</span>   */<a name="line.787"></a>
+<span class="sourceLineNo">788</span>  public static short toShort(ByteBuffer buffer, int offset) {<a name="line.788"></a>
+<span class="sourceLineNo">789</span>    if (UNSAFE_UNALIGNED) {<a name="line.789"></a>
+<span class="sourceLineNo">790</span>      return UnsafeAccess.toShort(buffer, offset);<a name="line.790"></a>
+<span class="sourceLineNo">791</span>    } else {<a name="line.791"></a>
+<span class="sourceLineNo">792</span>      return buffer.getShort(offset);<a name="line.792"></a>
+<span class="sourceLineNo">793</span>    }<a name="line.793"></a>
+<span class="sourceLineNo">794</span>  }<a name="line.794"></a>
+<span class="sourceLineNo">795</span><a name="line.795"></a>
+<span class="sourceLineNo">796</span>  /**<a name="line.796"></a>
+<span class="sourceLineNo">797</span>   * Reads an int value at the given buffer's current position. Also advances the buffer's position<a name="line.797"></a>
+<span class="sourceLineNo">798</span>   */<a name="line.798"></a>
+<span class="sourceLineNo">799</span>  public static int toInt(ByteBuffer buffer) {<a name="line.799"></a>
+<span class="sourceLineNo">800</span>    if (UNSAFE_UNALIGNED) {<a name="line.800"></a>
+<span class="sourceLineNo">801</span>      int i = UnsafeAccess.toInt(buffer, buffer.position());<a name="line.801"></a>
+<span class="sourceLineNo">802</span>      buffer.position(buffer.position() + Bytes.SIZEOF_INT);<a name="line.802"></a>
+<span class="sourceLineNo">803</span>      return i;<a name="line.803"></a>
+<span class="sourceLineNo">804</span>    } else {<a name="line.804"></a>
+<span class="sourceLineNo">805</span>      return buffer.getInt();<a name="line.805"></a>
+<span class="sourceLineNo">806</span>    }<a name="line.806"></a>
+<span class="sourceLineNo">807</span>  }<a name="line.807"></a>
+<span class="sourceLineNo">808</span><a name="line.808"></a>
+<span class="sourceLineNo">809</span>  /**<a name="line.809"></a>
+<span class="sourceLineNo">810</span>   * Reads an int value at the given buffer's offset.<a name="line.810"></a>
+<span class="sourceLineNo">811</span>   * @param buffer<a name="line.811"></a>
+<span class="sourceLineNo">812</span>   * @param offset<a name="line.812"></a>
+<span class="sourceLineNo">813</span>   * @return int value at offset<a name="line.813"></a>
+<span class="sourceLineNo">814</span>   */<a name="line.814"></a>
+<span class="sourceLineNo">815</span>  public static int toInt(ByteBuffer buffer, int offset) {<a name="line.815"></a>
+<span class="sourceLineNo">816</span>    if (UNSAFE_UNALIGNED) {<a name="line.816"></a>
+<span class="sourceLineNo">817</span>      return UnsafeAccess.toInt(buffer, offset);<a name="line.817"></a>
+<span class="sourceLineNo">818</span>    } else {<a name="line.818"></a>
+<span class="sourceLineNo">819</span>      return buffer.getInt(offset);<a name="line.819"></a>
+<span class="sourceLineNo">820</span>    }<a name="line.820"></a>
+<span class="sourceLineNo">821</span>  }<a name="line.821"></a>
+<span class="sourceLineNo">822</span><a name="line.822"></a>
+<span class="sourceLineNo">823</span>  /**<a name="line.823"></a>
+<span class="sourceLineNo">824</span>   * Converts a ByteBuffer to an int value<a name="line.824"></a>
+<span class="sourceLineNo">825</span>   *<a name="line.825"></a>
+<span class="sourceLineNo">826</span>   * @param buf The ByteBuffer<a name="line.826"></a>
+<span class="sourceLineNo">827</span>   * @param offset Offset to int value<a name="line.827"></a>
+<span class="sourceLineNo">828</span>   * @param length Number of bytes used to store the int value.<a name="line.828"></a>
+<span class="sourceLineNo">829</span>   * @return the int value<a name="line.829"></a>
+<span class="sourceLineNo">830</span>   * @throws IllegalArgumentException<a name="line.830"></a>
+<span class="sourceLineNo">831</span>   *           if there's not enough bytes left in the buffer after the given offset<a name="line.831"></a>
+<span class="sourceLineNo">832</span>   */<a name="line.832"></a>
+<span class="sourceLineNo">833</span>  public static int readAsInt(ByteBuffer buf, int offset, final int length) {<a name="line.833"></a>
+<span class="sourceLineNo">834</span>    if (offset + length &gt; buf.limit()) {<a name="line.834"></a>
+<span class="sourceLineNo">835</span>      throw new IllegalArgumentException("offset (" + offset + ") + length (" + length<a name="line.835"></a>
+<span class="sourceLineNo">836</span>          + ") exceed the" + " limit of the buffer: " + buf.limit());<a name="line.836"></a>
+<span class="sourceLineNo">837</span>    }<a name="line.837"></a>
+<span class="sourceLineNo">838</span>    int n = 0;<a name="line.838"></a>
+<span class="sourceLineNo">839</span>    for(int i = offset; i &lt; (offset + length); i++) {<a name="line.839"></a>
+<span class="sourceLineNo">840</span>      n &lt;&lt;= 8;<a name="line.840"></a>
+<span class="sourceLineNo">841</span>      n ^= toByte(buf, i) &amp; 0xFF;<a name="line.841"></a>
+<span class="sourceLineNo">842</span>    }<a name="line.842"></a>
+<span class="sourceLineNo">843</span>    return n;<a name="line.843"></a>
+<span class="sourceLineNo">844</span>  }<a name="line.844"></a>
+<span class="sourceLineNo">845</span><a name="line.845"></a>
+<span class="sourceLineNo">846</span>  /**<a name="line.846"></a>
+<span class="sourceLineNo">847</span>   * Reads a long value at the given buffer's offset.<a name="line.847"></a>
+<span class="sourceLineNo">848</span>   * @param buffer<a name="line.848"></a>
+<span class="sourceLineNo">849</span>   * @param offset<a name="line.849"></a>
+<span class="sourceLineNo">850</span>   * @return long value at offset<a name="line.850"></a>
+<span class="sourceLineNo">851</span>   */<a name="line.851"></a>
+<span class="sourceLineNo">852</span>  public static long toLong(ByteBuffer buffer, int offset) {<a name="line.852"></a>
+<span class="sourceLineNo">853</span>    if (UNSAFE_UNALIGNED) {<a name="line.853"></a>
+<span class="sourceLineNo">854</span>      return UnsafeAccess.toLong(buffer, offset);<a name="line.854"></a>
+<span class="sourceLineNo">855</span>    } else {<a name="line.855"></a>
+<span class="sourceLineNo">856</span>      return buffer.getLong(offset);<a name="line.856"></a>
+<span class="sourceLineNo">857</span>    }<a name="line.857"></a>
+<span class="sourceLineNo">858</span>  }<a name="line.858"></a>
+<span class="sourceLineNo">859</span><a name="line.859"></a>
+<span class="sourceLineNo">860</span>  /**<a name="line.860"></a>
+<span class="sourceLineNo">861</span>   * Put an int value out to the given ByteBuffer's current position in big-endian format.<a name="line.861"></a>
+<span class="sourceLineNo">862</span>   * This also advances the position in buffer by int size.<a name="line.862"></a>
+<span class="sourceLineNo">863</span>   * @param buffer the ByteBuffer to write to<a name="line.863"></a>
+<span class="sourceLineNo">864</span>   * @param val int to write out<a name="line.864"></a>
+<span class="sourceLineNo">865</span>   */<a name="line.865"></a>
+<span class="sourceLineNo">866</span>  public static void putInt(ByteBuffer buffer, int val) {<a name="line.866"></a>
+<span class="sourceLineNo">867</span>    if (UNSAFE_UNALIGNED) {<a name="line.867"></a>
+<span class="sourceLineNo">868</span>      int newPos = UnsafeAccess.putInt(buffer, buffer.position(), val);<a name="line.868"></a>
+<span class="sourceLineNo">869</span>      buffer.position(newPos);<a name="line.869"></a>
+<span class="sourceLineNo">870</span>    } else {<a name="line.870"></a>
+<span class="sourceLineNo">871</span>      buffer.putInt(val);<a name="line.871"></a>
+<span class="sourceLineNo">872</span>    }<a name="line.872"></a>
+<span class="sourceLineNo">873</span>  }<a name="line.873"></a>
+<span class="sourceLineNo">874</span><a name="line.874"></a>
+<span class="sourceLineNo">875</span>  public static int putInt(ByteBuffer buffer, int index, int val) {<a name="line.875"></a>
+<span class="sourceLineNo">876</span>    if (UNSAFE_UNALIGNED) {<a name="line.876"></a>
+<span class="sourceLineNo">877</span>      return UnsafeAccess.putInt(buffer, index, val);<a name="line.877"></a>
+<span class="sourceLineNo">878</span>    }<a name="line.878"></a>
+<span class="sourceLineNo">879</span>    buffer.putInt(index, val);<a name="line.879"></a>
+<span class="sourceLineNo">880</span>    return index + Bytes.SIZEOF_INT;<a name="line.880"></a>
+<span class="sourceLineNo">881</span>  }<a name="line.881"></a>
+<span class="sourceLineNo">882</span><a name="line.882"></a>
+<span class="sourceLineNo">883</span>  /**<a name="line.883"></a>
+<span class="sourceLineNo">884</span>   * Reads a double value at the given buffer's offset.<a name="line.884"></a>
+<span class="sourceLineNo">885</span>   * @param buffer<a name="line.885"></a>
+<span class="sourceLineNo">886</span>   * @param offset offset where double is<a name="line.886"></a>
+<span class="sourceLineNo">887</span>   * @return double value at offset<a name="line.887"></a>
+<span class="sourceLineNo">888</span>   */<a name="line.888"></a>
+<span class="sourceLineNo">889</span>  public static double toDouble(ByteBuffer buffer, int offset) {<a name="line.889"></a>
+<span class="sourceLineNo">890</span>    return Double.longBitsToDouble(toLong(buffer, offset));<a name="line.890"></a>
+<span class="sourceLineNo">891</span>  }<a name="line.891"></a>
+<span class="sourceLineNo">892</span><a name="line.892"></a>
+<span class="sourceLineNo">893</span>  /**<a name="line.893"></a>
+<span class="sourceLineNo">894</span>   * Reads a BigDecimal value at the given buffer's offset.<a name="line.894"></a>
+<span class="sourceLineNo">895</span>   * @param buffer<a name="line.895"></a>
+<span class="sourceLineNo">896</span>   * @param offset<a name="line.896"></a>
+<span class="sourceLineNo">897</span>   * @return BigDecimal value at offset<a name="line.897"></a>
+<span class="sourceLineNo">898</span>   */<a name="line.898"></a>
+<span class="sourceLineNo">899</span>  public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) {<a name="line.899"></a>
+<span class="sourceLineNo">900</span>    if (buffer == null || length &lt; Bytes.SIZEOF_INT + 1 ||<a name="line.900"></a>
+<span class="sourceLineNo">901</span>      (offset + length &gt; buffer.limit())) {<a name="line.901"></a>
+<span class="sourceLineNo">902</span>      return null;<a name="line.902"></a>
+<span class="sourceLineNo">903</span>    }<a name="line.903"></a>
+<span class="sourceLineNo">904</span><a name="line.904"></a>
+<span class="sourceLineNo">905</span>    int scale = toInt(buffer, offset);<a name="line.905"></a>
+<span class="sourceLineNo">906</span>    byte[] tcBytes = new byte[length - Bytes.SIZEOF_INT];<a name="line.906"></a>
+<span class="sourceLineNo">907</span>    copyFromBufferToArray(tcBytes, buffer, offset + Bytes.SIZEOF_INT, 0, length - Bytes.SIZEOF_INT);<a name="line.907"></a>
+<span class="sourceLineNo">908</span>    return new BigDecimal(new BigInteger(tcBytes), scale);<a name="line.908"></a>
+<span class="sourceLineNo">909</span>  }<a name="line.909"></a>
+<span class="sourceLineNo">910</span><a name="line.910"></a>
+<span class="sourceLineNo">911</span>  /**<a name="line.911"></a>
+<span class="sourceLineNo">912</span>   * Put a short value out to the given ByteBuffer's current position in big-endian format.<a name="line.912"></a>
+<span class="sourceLineNo">913</span>   * This also advances the position in buffer by short size.<a name="line.913"></a>
+<span class="sourceLineNo">914</span>   * @param buffer the ByteBuffer to write to<a name="line.914"></a>
+<span class="sourceLineNo">915</span>   * @param val short to write out<a name="line.915"></a>
+<span class="sourceLineNo">916</span>   */<a name="line.916"></a>
+<span class="sourceLineNo">917</span>  public static void putShort(ByteBuffer buffer, short val) {<a name="line.917"></a>
+<span class="sourceLineNo">918</span>    if (UNSAFE_UNALIGNED) {<a name="line.918"></a>
+<span class="sourceLineNo">919</span>      int newPos = UnsafeAccess.putShort(buffer, buffer.position(), val);<a name="line.919"></a>
+<span class="sourceLineNo">920</span>      buffer.position(newPos);<a name="line.920"></a>
+<span class="sourceLineNo">921</span>    } else {<a name="line.921"></a>
+<span class="sourceLineNo">922</span>      buffer.putShort(val);<a name="line.922"></a>
+<span class="sourceLineNo">923</span>    }<a name="line.923"></a>
+<span class="sourceLineNo">924</span>  }<a name="line.924"></a>
+<span class="sourceLineNo">925</span><a name="line.925"></a>
+<span class="sourceLineNo">926</span>  public static int putShort(ByteBuffer buffer, int index, short val) {<a name="line.926"></a>
+<span class="sourceLineNo">927</span>    if (UNSAFE_UNALIGNED) {<a name="line.927"></a>
+<span class="sourceLineNo">928</span>      return UnsafeAccess.putShort(buffer, index, val);<a name="line.928"></a>
+<span class="sourceLineNo">929</span>    }<a name="line.929"></a>
+<span class="sourceLineNo">930</span>    buffer.putShort(index, val);<a name="line.930"></a>
+<span class="sourceLineNo">931</span>    return index + Bytes.SIZEOF_SHORT;<a name="line.931"></a>
+<span class="sourceLineNo">932</span>  }<a name="line.932"></a>
+<span class="sourceLineNo">933</span><a name="line.933"></a>
+<span class="sourceLineNo">934</span>  public static int putAsShort(ByteBuffer buf, int index, int val) {<a name="line.934"></a>
+<span class="sourceLineNo">935</span>    buf.put(index + 1, (byte) val);<a name="line.935"></a>
+<span class="sourceLineNo">936</span>    val &gt;&gt;= 8;<a name="line.936"></a>
+<span class="sourceLineNo">937</span>    buf.put(index, (byte) val);<a name="line.937"></a>
+<span class="sourceLineNo">938</span>    return index + Bytes.SIZEOF_SHORT;<a name="line.938"></a>
+<span class="sourceLineNo">939</span>  }<a name="line.939"></a>
+<span class="sourceLineNo">940</span><a name="line.940"></a>
+<span class="sourceLineNo">941</span>  /**<a name="line.941"></a>
+<span class="sourceLineNo">942</span>   * Put a long value out to the given ByteBuffer's current position in big-endian format.<a name="line.942"></a>
+<span class="sourceLineNo">943</span>   * This also advances the position in buffer by long size.<a name="line.943"></a>
+<span class="sourceLineNo">944</span>   * @param buffer the ByteBuffer to write to<a name="line.944"></a>
+<span class="sourceLineNo">945</span>   * @param val long to write out<a name="line.945"></a>
+<span class="sourceLineNo">946</span>   */<a name="line.946"></a>
+<span class="sourceLineNo">947</span>  public static void putLong(ByteBuffer buffer, long val) {<a name="line.947"></a>
+<span class="sourceLineNo">948</span>    if (UNSAFE_UNALIGNED) {<a name="line.948"></a>
+<span class="sourceLineNo">949</span>      int newPos = UnsafeAccess.putLong(buffer, buffer.position(), val);<a name="line.949"></a>
+<span class="sourceLineNo">950</span>      buffer.position(newPos);<a name="line.950"></a>
+<span class="sourceLineNo">951</span>    } else {<a name="line.951"></a>
+<span class="sourceLineNo">952</span>      buffer.putLong(val);<a name="line.952"></a>
+<span class="sourceLineNo">953</span>    }<a name="line.953"></a>
+<span class="sourceLineNo">954</span>  }<a name="line.954"></a>
+<span class="sourceLineNo">955</span><a name="line.955"></a>
+<span class="sourceLineNo">956</span>  public static int putLong(ByteBuffer buffer, int index, long val) {<a name="line.956"></a>
+<span class="sourceLineNo">957</span>    if (UNSAFE_UNALIGNED) {<a name="line.957"></a>
+<span class="sourceLineNo">958</span>      return UnsafeAccess.putLong(buffer, index, val);<a name="line.958"></a>
+<span class="sourceLineNo">959</span>    }<a name="line.959"></a>
+<span class="sourceLineNo">960</span>    buffer.putLong(index, val);<a name="line.960"></a>
+<span class="sourceLineNo">961</span>    return index + Bytes.SIZEOF_LONG;<a name="line.961"></a>
+<span class="sourceLineNo">962</span>  }<a name="line.962"></a>
+<span class="sourceLineNo">963</span><a name="line.963"></a>
+<span class="sourceLineNo">964</span>  /**<a name="line.964"></a>
+<span class="sourceLineNo">965</span>   * Copies the bytes from given array's offset to length part into the given buffer. Puts the bytes<a name="line.965"></a>
+<span class="sourceLineNo">966</span>   * to buffer's current position. This also advances the position in the 'out' buffer by 'length'<a name="line.966"></a>
+<span class="sourceLineNo">967</span>   * @param out<a name="line.967"></a>
+<span class="sourceLineNo">968</span>   * @param in<a name="line.968"></a>
+<span class="sourceLineNo">969</span>   * @param inOffset<a name="line.969"></a>
+<span class="sourceLineNo">970</span>   * @param length<a name="line.970"></a>
+<span class="sourceLineNo">971</span>   */<a name="line.971"></a>
+<span class="sourceLineNo">972</span>  public static void copyFromArrayToBuffer(ByteBuffer out, byte[] in, int inOffset, int length) {<a name="line.972"></a>
+<span class="sourceLineNo">973</span>    if (out.hasArray()) {<a name="line.973"></a>
+<span class="sourceLineNo">974</span>      System.arraycopy(in, inOffset, out.array(), out.arrayOffset() + out.position(), length);<a name="line.974"></a>
+<span class="sourceLineNo">975</span>      // Move the position in out by length<a name="line.975"></a>
+<span class="sourceLineNo">976</span>      out.position(out.position() + length);<a name="line.976"></a>
+<span class="sourceLineNo">977</span>    } else if (UNSAFE_AVAIL) {<a name="line.977"></a>
+<span class="sourceLineNo">978</span>      UnsafeAccess.copy(in, inOffset, out, out.position(), length);<a name="line.978"></a>
+<span class="sourceLineNo">979</span>      // Move the position in out by length<a name="line.979"></a>
+<span class="sourceLineNo">980</span>      out.position(out.position() + length);<a name="line.980"></a>
+<span class="sourceLineNo">981</span>    } else {<a name="line.981"></a>
+<span class="sourceLineNo">982</span>      out.put(in, inOffset, length);<a name="line.982"></a>
+<span class="sourceLineNo">983</span>    }<a name="line.983"></a>
+<span class="sourceLineNo">984</span>  }<a name="line.984"></a>
+<span class="sourceLineNo">985</span><a name="line.985"></a>
+<span class="sourceLineNo">986</span>  /**<a name="line.986"></a>
+<span class="sourceLineNo">987</span>   * Copies bytes from given array's offset to length part into the given buffer. Puts the bytes<a name="line.987"></a>
+<span class="sourceLineNo">988</span>   * to buffer's given position. This doesn't affact the position of buffer.<a name="line.988"></a>
+<span class="sourceLineNo">989</span>   * @param out<a name="line.989"></a>
+<span class="sourceLineNo">990</span>   * @param in<a name="line.990"></a>
+<span class="sourceLineNo">991</span>   * @param inOffset<a name="line.991"></a>
+<span class="sourceLineNo">992</span>   * @param length<a name="line.992"></a>
+<span class="sourceLineNo">993</span>   */<a name="line.993"></a>
+<span class="sourceLineNo">994</span>  public static void copyFromArrayToBuffer(ByteBuffer out, int outOffset, byte[] in, int inOffset,<a name="line.994"></a>
+<span class="sourceLineNo">995</span>      int length) {<a name="line.995"></a>
+<span class="sourceLineNo">996</span>    if (out.hasArray()) {<a name="line.996"></a>
+<span class="sourceLineNo">997</span>      System.arraycopy(in, inOffset, out.array(), out.arrayOffset() + outOffset, length);<a name="line.997"></a>
+<span class="sourceLineNo">998</span>    } else if (UNSAFE_AVAIL) {<a name="line.998"></a>
+<span class="sourceLineNo">999</span>      UnsafeAccess.copy(in, inOffset, out, outOffset, length);<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>    } else {<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>      ByteBuffer outDup = out.duplicate();<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>      outDup.position(outOffset);<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>      outDup.put(in, inOffset, length);<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span>    }<a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>  }<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span><a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>  /**<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>   * Copies specified number of bytes from given offset of 'in' ByteBuffer to<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>   * the array. This doesn't affact the position of buffer.<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>   * @param out<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>   * @param in<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>   * @param sourceOffset<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>   * @param destinationOffset<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>   * @param length<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>   */<a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>  public static void copyFromBufferToArray(byte[] out, ByteBuffer in, int sourceOffset,<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>      int destinationOffset, int length) {<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>    if (in.hasArray()) {<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>      System.arraycopy(in.array(), sourceOffset + in.arrayOffset(), out, destinationOffset, length);<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>    } else if (UNSAFE_AVAIL) {<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>      UnsafeAccess.copy(in, sourceOffset, out, destinationOffset, length);<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>    } else {<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span>      ByteBuffer inDup = in.duplicate();<a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>      inDup.position(sourceOffset);<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>      inDup.get(out, destinationOffset, length);<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>    }<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>  }<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span><a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>  /**<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>   * Similar to  {@link Arrays#copyOfRange(byte[], int, int)}<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>   * @param original the buffer from which the copy has to happen<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>   * @param from the starting index<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>   * @param to the ending index<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>   * @return a byte[] created out of the copy<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>   */<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>  public static byte[] copyOfRange(ByteBuffer original, int from, int to) {<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>    int newLength = to - from;<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>    if (newLength &lt; 0) throw new IllegalArgumentException(from + " &gt; " + to);<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>    byte[] copy = new byte[newLength];<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>    ByteBufferUtils.copyFromBufferToArray(copy, original, from, 0, newLength);<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>    return copy;<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>  }<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span><a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>  // For testing purpose<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>  public static String toStringBinary(final ByteBuffer b, int off, int len) {<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>    StringBuilder result = new StringBuilder();<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>    // Just in case we are passed a 'len' that is &gt; buffer length...<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>    if (off &gt;= b.capacity())<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>      return result.toString();<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>    if (off + len &gt; b.capacity())<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>      len = b.capacity() - off;<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>    for (int i = off; i &lt; off + len; ++i) {<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>      int ch = b.get(i) &amp; 0xFF;<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span>      if ((ch &gt;= '0' &amp;&amp; ch &lt;= '9') || (ch &gt;= 'A' &amp;&amp; ch &lt;= 'Z') || (ch &gt;= 'a' &amp;&amp; ch &lt;= 'z')<a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>          || " `~!@#$%^&amp;*()-_=+[]{}|;:'\",.&lt;&gt;/?".indexOf(ch) &gt;= 0) {<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>        result.append((char) ch);<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>      } else {<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>        result.append(String.format("\\x%02X", ch));<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>      }<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>    }<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>    return result.toString();<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>  }<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span><a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>  public static String toStringBinary(final ByteBuffer b) {<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>    return toStringBinary(b, 0, b.capacity());<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>  }<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>}<a name="line.1067"></a>
 
 
 


Mime
View raw message