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


Java ByteBuffer.asLongBuffer方法代碼示例

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


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

示例1: longToByteArray

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public static byte[] longToByteArray(long inLong) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	LongBuffer lBuffer = bBuffer.asLongBuffer();
	lBuffer.put(inLong);
	return bArray;
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:8,代碼來源:BinUtils.java

示例2: longToByteArrayLittleEndian

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public static byte[] longToByteArrayLittleEndian(long inLong) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	bBuffer.order(ByteOrder.LITTLE_ENDIAN);
	LongBuffer lBuffer = bBuffer.asLongBuffer();
	lBuffer.put(inLong);
	return bArray;
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:9,代碼來源:BinUtils.java

示例3: asLongBuffer

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public static LongBuffer asLongBuffer(ByteBuffer buf) {
    LongBuffer buffer = buf.asLongBuffer();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    } else {
        bufferViews.put(buffer, buf);
    }
    return buffer;
}
 
開發者ID:LWJGLX,項目名稱:debug,代碼行數:11,代碼來源:RT.java

示例4: deserialize

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Read the inflights file and return a
 * {@link com.google.common.collect.SetMultimap}
 * of transactionIDs to events that were inflight.
 *
 * @return - map of inflight events per txnID.
 */
public SetMultimap<Long, Long> deserialize()
    throws IOException, BadCheckpointException {
  SetMultimap<Long, Long> inflights = HashMultimap.create();
  if (!fileChannel.isOpen()) {
    file = new RandomAccessFile(inflightEventsFile, "rw");
    fileChannel = file.getChannel();
  }
  if (file.length() == 0) {
    return inflights;
  }
  file.seek(0);
  byte[] checksum = new byte[16];
  file.read(checksum);
  ByteBuffer buffer = ByteBuffer.allocate(
      (int) (file.length() - file.getFilePointer()));
  fileChannel.read(buffer);
  byte[] fileChecksum = digest.digest(buffer.array());
  if (!Arrays.equals(checksum, fileChecksum)) {
    throw new BadCheckpointException("Checksum of inflights file differs"
        + " from the checksum expected.");
  }
  buffer.position(0);
  LongBuffer longBuffer = buffer.asLongBuffer();
  try {
    while (true) {
      long txnID = longBuffer.get();
      int numEvents = (int) (longBuffer.get());
      for (int i = 0; i < numEvents; i++) {
        long val = longBuffer.get();
        inflights.put(txnID, val);
      }
    }
  } catch (BufferUnderflowException ex) {
    LOG.debug("Reached end of inflights buffer. Long buffer position ="
        + String.valueOf(longBuffer.position()));
  }
  return inflights;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:46,代碼來源:FlumeEventQueue.java

示例5: testGetLong

import java.nio.ByteBuffer; //導入方法依賴的package包/類
@Test
public void testGetLong() {
  ByteBuffer bb = ByteBuffer.allocate(40);
  LongBuffer lb = bb.asLongBuffer();
  lb.put(0x1110223344556677L);
  lb.put(0x2220334455667788L);
  lb.put(0x3330445566778899L);
  lb.put(0x4440556677889900L);
  lb.put(0x55506677889900AAL);
  byte[] bytes = bb.array();
  ByteSource bs = createByteSource(bytes);
  long l = bs.getLong();
  assertEquals(0x1110223344556677L, l);
  assertEquals(8, bs.position());
  l = bs.getLong();
  assertEquals(0x2220334455667788L, l);
  assertEquals(16, bs.position());
  bs.position(4 * 8);
  l = bs.getLong();
  assertEquals(0x55506677889900AAL, l);
  assertEquals(40, bs.position());
  try {
    bs.getLong();
    fail("expected BufferUnderflowException");
  } catch (BufferUnderflowException expected) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:28,代碼來源:ByteSourceJUnitTest.java

示例6: testGetLongInt

import java.nio.ByteBuffer; //導入方法依賴的package包/類
@Test
public void testGetLongInt() {
  ByteBuffer bb = ByteBuffer.allocate(40);
  LongBuffer lb = bb.asLongBuffer();
  lb.put(0x1110223344556677L);
  lb.put(0x2220334455667788L);
  lb.put(0x3330445566778899L);
  lb.put(0x4440556677889900L);
  lb.put(0x55506677889900AAL);
  byte[] bytes = bb.array();
  ByteSource bs = createByteSource(bytes);
  bs.position(3);
  long l = bs.getLong(0);
  assertEquals(0x1110223344556677L, l);
  assertEquals(3, bs.position());
  l = bs.getLong(8);
  assertEquals(0x2220334455667788L, l);
  assertEquals(3, bs.position());
  l = bs.getLong(4 * 8);
  assertEquals(0x55506677889900AAL, l);
  assertEquals(3, bs.position());
  try {
    bs.getLong((4 * 8) + 1);
    fail("expected IndexOutOfBoundsException");
  } catch (IndexOutOfBoundsException expected) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:28,代碼來源:ByteSourceJUnitTest.java

示例7: asView

import java.nio.ByteBuffer; //導入方法依賴的package包/類
Buffer asView(ByteBuffer b, PrimitiveType t) {
    switch (t) {
        case BYTE: return b;
        case CHAR: return b.asCharBuffer();
        case SHORT: return b.asShortBuffer();
        case INT: return b.asIntBuffer();
        case LONG: return b.asLongBuffer();
        case FLOAT: return b.asFloatBuffer();
        case DOUBLE: return b.asDoubleBuffer();
    }
    throw new InternalError("Should not reach here");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:ByteBufferTest.java

示例8: getMetadata

import java.nio.ByteBuffer; //導入方法依賴的package包/類
private ByteBuffer getMetadata (BufferedImage img, String id, long start, long end) throws IOException {
    byte[] bytes = new byte[METAENTRY_LENGTH];
    Arrays.fill(bytes, (byte)'-'); //XXX
    
    ByteBuffer result = ByteBuffer.wrap(bytes);
    result.position(0);
    
    int width = img.getWidth();
    int height = img.getHeight();
    
    id = convertPathSeparators (id);
    
    //First write the id length, width and height as ints
    
    IntBuffer ibuf = result.asIntBuffer();
    ibuf.put(id.length()).put(width).put(height);
    
    result.position(result.position() + (ibuf.position() * 4));
    
    //Then write the start and end positions in the cache file as longs
    
    LongBuffer lbuf = result.asLongBuffer();
    lbuf.put(start).put(end);
    
    result.position(result.position() + (lbuf.position() * 8));
    
    //We are intentionally stripping the high eight bits - unless we start
    //having modules with katakana pathnames, 16 bits clean filenames will
    //not be needed
    
    char[] chars = id.toCharArray();
    if (chars.length + result.position() > METAENTRY_LENGTH) {
        throw new IOException ("ID " + id + " too long.  Limit is " + (METAENTRY_LENGTH - 8));
    }
    
    //Now write the id text
    for (int i=0; i < chars.length; i++) {
        result.put((byte) chars[i]);
    }
    
    result.position(METAENTRY_LENGTH);
    result.flip();
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:45,代碼來源:CacheWriter.java

示例9: serializeAndWrite

import java.nio.ByteBuffer; //導入方法依賴的package包/類
/**
 * Serialize the set of in flights into a byte longBuffer.
 *
 * @return Returns the checksum of the buffer that is being
 * asynchronously written to disk.
 */
public void serializeAndWrite() throws Exception {
  Collection<Long> values = inflightEvents.values();
  if (!fileChannel.isOpen()) {
    file = new RandomAccessFile(inflightEventsFile, "rw");
    fileChannel = file.getChannel();
  }
  if (values.isEmpty()) {
    file.setLength(0L);
  }
  //What is written out?
  //Checksum - 16 bytes
  //and then each key-value pair from the map:
  //transactionid numberofeventsforthistxn listofeventpointers

  try {
    int expectedFileSize = (((inflightEvents.keySet().size() * 2) //for transactionIDs and
                                                                  //events per txn ID
        + values.size()) * 8) //Event pointers
        + 16; //Checksum
    //There is no real need of filling the channel with 0s, since we
    //will write the exact number of bytes as expected file size.
    file.setLength(expectedFileSize);
    Preconditions.checkState(file.length() == expectedFileSize,
        "Expected File size of inflight events file does not match the "
            + "current file size. Checkpoint is incomplete.");
    file.seek(0);
    final ByteBuffer buffer = ByteBuffer.allocate(expectedFileSize);
    LongBuffer longBuffer = buffer.asLongBuffer();
    for (Long txnID : inflightEvents.keySet()) {
      Set<Long> pointers = inflightEvents.get(txnID);
      longBuffer.put(txnID);
      longBuffer.put((long) pointers.size());
      LOG.debug("Number of events inserted into "
          + "inflights file: " + String.valueOf(pointers.size())
          + " file: " + inflightEventsFile.getCanonicalPath());
      long[] written = ArrayUtils.toPrimitive(
          pointers.toArray(new Long[0]));
      longBuffer.put(written);
    }
    byte[] checksum = digest.digest(buffer.array());
    file.write(checksum);
    buffer.position(0);
    fileChannel.write(buffer);
    fileChannel.force(true);
    syncRequired = false;
  } catch (IOException ex) {
    LOG.error("Error while writing checkpoint to disk.", ex);
    throw ex;
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:57,代碼來源:FlumeEventQueue.java

示例10: PerfCounter

import java.nio.ByteBuffer; //導入方法依賴的package包/類
private PerfCounter(String name, int type) {
    this.name = name;
    ByteBuffer bb = perf.createLong(name, type, U_None, 0L);
    bb.order(ByteOrder.nativeOrder());
    this.lb = bb.asLongBuffer();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:PerfCounter.java


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