Questions tagged [bytebuffer]

A binary buffer with no specific encoding. Use this tag only if you're having specific problems in relation with byte buffers

A binary buffer with no specific encoding.

Examples include byte[] in Java, char[] or uint8_t[] in C++. Objects like std::wstring_t that have a specific encoding (like UTF-8) assigned to them are no byte buffers.

Use this tag only if you're having specific problems in relation with byte buffers. Do not use this tag if there is no indication that the byte buffer you are using has any relation to the problem you're asking about.

919 questions
5
votes
2 answers

Java ByteBuffer put vs wrap

What is the fastest way to fill up a pre-allocated ByteBuffer in Java? I first set the size of the byte buffer with allocateDirect(), this only needs to be done once. After, I need to fill it up continuously (recycling it) as fast as possible with…
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
5
votes
1 answer

How to read a request using CompletionHandlers and a ByteBuffer smaller than the request?

I am using Java 7 and AsynchronousSocketChannel. I would like to read a request (e.g. HTTP POST) but I'm struggling to come up with a nice solution to read the full request, if it's bigger than the size of the ByteBuffer I'm using. E.g. if the…
Jonas
  • 121,568
  • 97
  • 310
  • 388
4
votes
2 answers

Obtain low and high order nybbles from byte within Java ByteBuffer

I need to extract two integer values from a byte stored within a ByteBuffer (little endian order) ByteBuffer bb = ByteBuffer.wrap(inputBuffer); bb.order(ByteOrder.LITTLE_ENDIAN); The values I need to obtain from any byte within the ByteBuffer…
Tony
  • 3,587
  • 8
  • 44
  • 77
4
votes
2 answers

Is setting ByteBuffer order (depending on buffer-use) a safe / good optimization?

Java is Big-Endian; Network stack is Big-Endian; Intel/AMD (basically all of our computers) and ARM CPU's (most common Android and iOS chips) are all little-endian as well. Given all of that, if I am allocating a direct ByteBuffer for different…
Riyad Kalla
  • 10,604
  • 7
  • 53
  • 56
4
votes
5 answers

Find a string inside a bytebuffer

I'm switching from C to Java. I'm wondering about how to find a string inside a bytebuffer, is there something like memchr in java? The bytebuffer is only partly a string, the rest is raw bytes so any java method has to work on bytes + chars. I am…
Blub
  • 13,014
  • 18
  • 75
  • 102
4
votes
3 answers

Is there an explanation for the behavior of this Java ByteBuffer?

I need to convert numerical values into byte arrays. For example, to convert a long to a byte array, I have this method: public static byte[] longToBytes(long l) { ByteBuffer buff = ByteBuffer.allocate(8); buff.order(ByteOrder.BIG_ENDIAN); …
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
4
votes
1 answer

How to convert byte[] to bytebuffer native memory?

I need pass a large amount memory to jni side to parse it. I used GetByteArrayElements to get the native pointer before.but i found this method is always copy the memory,not using the memory directly. So i use GetDirectBufferAddress to get memory…
PDF1001
  • 173
  • 3
  • 13
4
votes
2 answers

Get an Publisher from InputStream

I just upgraded my mongo-db-java-driver and now the handy function GridFSBucket.uploadFromStream has gone. Therefore we now got a GridFSUploadPublisher uploadFromPublisher(String filename, Publisher source); Any ideas how to…
wutzebaer
  • 14,365
  • 19
  • 99
  • 170
4
votes
2 answers

Java ByteBuffer issues with signed and unsigned types converting byte array to integer

I expected this: ByteBuffer.wrap(new byte[] { 0, 0, 0, -34 }).getInt() == 222 However the following is true: ByteBuffer.wrap(new byte[] { 0, 0, 0, -34 }).getInt() == -570425344 How do I get around this yet another of Java's many limitations with…
Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
4
votes
0 answers

Creating a Monix Observable from a NuProcess ByteBuffer

So I have a current project that uses Java Process and I am trying to replace it with NuProcess (i.e. https://github.com/brettwooldridge/NuProcess). For dealing with Java Process's STDOUT/STDERROR you have had an InputStream and since Monix provided…
mdedetrich
  • 1,899
  • 1
  • 18
  • 29
4
votes
4 answers

How to convert a Data Class to ByteBuffer in Kotlin?

I am trying to use Kinesis, which expects data in byte buffer format. All the examples I have seen so far are in Java and pass simple strings. Can anybody give an idea of how to convert a kotlin data class to bytebuffer? e.g. data class abc ( …
N. S. Mehra
  • 45
  • 1
  • 1
  • 5
4
votes
2 answers

Alternatives to ByteBuffers for a low-level UDP messaging system

I'm working on a low-level UDP messaging layer for an encrypted P2P architecture, if interested you can read more about it on its github page. I've built a neat serialization framework that turns POJOs into compact ByteBuffers, and also various…
sanity
  • 35,347
  • 40
  • 135
  • 226
4
votes
1 answer

How do I decompress large files using Zstd-jni and Byte Buffers

I am trying to decompress a lot of 40 MB+ files as I download them in parallel using ByteBuffers and Channels. I am getting better throughput by using Channels than I do by using Streams and we need this to be a very high throughput system as we…
Jay Askren
  • 10,282
  • 14
  • 53
  • 75
4
votes
3 answers

Why doesn't ByteBuffer preserve index for putDouble and getDouble?

I'm having difficulty understanding the semantics of ByteBuffer in the following scenario: int sizeOfDouble = 8; int numberOfDoubles = 4; ByteBuffer testBuf = ByteBuffer.allocateDirect(sizeOfDouble*numberOfDoubles); testBuf.putDouble(0,…
Kirby
  • 3,649
  • 3
  • 26
  • 28
4
votes
0 answers

buffer.clear() or allocate new

I have a java class that writes small messages (< 100 bytes) to a buffer. I have three message types, and so I've allocated 3 buffers. // Cache seprate buffers for each message type Class MyWriter(){ private ByteBuffer loginBuffer =…
Adam Hughes
  • 14,601
  • 12
  • 83
  • 122