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
0
votes
2 answers

Java NIO. Why flip() method breaks my program?

Java code below: import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Test { public static void main(String args[]) throws IOException { …
user471011
  • 7,104
  • 17
  • 69
  • 97
0
votes
1 answer

How to load a random access or memory mapped file hosted online from an applet

I have a Processing script in which I'm plotting a small subset of data from a very large file that is constantly being updated. The data will be randomly accessed based on user input, and so to increase speed without loading the whole file into…
0
votes
1 answer

Java NIO ByteBuffer : read the message size on head before read the complete message

I'm making a java NIO server which receive messages, each message have its size on the head of the message, that why I'm reading first into a buffer which have default size(44), then get the complete size from this buffer, and then create a new…
Fozix
  • 133
  • 3
  • 12
0
votes
2 answers

Sending data over TCP

I have a client server situation, where the client sends the data (a movie for example) to the server, the server saves that data to the HDD. It sends the data by a fixed array of bytes. After the bytes are sent, the server asks if there is more, if…
Jorne De Blaere
  • 39
  • 2
  • 14
0
votes
2 answers

How to append one ByteBuffer to other?

Suppose that I have 2 ByteBuffer containing some bytes in it... How would be the best way to append all the content of one ByteBuffer with other? I'm doing this but it throws a BufferUnderFlowException: ByteBuffer allData =…
mevqz
  • 653
  • 3
  • 9
  • 19
0
votes
1 answer

Java ByteBuffer "put" method - preventing buffer overflow

I want to use the put method of the java nio ByteBuffer in the following way: ByteBuffer small = ByteBuffer.allocate(SMALL_AMOUNT_OF_BYTES); ByteBuffer big = getAllData(); while (big.hasRemaining()){ small.put(big); send(small); } the…
bennyl
  • 2,886
  • 2
  • 29
  • 43
0
votes
1 answer

what if we exceed the capacity of allocating buffer in ByteBuffer.allocate(48) NIO package class in java

file = new RandomAccessFile("xanadu.txt", "rw"); FileChannel channel = file.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(48); int byteReads = channel.read(buffer); SO I am allocating 48 as a capacity in the Buffer.…
Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128
0
votes
1 answer

MappedByteBuffer byte orders reversed?

I have a java.nio.MappedByteBuffer that I am using to read integers from a little-endian file. I set the byte order to LITTLE_ENDIAN using ByteBuffer.order(), but this causes the buffer to interpret integers as if they were big endian. Confirm that…
Clark
  • 890
  • 8
  • 20
0
votes
1 answer

Android jni datatype losing precision (ByteBuffer, int)

What am I doing: I add four integers in C. on the way, I lose information. See code below: //c-file jbyte *inputByteArray = (*env)->GetDirectBufferAddress (env, obj); // checked every value, also sizeof(val1)= 4 etc... int val1 = (int)…
mojjj
  • 625
  • 8
  • 18
0
votes
2 answers

Java bytebuffer to C

From a C program on Windows we need to read and write like a Java bytebuffer which stores binary in BIG_ENDIAN The algorithm is described at : http://mindprod.com/jgloss/binaryformats.html Need to read and write int and float. Does anyone have…
Bert
-1
votes
1 answer

First byte is suddenly zeroed while converting to CString

I want to do FFI call. To do so i need to convert a Rust string into C-zero-terminated-string in a proper encoding. I wrote this code but somehow it replaces first byte with zero. Why this happen? How do I fix this? use…
osseum
  • 187
  • 14
-1
votes
3 answers

Is it possible to convert strongly-typed data to bytes using the ByteBuffer class?

Is it possible to convert strongly-typed data to bytes using the ByteBuffer class? If not, what is its main purpose? If yes, I am looking at its documentation and can find nothing. The put methods require a byte and not an int fro example.
darksky
  • 20,411
  • 61
  • 165
  • 254
-1
votes
1 answer

ImageIo reading from byte data results in "Empty region!"

I have two services which trade binary data from an original heic/heif image via redis (binary safe). Since ImageIo does not support that image type I built a separate service in nodejs, which just converts heic/heif images to jpegs. After…
-1
votes
1 answer

ByteBuffer discards trailing newline

Here is how I put a string to ByteBuffer String message="Hello\n\n"; ByteBuffer bresult = ByteBuffer.allocate(message.getBytes().length); bresult.put(message.getBytes()); bresult.flip(); When I convert bytebuffer to string to see the result \n\n is…
-1
votes
1 answer

How to use []byte as a buffer in registry.GetValue?

The documentation in the registry package for GetValue() says : GetValue retrieves the type and data for the specified value associated with an open key k. It fills up buffer buf and returns the retrieved byte count n. If buf is too small to fit…
WarBro
  • 305
  • 2
  • 10