question: private void writeChunks ( OutputStream outputStream , byte [ ] bytes , int length ) throws IOException { synchronized ( outputStream ) { int chunksize = 8 * 1024 ; for ( int p = 0 ; p < length ; p += chunksize ) { int chunk = p + chunksize < length ? chunksize : length - p ; outputStream . write ( bytes , p , chunk ) ; } } outputStream . flush ( ) ; }
target:  A private function to write things out. This needs to be synchronized as writes can occur from multiple threads. We write in chunks to allow the other side to synchronize for large sized writes.