I've already done it for zip in my Java program which was pretty straight forward and thought I'd expand it to cover the other most common format rar as well. But I can't find any information about reading the content of rar files to memory.
Your best bet is using unrar.dll and writing a JNI wrapper. It's possible to do this without going via disk.
Or I guess you could try using JNA to access the DLL directly.
JNI is for pussies, and dear god why do you want to read RAR files?
dicks out for Harambe