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
3 answers

Fast ByteBuffer to CharBuffer or char[]

What is the fastest method to convert a java.nio.ByteBuffer a into a (newly created) CharBuffer b or char[] b. By doing this it is important, that a[i] == b[i]. This means, that not a[i] and a[i+1] together make up a value b[j], what getChar(i)…
towi
  • 21,587
  • 28
  • 106
  • 187
5
votes
3 answers

Is Java Native Memory Faster than the heap?

I'm exploring options to help my memory-intensive application, and in doing so I came across Terracotta's BigMemory. From what I gather, they take advantage of non-garbage-collected, off-heap "native memory," and apparently this is about 10x slower…
Michael McGowan
  • 6,528
  • 8
  • 42
  • 70
5
votes
1 answer

Is there a way to gzip a byte buffer in Java?

I have pretty huge DirectByteBuffer and I would like to produce a gzipped DirectByteBuffer from it without transferring its content to the heap. The standard java.util.Deflater cannot be helpful since it operates on byte[] which is on-heap by…
Some Name
  • 8,555
  • 5
  • 27
  • 77
5
votes
3 answers

java.lang.UnsupportedOperationException at java.nio.ByteBuffer.array(ByteBuffer.java:959)

The following Java code compiles, but there's an error at runtime: # javac ByteBufTest.java # java ByteBufTest Exception in thread "main" java.lang.UnsupportedOperationException at java.nio.ByteBuffer.array(ByteBuffer.java:959) at…
zzkjliu
  • 86
  • 1
  • 8
5
votes
2 answers

Why is copyPixelsFromBuffer giving incorrect color? setPixels is correct but slow

For my android app I am getting a ByteBuffer from native code. It contains the pixel color values to create a bitmap. Original image - I used copyPixelsFromBuffer on bitmap, but I am getting incorrect color on displaying the bitmap. Here is the…
Vinayak Garg
  • 6,518
  • 10
  • 53
  • 80
5
votes
2 answers

Sending byte array of approximately fixed size everytime to another method

I have a method which takes a parameter which is Partition enum. This method will be called by multiple background threads (15 max) around same time period by passing different value of partition. Here dataHoldersByPartition is a ImmutableMap of…
user1950349
  • 4,738
  • 19
  • 67
  • 119
5
votes
1 answer

Printing a logo on a Custom TG2480H printer

I'm printing a receipt using the Custom TG2480-H printer. I've got all of the receipt working except for the logo. I've got a monochrome .bmp file that represents the logo and has the right dimenions. I'm retrieving the file, using different…
Robin-Hoodie
  • 4,886
  • 4
  • 30
  • 63
5
votes
3 answers

Android download file out of memory woes

I am trying to download a zip file that is just less than 22 mb on start. I changed the default BufferedInputStream after these exceptions, but still get an out of memory error. public void downloadFromUrl(String fileName) { //avoid…
user375566
5
votes
3 answers

Are the ByteBuffer/IntBuffer/ShortBuffer Java classes fast?

I'm working on an Android application (in Java, obviously) and I recently updated my UDP reader code. In both versions, I set up some buffers and receive a UDP packet: byte[] buf = new byte[10000]; short[] soundData = new…
Rich
  • 4,157
  • 5
  • 33
  • 45
5
votes
2 answers

Java - Convert 16-bit signed pcm audio data array to double array

I'm working on a project involved audio processing. I'm taking a piece of audio from a file, and then would like to do some processing on it. The issue is that I get the audio data as byte array, while my processing is on double array (and later on…
DanielY
  • 1,141
  • 30
  • 58
5
votes
1 answer

How do I getInt from a ByteBuffer with only 1 remaining byte (Java NIO)

I am new to Java NIO and am unsure how to do things nio-ishly. Assume I have read some data from a socket into a ByteBuffer and consumed all bytes but one, using the get methods of ByteBuffer. I know the next thing will be four bytes with an integer…
5
votes
3 answers

Java - ByteBuffer or ArrayList?

Recently I created a wrapper to read and write data into a byte array. To do it, I've been using an ArrayList, but I was wondering if this is the most efficent way to do it, because: addAll() doesn't work with byte arrays (even using…
eric.m
  • 1,577
  • 10
  • 20
5
votes
2 answers

ByteBuffer - compareTo method might diverge

Based on the article here, compareTo method on the ByteBuffers might not work correctly when dealing with negative numbers bytes in Java are signed, contrary to what one typically expects. What is easy to miss though, is the fact that this affects…
Bober02
  • 15,034
  • 31
  • 92
  • 178
5
votes
2 answers

What is the equivalent of Java's ByteBuffer.wrap in C#?

byte[] input = new byte[] {2, 4, 5, 2, 1}; ByteBuffer bytebuf = ByteBuffer.wrap(input); ByteBuffer.wrap(byte[] array) method makes buffer and array are inter-connected, modifications to the buffer will cause the array to be modified and vice…
NoeL
  • 67
  • 1
  • 1
  • 7
5
votes
1 answer

JavaFX DragAndDrop with custom DataFormat

The Overview I am setting up drag & drop in a Java FX application. When I try to grab custom data from the Dragboard I am getting a java.nio.HeapByteBuffer instead of an Object as the JavaDoc stuggest. This byte buffer cannot be cast to my original…
Sean Connolly
  • 5,692
  • 7
  • 37
  • 74