JDK-8279283 excluded two cases from its target optimization: a mark being set, and buffer holding unwritten bytes. This PR resolves the latter one: In case the buffer is holding unwritten bytes, the buffer is first drained into the target stream, before the optimization is called. By doing so, the propability that the optimization actually takes effect is strongly increased, as typically BufferedInputStream will actually hold unwritten bytes in the buffer in most cases. Due to that, this new issue is the actual enabler for the benefit originally proposed by
JDK-8279283.