FileChannel implements InterruptibleChannel, help or hindrance?
Alan Bateman
Alan.Bateman at oracle.com
Mon Mar 5 15:25:34 UTC 2018
On 05/03/2018 15:15, David Lloyd wrote:
> :
> In all cases, exceptionless partial reads are a perfectly
> safe/acceptable outcome for interruption. In fact if the API were
> being designed from scratch today, I might even argue that a
> zero-bytes read/write would be the preferred behavior when operations
> are entered in an interrupted state. Either way I don't see how
> anything in the API (as I've proposed it) could possibly lead to data
> loss. AFAICT the biggest API risk is the use of bytesTransferred in
> InterruptedIOException, which in retrospect was probably not a great
> idea.
Switch your example to writing and wrap it in an API (such as
OutputStream) that does not tolerate short writes and you'll start to
see some of the issues. Reading is problematic too btw, esp. if you
throw an exception after reading bytes.
-Alan
More information about the nio-dev
mailing list