ojluni: solve issues with exceptions in cipher-related streams

Port from
http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/8402ef8fabde

Incorrect handling of exceptions and closed ciphers can
result in problems with authentication.
See
http://bugs.java.com/view_bug.do?bug_id=7160837

- CipherOutputStream: when closing, avoid calling doFinal on the
cipher (again) if the stream was already closed

- DigestOutputStream: write to stream before updating the digest

Note: CipherInputStream has been already updated in
https://android-review.googlesource.com/#/c/249160/

Bug: 29631070
Test: vogar DigestOutputStream CipherOutputStream
Change-Id: If4884d1ece21cfcb46e085a08b0910ee8b6cb2d3
4 files changed