本文整理匯總了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));
}
示例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]));
}
}
}
}
示例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);
}
}
示例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());
}
示例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]);
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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]);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}