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


Java LongBuffer類代碼示例

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


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

示例1: testGet_io

import java.nio.LongBuffer; //導入依賴的package包/類
public void testGet_io() throws IOException {
  assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
  assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
  assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
  assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
  ArbitraryInstances.get(PrintStream.class).println("test");
  ArbitraryInstances.get(PrintWriter.class).println("test");
  assertNotNull(ArbitraryInstances.get(File.class));
  assertFreshInstanceReturned(
      ByteArrayOutputStream.class, OutputStream.class,
      Writer.class, StringWriter.class,
      PrintStream.class, PrintWriter.class);
  assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
  assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
  assertNotNull(ArbitraryInstances.get(ByteSink.class));
  assertNotNull(ArbitraryInstances.get(CharSink.class));
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:27,代碼來源:ArbitraryInstancesTest.java

示例2: main

import java.nio.LongBuffer; //導入依賴的package包/類
public static void main(String[] args) {
    Random r = new Random();
    int entries = 1000;
    boolean[] src = new boolean[entries * 64];
    long[] dest = new long[entries];
    long[] result = new long[entries];

    for (int c = 0; c < 2000; c++) {
        for (int i = 0; i < entries; i++) {
            long l = r.nextLong();
            for (int bit = 0; bit < 64; bit++) {
                src[i * 64 + bit] = (l & (1L << bit)) != 0;
            }
            dest[i] = 0;
            result[i] = l;
        }
        test(src, 0, LongBuffer.wrap(dest, 0, dest.length), 0, src.length);
        for (int i = 0; i < entries; i++) {
            if (dest[i] != result[i]) {
                throw new InternalError(i + ": " + Long.toHexString(dest[i]) + " != " + Long.toHexString(result[i]));
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:Test6661247.java

示例3: testLongGet

import java.nio.LongBuffer; //導入依賴的package包/類
@Test(dataProvider = "longViewProvider")
public void testLongGet(String desc, IntFunction<ByteBuffer> fbb,
                        Function<ByteBuffer, LongBuffer> fbi) {
    ByteBuffer bb = allocate(fbb);
    LongBuffer vb = fbi.apply(bb);
    int o = bb.position();

    for (int i = 0; i < vb.limit(); i++) {
        long fromBytes = getLongFromBytes(bb, o + i * 8);
        long fromMethodView = bb.getLong(o + i * 8);
        assertValues(i, fromBytes, fromMethodView, bb);

        long fromBufferView = vb.get(i);
        assertValues(i, fromMethodView, fromBufferView, bb, vb);
    }

    for (int i = 0; i < vb.limit(); i++) {
        long v = getLongFromBytes(bb, o + i * 8);
        long a = bb.getLong();
        assertValues(i, v, a, bb);

        long b = vb.get();
        assertValues(i, a, b, bb, vb);
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ByteBufferViews.java

示例4: isDirect

import java.nio.LongBuffer; //導入依賴的package包/類
private static boolean isDirect(Buffer buf) {
    if (buf instanceof FloatBuffer) {
        return ((FloatBuffer) buf).isDirect();
    }
    if (buf instanceof IntBuffer) {
        return ((IntBuffer) buf).isDirect();
    }
    if (buf instanceof ShortBuffer) {
        return ((ShortBuffer) buf).isDirect();
    }
    if (buf instanceof ByteBuffer) {
        return ((ByteBuffer) buf).isDirect();
    }
    if (buf instanceof DoubleBuffer) {
        return ((DoubleBuffer) buf).isDirect();
    }
    if (buf instanceof LongBuffer) {
        return ((LongBuffer) buf).isDirect();
    }
    throw new UnsupportedOperationException(" BufferAux.isDirect was called on " + buf.getClass().getName());
}
 
開發者ID:asiermarzo,項目名稱:Ultraino,代碼行數:22,代碼來源:BufferUtils.java

示例5: testCompression

import java.nio.LongBuffer; //導入依賴的package包/類
@Test
public void testCompression() {
    int n = 1000000;
    FloatHistogram x = new FloatHistogram(1e-3, 10);

    Random rand = new Random();
    for (int i = 0; i < n; i++) {
        x.add(rand.nextDouble());
    }
    long[] compressed = x.getCompressedCounts();
    System.out.printf("%d\n", compressed.length);
    long[] uncompressed = new long[x.getCounts().length];
    long[] counts = x.getCounts();

    int k = Simple64.decompress(LongBuffer.wrap(compressed), uncompressed);
    assertEquals(k, counts.length);
    for (int i = 0; i < uncompressed.length; i++) {
        assertEquals(counts[i], uncompressed[i]);
    }
}
 
開發者ID:tdunning,項目名稱:latency-histograms,代碼行數:21,代碼來源:FloatHistogramTest.java

示例6: readLongArray

import java.nio.LongBuffer; //導入依賴的package包/類
/**
 * ByteChannelからlong配列を読み込む
 * @param channel
 * @return
 * @throws IOException
 */
public static long[] readLongArray(@NonNull final ByteChannel channel)
	throws IOException {
	
	final int n = readInt(channel);
	final ByteBuffer buf = ByteBuffer.allocate(n * 8).order(ByteOrder.BIG_ENDIAN);
	final int readBytes = channel.read(buf);
	if (readBytes != n * 8) throw new IOException();
	buf.clear();
	final LongBuffer result = buf.asLongBuffer();
	if (result.hasArray()) {
		return result.array();
	}  else {
		final long[] b = new long[n];
		result.get(b);
		return b;
	}
}
 
開發者ID:saki4510t,項目名稱:libcommon,代碼行數:24,代碼來源:ChannelHelper.java

示例7: readAsLongBuffer

import java.nio.LongBuffer; //導入依賴的package包/類
@Benchmark
public void readAsLongBuffer() throws IOException {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(64 * 1024);
    LongBuffer longBuffer = byteBuffer.asLongBuffer();
    long readValueCount = 0;
    try (ReadableByteChannel byteChannel = _testFile.open();) {
        while (byteChannel.read(byteBuffer) > 0) {
            byteBuffer.flip();
            while (longBuffer.hasRemaining()) {
                long longValue = longBuffer.get();
                assertThat(longValue).isEqualTo(readValueCount);
                readValueCount++;
            }
            longBuffer.rewind();
        }
    }
    assertThat(readValueCount).isEqualTo(BinaryByteUnit.GIBIBYTES.toBytes(1) / 8);
}
 
開發者ID:jzillmann,項目名稱:gradle-jmh-report,代碼行數:19,代碼來源:ReadBenchmark.java

示例8: createFramebuffers

import java.nio.LongBuffer; //導入依賴的package包/類
private static long[] createFramebuffers(VkDevice device, Swapchain swapchain, long renderPass, int width, int height) {
    LongBuffer attachments = stackMallocLong(1);
    VkFramebufferCreateInfo fci = VkFramebufferCreateInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO)
            .pAttachments(attachments)
            .flags(VK_FLAGS_NONE)
            .height(height)
            .width(width)
            .layers(1)
            .pNext(NULL)
            .renderPass(renderPass);
    // Create a framebuffer for each swapchain image
    long[] framebuffers = new long[swapchain.images.length];
    LongBuffer pFramebuffer = stackMallocLong(1);
    for (int i = 0; i < swapchain.images.length; i++) {
        attachments.put(0, swapchain.imageViews[i]);
        int err = vkCreateFramebuffer(device, fci, null, pFramebuffer);
        long framebuffer = pFramebuffer.get(0);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to create framebuffer: " + translateVulkanResult(err));
        }
        framebuffers[i] = framebuffer;
    }
    return framebuffers;
}
 
開發者ID:LWJGLX,項目名稱:autostack,代碼行數:26,代碼來源:ClearScreenDemoUseNewStack.java

示例9: setupDebugging

import java.nio.LongBuffer; //導入依賴的package包/類
/**
 * This function sets up the debug callback which the validation layers will use to yell at us when we make mistakes.
 */
private static long setupDebugging(VkInstance instance, int flags, VkDebugReportCallbackEXT callback) {
    // Again, a struct to create something, in this case the debug report callback
    VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = VkDebugReportCallbackCreateInfoEXT.callocStack()
            .sType(VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT) // <- the struct type
            .pNext(NULL) // <- must be NULL
            .pfnCallback(callback) // <- the actual function pointer (in LWJGL a Closure)
            .pUserData(NULL) // <- any user data provided to the debug report callback function
            .flags(flags); // <- indicates which kind of messages we want to receive
    LongBuffer pCallback = stackMallocLong(1); // <- allocate a LongBuffer (for a non-dispatchable handle)
    // Actually create the debug report callback
    int err = vkCreateDebugReportCallbackEXT(instance, dbgCreateInfo, null, pCallback);
    long callbackHandle = pCallback.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create VkInstance: " + translateVulkanResult(err));
    }
    return callbackHandle;
}
 
開發者ID:LWJGLX,項目名稱:autostack,代碼行數:21,代碼來源:ClearScreenDemoUseCallerStack.java

示例10: append

import java.nio.LongBuffer; //導入依賴的package包/類
@Override
public DoubleImmutableArray.Builder append(double value) {
    final LongBuffer current;
    
    // If the specified outer index is not yet allocated, do that first.
    if (outer == buffers.size()) {
        buffers.add(current = ByteBuffer.allocateDirect(
            BUFFER_SIZE * Long.BYTES
        ).asLongBuffer());
    } else {
        current = buffers.getLast();
    }
    
    // Store the value at the specified index.
    current.put(inner, Double.doubleToLongBits(value));
    
    // If the inner index is about to overflow, reset it and increment outer
    // index until next time.
    if (BUFFER_SIZE == ++inner) {
        inner = 0;
        outer++;
    }
    
    return this;
}
 
開發者ID:Pyknic,項目名稱:immutable-array,代碼行數:26,代碼來源:DoubleImmutableArrayBuilder.java

示例11: forEachThenClear

import java.nio.LongBuffer; //導入依賴的package包/類
private void forEachThenClear(LongConsumer action) {
    final long length = length();
    final LongBuffer[] bufferArray = bufferArray();
    
    for (long l = 0; l < length; l++) {
        final int o = outerIndex(l);
        final int i = innerIndex(l);
        
        action.accept(bufferArray[o].get(i));
        
        // If we just consumed the last value in this buffer, clear it.
        if (i + 1 == BUFFER_SIZE) {
            MemoryUtil.clear(bufferArray[o]);
        }
    }
}
 
開發者ID:Pyknic,項目名稱:immutable-array,代碼行數:17,代碼來源:LongImmutableArrayBuilder.java

示例12: computeHashForChunk

import java.nio.LongBuffer; //導入依賴的package包/類
private static long computeHashForChunk(ByteBuffer buffer) {

        LongBuffer longBuffer = buffer.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer();
        long hash = 0;

        while (longBuffer.hasRemaining()) {
            hash += longBuffer.get();
        }

        return hash;
    }
 
開發者ID:atulgpt,項目名稱:SubtitleDownloader,代碼行數:12,代碼來源:OpenSubtitlesHasher.java

示例13: longToByteArray

import java.nio.LongBuffer; //導入依賴的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

示例14: longToByteArrayLittleEndian

import java.nio.LongBuffer; //導入依賴的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

示例15: testFreshInstance

import java.nio.LongBuffer; //導入依賴的package包/類
@AndroidIncompatible // problem with equality of Type objects?
public void testFreshInstance() {
  assertFreshInstances(
      String.class, CharSequence.class,
      Appendable.class, StringBuffer.class, StringBuilder.class,
      Pattern.class, MatchResult.class,
      Number.class, int.class, Integer.class,
      long.class, Long.class,
      short.class, Short.class,
      byte.class, Byte.class,
      boolean.class, Boolean.class,
      char.class, Character.class,
      int[].class, Object[].class,
      UnsignedInteger.class, UnsignedLong.class,
      BigInteger.class, BigDecimal.class,
      Throwable.class, Error.class, Exception.class, RuntimeException.class,
      Charset.class, Locale.class, Currency.class,
      List.class, Map.Entry.class,
      Object.class,
      Equivalence.class, Predicate.class, Function.class,
      Comparable.class, Comparator.class, Ordering.class,
      Class.class, Type.class, TypeToken.class,
      TimeUnit.class, Ticker.class,
      Joiner.class, Splitter.class, CharMatcher.class,
      InputStream.class, ByteArrayInputStream.class,
      Reader.class, Readable.class, StringReader.class,
      OutputStream.class, ByteArrayOutputStream.class,
      Writer.class, StringWriter.class, File.class,
      Buffer.class, ByteBuffer.class, CharBuffer.class,
      ShortBuffer.class, IntBuffer.class, LongBuffer.class,
      FloatBuffer.class, DoubleBuffer.class,
      String[].class, Object[].class, int[].class);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:34,代碼來源:FreshValueGeneratorTest.java


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