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.
Encodes text into a sequence of bytes using the named charset and returns the result as a ByteString . static ByteString. copyFrom(java.lang.String text, java.lang.String charsetName) Encodes text into a sequence of bytes using the named charset and returns the result as a ByteString .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With