Here's my code:
Hard to believe that's all of it.
How do I know how big the buffer size should be?
Big enough to hold all the data. Perhaps whatever you are get()ting data from should have a means of telling you that.
The "key" should return an int as a string.
There is a limit to how big an int can be, when represented as a string. Make the array that size.