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

ByteBuffer.flip() Issue

I have a class as follows: final ByteBuffer data; 1st_constructor(arg1, arg2, arg3){ data = ByteBuffer.allocate(8); // Use "put" method to add values to the ByteBuffer //.... eg: 2 ints //.... …
user2268507
0
votes
1 answer

Assign ByteBuffer to Byte[] Error

I have a class as follows: final ByteBuffer data; 1st_constructor(arg1, arg2, arg3){ data = ByteBuffer.allocate(8); // Use "put" method to add values to the ByteBuffer //.... eg: 2 ints //.... } 1st_constructor(arg1, arg2){ …
user2268507
0
votes
0 answers

1-byte-long ByteBuffer allocate or allocateDirect

I'm writing a library for reading/writing bits from/to Streams/Channels. When working with Channels I use 1-byte-long ByteBuffer. Here comes how to read/write with those ByteBuffer. //@Override // commented for pre 5 public int readUnsignedByte()…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
0
votes
2 answers

Writing data to file is erasing everything before it(Placing 00's) and changing the file size

I have a program which writes out some data- I am using this logic FileOutputStream outpre = new FileOutputStream(getfile()); FileChannel ch = outpre.getChannel(); ch.position(startwr); ch.write(ByteBuffer.wrap(dsave)); outpre.close(); It writes…
0
votes
1 answer

Record MIC sound into byte array in android

I'm trying to record from the MIC direcly to a short array. The goal is not to write a file with the audio track, just save it within a short array. If've tried several methods and the best I've found is recording with AudioRecord and to play it…
josecash
  • 339
  • 4
  • 19
0
votes
1 answer

NIO byte Buffer has empty bytes when ready to read

I am writing an NIO server, right now to test I am connecting to myself, i have it written to where the client sends a handshake protocol and the server has to respond but when i try to read the handshake all i get are empty bytes from the byte…
sola
  • 149
  • 1
  • 2
  • 12
0
votes
1 answer

Java nio partial read

My goal is to send different kind of messages from client to server, and it will be text based. The thing I am uncertain of is how to del with partial reads here. I will have to be sure that I get a whole message and nothing more. Do anyone have…
olemara
  • 9
  • 2
0
votes
1 answer

Convert YBR_Full image to RGB in java

I could get the array of byte contains the YUV values and perform the same method in( Confusion on YUV NV21 conversion to RGB ) on it to get the array of int value represent RGB,and then i tried to convert this array to ByteBuffer so i can view it…
java_87
  • 5
  • 6
0
votes
0 answers

Pass XML Marshalled data into a ByteBuffer

For a current project, I need to write XML data into a ByteBuffer to write the output XML in a binary format (.dat for example). Is there a lib or class that will, for each java objects corresponding to the elements of my xml, write the value of its…
Viria
  • 47
  • 5
0
votes
1 answer

Export ByteBuffer as Little Endian File in Java

I want to Export a ByteBuffer as Little Endian into a file, but when I read in the file again I have to read it as Big Endian to get the right values. How can I export a ByteBuffer in a way that I can read in the created file as Little Endian and…
Ephisray
  • 3
  • 5
0
votes
3 answers

Cannot extract correct information from message received through SocketChannel

I am sending a string which has been converted into bytes using a DataOutput stream // creates a client socket which connects to the first successor's server. Socket clientSocket = new Socket(host, succ1_port); // send the output_string to the…
user2268507
0
votes
1 answer

Is ByteBuffer.getInt() blocking?

I'm willing to use a ByteBuffer to inter thread communication of JNI and C++. I couldn't find in the documentation whether ByteBuffer's getInt() is blocking or not. So, do I need to do something like: if(byteBuffer.asIntBuffer().hasRemaining()) …
quimnuss
  • 1,503
  • 2
  • 17
  • 37
0
votes
1 answer

Bytebuffer in Java

I send long number via UDP. LinkedQueue Q = new LinkedQueue(); while (this._run) { udp_socket.receive(packet); if (packet.getLength() > 0) { ByteBuffer bb = ByteBuffer.wrap(buf, 0, packet.getLength()); …
Anh Tuan
  • 1
  • 1
0
votes
1 answer

Write DataOutputStream in ByteArray / ByteBuffer with "dynamic" size?

i ask myself if there is a nice solution for receiving data via TCP and reading the data in a DataInputStream and store the data in a bytearray of "dynamic" size. I thought about some solutions like writing in buffers and finally store it in a…
Chris Jung
  • 49
  • 1
  • 6
0
votes
1 answer

NIO and visibility of ByteBuffers across threads

It seems that in implementing servers that rely on java nio, the following practice is standard: Use a single thread (and a single selector) for reads: ByteBuffer buffer = . . . selector.select() ... channel.read(buffer) if…
igaz
  • 392
  • 3
  • 9