Questions tagged [charbuffer]

8 questions
3
votes
3 answers

How exactly CharBuffer equals() method works?

I cannot understand particular details of CharBuffer equals() method functioning. I don't understand this "considered independently of their starting positions" phrase: Two char buffers are equal if, and only if, They have the same element…
Code Complete
  • 3,146
  • 1
  • 15
  • 38
1
vote
1 answer

Java Conversion from byte[] to char[]

I have wrote a simple snippet in which I try to convert (maybe) a byte array in char array e vice versa. There are a lot of examples on the Net but this is for me the simplest way to do it. I need to use array and not strings because its content is…
0
votes
1 answer

CharBuffer to string?

How to get the string "hi" from the CharBuffer? toString() does not seem to work. val a = CharBuffer.allocate(10); a.put('h'); a.put('i'); val b = a.toString(); Variable states after running the code above:
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
0
votes
1 answer

How can we allocate a direct CharBuffer if we don't have any respective (allocateDirect) methods in `CharBuffer` or `Buffer`?

Why do we have isDirect() method in CharBuffer? How can we allocate a direct CharBuffer if we don't have any respective (allocateDirect) methods in CharBuffer or Buffer ? I may guess it is: ByteBuffer.alocateDirect(100).asCharBuffer() Is this so…
user10777718
  • 723
  • 4
  • 16
0
votes
2 answers

What are CharBuffer objects with different "element type" (not equal by definition)?

The equals() method of CharBuffer is quite tricky. From here I got that it makes char-by-char ( or element-by-element ???) comparison of the following block: from (starting) position (returned by position()) inclusive to limit() exclusive. Capacity…
Code Complete
  • 3,146
  • 1
  • 15
  • 38
0
votes
0 answers

CharBuffer and ByteBuffer - charset encoding

Java stores characters in UCS-2 format. byte[] bytes = {0x00, 0x48, 0x00, 0x69, 0x00, 0x2c, 0x60, (byte)0xA8, 0x59, 0x7D, 0x00, 0x21}; // Print UCS-2 in hex codes System.out.printf("%10s", "UCS-2"); for(int i=0;…
overexchange
  • 15,768
  • 30
  • 152
  • 347
0
votes
0 answers

ByteBuffer as CharBuffer

I have the following code. String s="AAAA" ByteBuffer newBuffer = ByteBuffer.allocate(100); CharBuffer cbuf = newBuffer.asCharBuffer(); for (char c : s.toCharArray()) { cbuf.put(c); } When I get the cbuf it's in the form 0 , 65 , 0 , 65 ,…
Hussey123
  • 479
  • 1
  • 5
  • 21
0
votes
1 answer

Java CharBuffer from socket ERROR_FORMAT

Java: 1.7 OS: Linux (but I don't know which Linux it is) I have a CharBuffer to contain something I read from socket's BufferedReader. Socket was established that for sure, and when I'm trying to dump it, it gives me an ERROR_FORMAT result. After…
RRTW
  • 3,160
  • 1
  • 35
  • 54