Q:

How to download a jar file in corda? 

I have uploaded a jar file in a node. 
How to download the attachment. 
While downloading the attachment, will I get the attachment in jar file itself?  There will be a download button in UI, on clicking the attachment need to download.  In UI, I will provide hash of the file. 

A:

You use the CordaRPCOps.openAttachment() method.  It takes as input the hash of the attachment, and returns an InputStream of the attachment JAR. 
Here's a simple endpoint to download an attachment as an input stream:
@GET
@Path("download-attachment")
fun downloadAttachment(@QueryParam("attachment_hash") attachmentHash: String): InputStream {
    val secureHash = SecureHash.parse(attachmentHash)
    return rpcOps.openAttachment(secureHash)
}

You then need to write out the input stream as a JAR file.  Here's a simple helper function to do that:
fun downloadJar(url: String) {
    val inputStream = URL(url).openStream()

    BufferedReader(InputStreamReader(inputStream)).use {
        File("./downloaded_jar.jar").outputStream().use { outputStream ->
            inputStream.copyTo(outputStream)
        }
    }
}

