0

Currently I have a ByteBuffer in the following format:

"[java.nio.HeapByteBuffer[pos=8 lim=140 cap=83620]", which is a String.

I am currently hard-coding a HeapByteBuffer into my Java Code to see if I can extract any information.

How can I read the bytes contained within the HeapByteBuffer, so that I can later parse it into a certain format.

Please help!!

  • Sorry I didn't type it well. The ByteBuffer is in the following format "[java.nio.HeapByteBuffer...]", enclosed in strings. I am not sure how to convert it or hardcode it to a data structure of ByteBuffer. If it is a ByteBuffer, then I can use the BufferedReader method and get() to extract the bytes. – Nitin Seelam Feb 24 '16 at 19:09
  • if you have that string, there is absolutely 100% nothing you can do to get the contents of that `ByteBuffer` out. _No way whatsoever._ That's not a format you can retrieve the information from. – Louis Wasserman Feb 24 '16 at 19:11
  • @Wasserman, is there a way to change its format from a string? Sorry, but I am very new to Java. Currently I have the following line: String data = "[java.nio.HeapByteBuffer[pos=8 lim=144 cap=83626]]"; is there a way to transform "data" into a ByteBuffer? – Nitin Seelam Feb 24 '16 at 19:23
  • That `String` has _no_ information about the bytes that are actually in the buffer; there's no way to recover that information. The only thing you can do is get a better `String` with more information. – Louis Wasserman Feb 24 '16 at 19:24
  • @Wasserman Ok thanks for clarifying. – Nitin Seelam Feb 24 '16 at 19:26
  • I think that `String` is the result of calling the `toString()` method of the buffer. That's not a useful way to interact with an object. For many classes `toString()` is really just a bit of debugging help. You need to use other API. – Persixty Aug 09 '22 at 08:34
  • Does this answer your question? [How to convert "java.nio.HeapByteBuffer" to String](https://stackoverflow.com/questions/26676733/how-to-convert-java-nio-heapbytebuffer-to-string) – Persixty Aug 09 '22 at 08:34

0 Answers0