Kryo register FileInputStream and addDefaultSerializer for InputStream (#471)

HashCheckingStream CordaSerializable and FileInputStream Kryo register
This commit is contained in:
Konstantinos Chalkias
2017-04-06 11:25:49 +01:00
committed by GitHub
parent d6403ce8cb
commit f7dd2733f2
3 changed files with 27 additions and 8 deletions

View File

@ -65,11 +65,12 @@ class NodeAttachmentService(override var storePath: Path, dataSourceProperties:
* inside it, we haven't read the whole file, so we can't check the hash. But when copying it over the network
* this will provide an additional safety check against user error.
*/
private class HashCheckingStream(val expected: SecureHash.SHA256,
val expectedSize: Int,
input: InputStream,
private val counter: CountingInputStream = CountingInputStream(input),
private val stream: HashingInputStream = HashingInputStream(Hashing.sha256(), counter)) : FilterInputStream(stream) {
@VisibleForTesting @CordaSerializable
class HashCheckingStream(val expected: SecureHash.SHA256,
val expectedSize: Int,
input: InputStream,
private val counter: CountingInputStream = CountingInputStream(input),
private val stream: HashingInputStream = HashingInputStream(Hashing.sha256(), counter)) : FilterInputStream(stream) {
override fun close() {
super.close()
@ -86,7 +87,7 @@ class NodeAttachmentService(override var storePath: Path, dataSourceProperties:
private val checkOnLoad: Boolean) : Attachment {
override fun open(): InputStream {
var stream = ByteArrayInputStream(attachment)
val stream = ByteArrayInputStream(attachment)
// This is just an optional safety check. If it slows things down too much it can be disabled.
if (id is SecureHash.SHA256 && checkOnLoad)