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
4
votes
1 answer

converting numbers (short, int, long, float, double,bigint) to byte array: Scala/Java

I've following scala code to convert (short, int, long, float, double,bigint) to byte array. def getByteArray(value: Any, of_type: String) = { of_type match { case "short" =>…
codehammer
  • 876
  • 2
  • 10
  • 27
4
votes
4 answers

From ByteBuffer to double array

I have a ByteBuffer containing three double values, e.g. {1.0, 2.0, 3.0}. What I have now is double[] a = new double[3]; for (int i = 0; i < 3; i++) { a[i] = byteBuffer.getDouble(); } which works fine, but I would prefer a one-step solution via…
Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
4
votes
1 answer

Java: Size limitation on direct IntBuffer?

I want to allocate a direct IntBuffer in Java with, say, a billion elements (64-bit system). The only way I know of is creating a direct ByteBuffer and viewing it as a direct IntBuffer. However, 4*1,000,000,000 exceeds Integer.MAX_VALUE, so my…
Flowi
  • 45
  • 4
4
votes
1 answer

concatenate two byteBuffers to a single

Hi I've 2 byteBuffers and I want to concatenate them together to a single byteBuffer. I found a similar question here but none of the suggestions there worked for me.
davidmoshko
  • 223
  • 1
  • 4
  • 8
4
votes
1 answer

How to find out total number of bytes stored in ByteBuffer?

I am trying to extract total number of bytes I have stored in my ByteBuffer data_record_value. Below is how we representdata_record_value as one Byte Array and then write to our database from Java code. Offset Length (in bytes) Purpose 0…
john
  • 11,311
  • 40
  • 131
  • 251
4
votes
2 answers

How to obtain used byte[] from ByteBuffer

The java.nio.ByteBuffer class has a ByteBuffer.array() method, however this returns an array that is the size of the buffer's capacity, and not the used capacity. Due to this, I'm having quite a bit of issues. I've noticed that using…
Hobbyist
  • 15,888
  • 9
  • 46
  • 98
4
votes
1 answer

Which JVMs do not support direct java.nio.ByteBuffer?

The release notes for Java NIO (in Java 1.4+) state that support for direct ByteBuffers is an optional feature. I am curious which JVM vendors/flavors do not support it? Should a JNI library always code for managed ByteBuffers and relegate direct…
Joe Holloway
  • 28,320
  • 15
  • 82
  • 92
4
votes
2 answers

What is the difference between rewind() and clear() of class ByteBuffer?

Note that in JDK document's words rewind() and clear() looks alike for "cleaning" the ByteBuffer. Actually the old data exists, furthermore rewind() should be used before channel-write or get operation and clear() corresponds to channel-read or put…
liujyg
  • 41
  • 1
  • 3
4
votes
2 answers

Why do bytebuffer give buffer overflow exception when buffer is not full

I'm not sure why the following example gives buffer overflow exception. Hope someone can explain why, and how i can do it correctly. It's as simple as this: ByteBuffer bf =…
Ikky
  • 2,826
  • 14
  • 47
  • 68
4
votes
2 answers

ByteBuffer underflow

I try to use the java libary ByteBuffer and wrote following code example: ByteBuffer buf = ByteBuffer.allocate(32); buf.putInt(4); buf.putInt(8); buf.putInt(12); buf.putInt(16); buf.putInt(20); buf.putInt(24); …
Crigges
  • 1,083
  • 2
  • 15
  • 28
4
votes
5 answers

How to extend the allocated memory of a bytebuffer

I have a bytebuffer and I put Ints,Chars etc.. Because I do not know how much space I need I would like to dynamically growth the bytebuffer. How can this be done ? Example : - I have a Bytebuffer of 2 bytes - I add a character to the bytebuffer…
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
4
votes
2 answers

Java: Using type punning on primitive arrays?

I need to be able to convert byte arrays to/from other primitive type arrays, but instead of casting, I need type punning. Correct term for raw copy without casting? I thought it would be possible to do the following: // idea: byte[12] -> int[3],…
java.is.for.desktop
  • 10,748
  • 12
  • 69
  • 103
4
votes
1 answer

Read/write /proc//mem from java code on Android platform

I want to read and write memory from ptaced child process (/proc/pid/mem) on Android. Before read/write i attached to process using ptrace (Status=4991, WIFSTOPPED(Status)=true). int lSize = (int) (pAddressEnd - pAddressStart); ByteBuffer…
Aleksandr
  • 1,303
  • 2
  • 11
  • 19
4
votes
4 answers

Java ArrayList consecutive memory allocation only for references?

I want to allocate an arraylist of primitive datatype objects like int,char etc (not array because it's going to grow in future may be not linearly) but required to be stored at consecutive memory locations in RAM (jvm managed heap). But since when…
Dhwanit
  • 610
  • 1
  • 9
  • 17
4
votes
1 answer

Java - ByteBuffer.remaining() problems

Summary: I have a ByteBuffer in which I am pumping some data. After that, I want to send this data over a Socket. So, I wrote code like this: private static void serialize(ByteBuffer buffer, EmployeeData emp, CharsetEncoder encoder) { // id …
feroze
  • 7,380
  • 7
  • 40
  • 57