本文整理汇总了Java中java.nio.LongBuffer.put方法的典型用法代码示例。如果您正苦于以下问题:Java LongBuffer.put方法的具体用法?Java LongBuffer.put怎么用?Java LongBuffer.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.LongBuffer
的用法示例。
在下文中一共展示了LongBuffer.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: append
import java.nio.LongBuffer; //导入方法依赖的package包/类
@Override
public LongImmutableArray.Builder append(long 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, value);
bitmask |= 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: testGetLong
import java.nio.LongBuffer; //导入方法依赖的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) {
}
}
示例7: testGetLongInt
import java.nio.LongBuffer; //导入方法依赖的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) {
}
}
示例8: toByteArray
import java.nio.LongBuffer; //导入方法依赖的package包/类
private static byte[] toByteArray(UUID uuid) {
byte[] byteArray = new byte[(Long.SIZE / Byte.SIZE) * 2];
ByteBuffer buffer = ByteBuffer.wrap(byteArray);
LongBuffer longBuffer = buffer.asLongBuffer();
longBuffer.put(new long[] { uuid.getMostSignificantBits(),uuid.getLeastSignificantBits() });
return byteArray;
}
示例9: setUNID
import java.nio.LongBuffer; //导入方法依赖的package包/类
/**
* Sets a new universal id stored by this OID
*
* @param unid new universal id
*/
public void setUNID(String unid) {
if (unid.length()!=32) {
throw new IllegalArgumentException("Invalid unid: "+unid);
}
for (int i=0; i<32; i++) {
char c = unid.charAt(i);
if ((c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f')) {
}
else {
throw new IllegalArgumentException("Invalid unid: "+unid);
}
}
write();
Pointer oidPtr = getPointer();
ByteBuffer data = oidPtr.getByteBuffer(0, 16).order(ByteOrder.LITTLE_ENDIAN);
LongBuffer longBuffer = data.asLongBuffer();
String firstPart = unid.substring(0, 16);
long firstPartAsLong = new BigInteger(firstPart, 16).longValue();
longBuffer.put(0, firstPartAsLong);
String secondPart = unid.substring(16);
long secondPartAsLong = new BigInteger(secondPart, 16).longValue();
longBuffer.put(1, secondPartAsLong);
read();
String newWrittenUnid = getUNIDAsString();
if (!unid.equalsIgnoreCase(newWrittenUnid)) {
//should not happen ;-)
throw new IllegalStateException("Error setting new UNID in OID structure. Probably wrong memory alignment. Please contact dev.");
}
}
示例10: getAccumulatorOutput
import java.nio.LongBuffer; //导入方法依赖的package包/类
public static void getAccumulatorOutput(int analogPortHandle, LongBuffer value, LongBuffer count)
{
double accum_value = getWrapperFromBuffer(analogPortHandle).getAccumulator();
accum_value *= 1000000000;
accum_value *= .007; // Volts per degree second
accum_value *= 100;
value.put((long) accum_value);
count.put(1);
}
示例11: copy
import java.nio.LongBuffer; //导入方法依赖的package包/类
public static void copy(LongBuffer src, LongBuffer dst) {
if (dst != null && !dst.isDirect()) {
int saved_position = dst.position();
dst.put(src);
dst.position(saved_position);
}
}
示例12: doWrap
import java.nio.LongBuffer; //导入方法依赖的package包/类
private static LongBuffer doWrap(LongBuffer buffer) {
LongBuffer direct_buffer = lookupBuffer(buffer);
direct_buffer.clear();
int saved_position = buffer.position();
direct_buffer.put(buffer);
buffer.position(saved_position);
direct_buffer.flip();
return direct_buffer;
}
示例13: close
import java.nio.LongBuffer; //导入方法依赖的package包/类
public void close()
throws ApfloatRuntimeException
{
if ((this.mode & WRITE) != 0 && getData() != null)
{
final long[] array = getLongData();
ReadableByteChannel in = new ReadableByteChannel()
{
public int read(ByteBuffer buffer)
{
LongBuffer dst = buffer.asLongBuffer();
int writeLength = dst.remaining();
dst.put(array, this.writePosition, writeLength);
this.writePosition += writeLength;
buffer.position(buffer.position() + writeLength * 8);
return writeLength * 8;
}
public void close() {}
public boolean isOpen() { return true; }
private int writePosition = 0;
};
transferFrom(in, this.fileOffset * 8, (long) array.length * 8);
}
super.close();
}
示例14: put
import java.nio.LongBuffer; //导入方法依赖的package包/类
public static LongBuffer put(LongBuffer buf, long s) {
buf.put(s);
writeLongBuffer(buf);
return buf;
}
示例15: serializeAndWrite
import java.nio.LongBuffer; //导入方法依赖的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;
}
}