Hmmm . . . this is sure ugly. One potential pitfall is that you're now adjusting the write window even if it's a deeper layer throwing this exception. For example, the TLS layer can throw InterruptedIOExceptions and in that case we don't want to adjust windows like this. We really don't know how many bytes have been written.