Issue
Could anyone please let me know how to convert protobuf's ByteString to an octal escape sequence String in java?
In my case, I am getting the ByteString value as \376\024\367
so, when I print the string value in console using System.out.println()
, I should get "\376\024\367"
.
Many thanks.
Solution
Normally, you'd convert a ByteString to a String using ByteString#toString(Charset)
. This method lets you specify what charset the text is encoded in. If it's UTF-8, you can also use the method toStringUtf8()
as a shortcut.
From your question, though, it sounds like you actually want to produce the escaped format using C-style three-digit octal escapes. AFAIK there's no public function to do this, but you can see the code here. You could copy that code into your own project and use it.
Answered By - Kenton Varda
Answer Checked By - Gilberto Lyons (JavaFixing Admin)