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
7
votes
4 answers

How to serialize ByteBuffer

I wish to send a java.nio.ByteBuffer accross a network using RMI, however ByteBuffer isn't serializable. I've tried the following custom class to no avail: public class NetByteBuffer implements java.io.Serializable { ByteBuffer buffer; public…
jtnire
  • 1,348
  • 5
  • 21
  • 32
7
votes
4 answers

Extract Longs from ByteBuffer (Java/Scala)

I'm constructing BigInt numbers that consist of two Longs each in the following way: val msb = -1L // some arbitrary long value, can be anything between Long.Min/MaxValue val lsb = 25L // a second arbitrary long value val bb = ByteBuffer …
ceran
  • 1,392
  • 1
  • 17
  • 43
7
votes
2 answers

Java's ByteBuffer nearest counterpart in C#?

Currently looking to interface a Java and a C# application. In Java I can use getShort(), getFloat() etc, to get various different data types from the buffer. In C# I am using a MemoryStream, but there is only a single get() function. Does anybody…
Verlix
  • 71
  • 4
7
votes
3 answers

Is it possible to read the Process stdout InputStream into an NIO ByteBuffer?

Is it possible to use NIO to process the stdout from a Process? I have it working with java.io, but this is something of an exercise to learn a bit more about NIO and to explore the possibility of performance improvements. Basically I want to…
Rob
  • 5,512
  • 10
  • 41
  • 45
6
votes
1 answer

Hadoop Throws ClassCastException for the keytype of java.nio.ByteBuffer

I am using "hadoop-0.20.203.0rc1.tar.gz" for my cluster setup. Whenever I set job.setMapOutputKeyClass(ByteBuffer.class); and run the job I get following Exception: 12/01/13 15:09:00 INFO mapred.JobClient: Task Id :…
samarth
  • 3,866
  • 7
  • 45
  • 60
6
votes
4 answers

Prevent OutOfMemory when using java.nio.MappedByteBuffer

Consider application, which create 5-6 threads, each thread in cycle allocate MappedByteBuffer for 5mb page size. MappedByteBuffer b = ch.map(FileChannel.MapMode.READ_ONLY, r, 1024*1024*5); Sooner or later, when application works with big files,…
user12384512
  • 3,362
  • 10
  • 61
  • 97
6
votes
4 answers

How can I determine the length of received bytes of UsbRequest.queue(..) method?

I have troubles with UsbRequest class in Android 3.1. This is my code: ByteBuffer buffer = ByteBuffer.allocate(4096); buffer.order(ByteOrder.LITTLE_ENDIAN); UsbRequest request = new UsbRequest(); request.initialize(mConnection,…
Slava
  • 96
  • 1
  • 3
6
votes
1 answer

Fast copy ByteBuffer into ByteBuffer in Dart

How do I perform a fast copy of the bytes of a ByteBuffer into another larger ByteBuffer (at non-zero offset) in Dart? There are slow ways to do this. One is to cast each to a Uint8List and copy over one index at a time. Another is to cast into each…
Joe Lapp
  • 2,435
  • 3
  • 30
  • 42
6
votes
1 answer

Why does DirectByteBuffer.array() have extra size?

My code is: if (frameRGBABuffer == null) { frameRGBABuffer = ByteBuffer.allocateDirect(cameraHeight * cameraWidth * 4) .order(ByteOrder.nativeOrder()); } Log.d("tag",frameRGBABuffer.array().length) My camera resolution is 1280×720,…
zccneil
  • 139
  • 11
6
votes
2 answers

How to extract used byte array 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 some issues. I have a ByteBuffer which I am allocating as some…
flash
  • 1,455
  • 11
  • 61
  • 132
6
votes
0 answers

Android MediaExtractor / MediaCodec Native Crash

I have developed a simple audio player in Android that, among others, plays .mp3-files. To decode the files I am using the Android MediaExtractor and the Android MediaCodec. The sample code looks as follows: int inIndex =…
6
votes
2 answers

What is difference between getXXXVolatile vs getXXX in java unsafe?

I am trying to understand the two methods here in java unsafe: public native short getShortVolatile(Object var1, long var2); vs public native short getShort(Object var1, long var2); What is the real difference here? What does volatile here…
Lubor
  • 989
  • 3
  • 10
  • 33
6
votes
1 answer

Java ByteBuffer BigEndian Double

When I try to write in a file a binary files with value like this : public static main(String[] args){ ByteBuffer output = ByteBuffer.allocate(80); output.order(ByteOrder.BIG_ENDIAN); output.putDouble(545.5); …
H. Saoud
  • 63
  • 5
6
votes
2 answers

Pack header and data layout in one byte array using ByteBuffer in an efficient way?

I have a header and data which I need to represent in one Byte Array. And I have a particular format for packing the header in a Byte Array and also a different format to pack the data in a Byte Array. After I have these two, I need to make one…
john
  • 11,311
  • 40
  • 131
  • 251
6
votes
4 answers

How Java GC Does Direct Byte Buffer Clean Up, Because IBM Docs says, It Does.

I assumed, I understood how Bytebuffer and DirectByteBuffer differs until i read a artical on IBM documentation, metioning : "Direct ByteBuffer objects clean up their native buffers automatically but can only do so as part of Java heap…
Ankush G
  • 989
  • 9
  • 14