當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuffer.hashCode方法代碼示例

本文整理匯總了Java中java.nio.ByteBuffer.hashCode方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuffer.hashCode方法的具體用法?Java ByteBuffer.hashCode怎麽用?Java ByteBuffer.hashCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.hashCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toHex

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Returns a formatted hex string of an area of this Memory.
 * Used primarily for testing.
 * @param preamble a descriptive header
 * @param offsetBytes offset bytes relative to the Memory start
 * @param lengthBytes number of bytes to convert to a hex string
 * @param state the ResourceState
 * @return a formatted hex string in a human readable array
 */
static String toHex(final String preamble, final long offsetBytes, final int lengthBytes,
    final ResourceState state) {
  checkBounds(offsetBytes, lengthBytes, state.getCapacity());
  final StringBuilder sb = new StringBuilder();
  final Object uObj = state.getUnsafeObject();
  final String uObjStr = (uObj == null) ? "null"
          : uObj.getClass().getSimpleName() + ", " + (uObj.hashCode() & 0XFFFFFFFFL);
  final ByteBuffer bb = state.getByteBuffer();
  final String bbStr = (bb == null) ? "null"
          : bb.getClass().getSimpleName() + ", " + (bb.hashCode() & 0XFFFFFFFFL);
  final MemoryRequestServer memReqSvr = state.getMemoryRequestServer();
  final String memReqStr = (memReqSvr == null) ? "null"
          : memReqSvr.getClass().getSimpleName() + ", " + (memReqSvr.hashCode() & 0XFFFFFFFFL);
  final long cumBaseOffset = state.getCumBaseOffset();
  sb.append(preamble).append(LS);
  sb.append("NativeBaseOffset    : ").append(state.getNativeBaseOffset()).append(LS);
  sb.append("UnsafeObj, hashCode : ").append(uObjStr).append(LS);
  sb.append("UnsafeObjHeader     : ").append(state.getUnsafeObjectHeader()).append(LS);
  sb.append("ByteBuf, hashCode   : ").append(bbStr).append(LS);
  sb.append("RegionOffset        : ").append(state.getRegionOffset()).append(LS);
  sb.append("Capacity            : ").append(state.getCapacity()).append(LS);
  sb.append("CumBaseOffset       : ").append(cumBaseOffset).append(LS);
  sb.append("MemReq, hashCode    : ").append(memReqStr).append(LS);
  sb.append("Valid               : ").append(state.isValid()).append(LS);
  sb.append("Resource Read Only  : ").append(state.isResourceReadOnly()).append(LS);
  sb.append("Resource Endianness : ").append(state.order().toString()).append(LS);
  sb.append("JDK Version         : ").append(UnsafeUtil.JDK).append(LS);
  //Data detail
  sb.append("Data, littleEndian  :  0  1  2  3  4  5  6  7");

  for (long i = 0; i < lengthBytes; i++) {
    final int b = unsafe.getByte(uObj, cumBaseOffset + offsetBytes + i) & 0XFF;
    if ((i % 8) == 0) { //row header
      sb.append(String.format("%n%20s: ", offsetBytes + i));
    }
    sb.append(String.format("%02x ", b));
  }
  sb.append(LS);

  return sb.toString();
}
 
開發者ID:DataSketches,項目名稱:memory,代碼行數:51,代碼來源:Memory.java


注:本文中的java.nio.ByteBuffer.hashCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。