I uploaded a zip file using the attachment option in Corda and I got a SecureHash as output. Then I tried to download the same zip file using this hash as input to openAttachment method I got a InputStream. I tried to read the contents of this InputStream using BufferReader but I could not because it is encrypted. I got the "import java.util.zip.ZipEntry" package to read the zip file content but didn’t work. How can I read the contents of the zip file?
The code is as follows:
fun main(args: Array<String>) :String {
require(args.isNotEmpty()) { "Usage: uploadBlacklist <node address>" }
args.forEach { arg ->
val nodeAddress = parse(args[0])
val rpcConnection = CordaRPCClient(nodeAddress).start("user1", "test")
val proxy = rpcConnection.proxy
val attachmentInputStream = File(args[1]).inputStream()
val attachmentHash = proxy.uploadAttachment(attachmentInputStream)
print("AtachmentHash"+attachmentHash)
// Download the attachment
val inputString = proxy.openAttachment(attachmentHash).bufferedReader().use { it.readText() }
println("The contents are ")
print(inputString)
val file = File("OutputFile.txt")
file.writeText(inputString)
rpcConnection.notifyServerAndClose()
}
return("File downloaded successfully in the path")
}