My philosophy here is simple: we do all the socket job in native code and hold native buffer as a link in java code (long number). I take data from the native buffer only when I need it cause memory copying is an expensive operation.

And I try to avoid using Java arrays cause they are significantly slower then native ones.

And about protection… I forgot about making Socket class thread-safe, thank you. Actually, I think I should simply <code>synchronize</code> reading and writing methods with the streams in order to avoid simultaneous calls. What do you think?