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

Delphi XE byte array index

I use simple circular buffer like this var Values: array [byte] of single; ptr: byte; In this test example for ptr:=0 to 10 do Values[Byte(ptr-5)]:=1; I expect to have set to 1 first 5 values and last 5 values, but XE4 compiller produce…
Michael Gendelev
  • 471
  • 4
  • 16
6
votes
2 answers

Read bytes from Java NIO socketchannel until marker is reached

I´m searching for an efficient way to read bytes from a socket channel using Java NIO. The task is quite easy, I have a solution, though I´m searching for a cleaner and more efficient way to solve this. Here´s the scenario: Data is read from a…
Patze
  • 297
  • 2
  • 13
6
votes
2 answers

Converting BufferedImage to ByteBuffer

I'm trying to convert a Buffered image into a ByteBuffer but i get this exception java.awt.image.DataBufferInt cannot be cast to java.awt.image.DataBufferByte can someone please help me out and suggest a good method of conversion. Source: public…
Sumal Perera
  • 297
  • 1
  • 3
  • 6
6
votes
2 answers

Spring data Cassandra 2.0 Select BLOB column returns incorrect ByteBuffer data

Context: Spring data cassandra official 1.0.2.RELEASE from Maven Central repo, CQL3, cassandra 2.0, datastax driver 2.0.4 Background: The cassandra blob data type is mapped to a Java ByteBuffer. The sample code below demonstrates that you won't…
Bernard Hauzeur
  • 2,317
  • 1
  • 18
  • 25
6
votes
3 answers

ByteBuffer, what is a clean way to detect if it needs to be flipped

Is there a clean sure fire way to detect if a ByteBuffer needs flipping? I have a ByteBuffer that is used for packing and unpacking a data stucture and also for storage of bytes to be packed / unpacked. However, if a write operation has just been…
JeffV
  • 52,985
  • 32
  • 103
  • 124
6
votes
1 answer

How to use Wrap Method of ByteBuffer in Java

Okay, so I was looking up what the best way to convert from a byte array to it's numeric value in java was and I came across this link. And the second answer mentions the use of the ByteBuffer class. For those that do not wish to click on the link,…
This 0ne Pr0grammer
  • 2,632
  • 14
  • 57
  • 81
6
votes
1 answer

Java MappedByteBuffer.isLoaded()

It seems to me that MappedByteBuffer.isLoaded() consistently returns false on Windows. When I test on say BSD Unix I get true using the same test data. Should I worry? I basically cannot get isLoaded()to return true on Windows no matter what size…
peterh
  • 18,404
  • 12
  • 87
  • 115
6
votes
4 answers

Java NIO MappedByteBuffer OutOfMemoryException

I am really in trouble: I want to read HUGE files over several GB using FileChannels and MappedByteBuffers - all the documentation I found implies it's rather simple to map a file using the FileChannel.map() method. Of course there is a limit at 2GB…
Zordid
  • 10,451
  • 11
  • 42
  • 58
6
votes
4 answers

why are ByteBuffers hashCodes the same?

I have a class constructor like this: public JavoImageCorrectedDataHeader() { ByteBuffer buffer = ByteBuffer.allocate(this.size()); buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN); setByteBuffer(buffer, 0); …
5YrsLaterDBA
  • 33,370
  • 43
  • 136
  • 210
6
votes
1 answer

How comes .array() doesn't work on ByteBuffers returned from map'ed FileChannels?

I'm doing memory-mapped IO in Java. The FileChannel class allows you to map a ByteBuffer to a particular part of a file. I'm doing that with a file opened read only. The problem I am having is that I'm getting an exception when I attempt to call…
vy32
  • 28,461
  • 37
  • 122
  • 246
5
votes
2 answers

Java Read File Larger than 2 GB (Using Chunking)

I'm implementing a file transfer server, and I've run into an issue with sending a file larger than 2 GB over the network. The issue starts when I get the File I want to work with and try to read its contents into a byte[]. I have a for loop…
Eliezer
  • 7,209
  • 12
  • 56
  • 103
5
votes
1 answer

How to make ByteBuffer as efficient as direct byte[] access after JIT has warmed up?

I am trying to optimize a simple decompression routine, and came across this weird performance quirk that I can't seem to find much information on: Manually implemented trivial byte buffers are 10%-20% faster than the built in byte buffers (heap &…
byteit101
  • 3,910
  • 2
  • 20
  • 29
5
votes
1 answer

What's the space-efficient way to read multiple ByteBuffers into a single String?

I'm writing a decoder that will receive a sequence of byte buffers and decode the contents into a single String. There can be any number of byte buffers, each containing any number of bytes. The buffers aren't necessarily split on character…
Sam
  • 8,330
  • 2
  • 26
  • 51
5
votes
2 answers

How do you get successive slices out of a ByteBuffer?

I have a ByteBuffer that contains a large file (100 MB): java.nio.ByteBuffer byteBuffer = ByteBuffer.wrap(multipartFile.getBytes()); writeChannel.write(byteBuffer); writeChannel.closeFinally(); I can only legally write 1 MB to the…
Percy
  • 129
  • 4
  • 8
5
votes
1 answer

How to use java.nio.channels.FileChannel to read to ByteBuffer achieve similiar behavior like BufferedReader#readLine()

I want to use java.nio.channels.FileChannel to read from a file, but I want to read line per line like BufferedReader#readLine() does. The reason why I need to use java.nio.channels.FileChannel instead of java.io is because I need to put a lock on a…
Thang Pham
  • 38,125
  • 75
  • 201
  • 285