Я загрузил файл JAR и нашел его хэш. Теперь попытался скачать файл, указав его хеш. При запуске следующий код получил вывод: -
банка: (blacklist.txt, [B @ 35f9985c).
Что мы можем вывести из вывода. Как посмотреть скачанный файл?
@PUT
@Path("download_file")
fun createIOU(
@QueryParam("sechash") sechash: String
): Response {
val SecuHash = SecureHash.parse(sechash)
return try {
val attachmentJr = downloadAttachment(rpcOps, SecuHash)
println("jar :"+attachmentJr)
Response.status(CREATED).entity("Transaction id ${attachmentJr} committed to ledger.\n").build()
} catch (ex: Throwable) {
logger.error(ex.message, ex)
Response.status(BAD_REQUEST).entity(ex.message!!).build()
}
}
private fun downloadAttachment(proxy: CordaRPCOps, attachmentHash: SecureHash): Pair<String, ByteArray>? {
//Get the attachmentJar from node for attachmentHash.
val attachmentJar = proxy.openAttachment(attachmentHash)
//Read the content of Jar to get file name and data.
var file_name_data: Pair<String, ByteArray>? = null
JarInputStream(attachmentJar).use { jar ->
while (true) {
val nje = jar.nextEntry ?: break
if (nje.isDirectory) {
continue
}
file_name_data = Pair(nje.name, jar.readBytes())
}
}
return file_name_data
}
Получил вывод как:
![enter image description here](https://i.stack.imgur.com/8swxv.png)