Skip to content

Instantly share code, notes, and snippets.

@asnare
Created November 20, 2017 16:52
Show Gist options
  • Save asnare/2a14f5a7ab751f8783c72121c64785df to your computer and use it in GitHub Desktop.
Save asnare/2a14f5a7ab751f8783c72121c64785df to your computer and use it in GitHub Desktop.
def bufferToString(input: ByteBuffer, charset: Charset): String =
if (input.hasArray)
new String(input.array(), input.arrayOffset(), input.limit(), charset)
else
bufferToString(ByteBuffer.allocate(input.limit())
.put(input)
.flip().asInstanceOf[ByteBuffer], charset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment