I believe CipherInputStream might help you. It functions just like a normal InputStream object but also applies a Cipher (either encryption or decryption). If you want to read a file in non-plain text, write the file with a CipherOutputStream, then read it normally like any other file with a CipherInputStream on the other end.
If your file is already encrypted, which it sound like it is, you'd only need the CipherInputStream initialized to whatever encryption method was used to create the native code.
FileInputStream in = new FileInputStream("YOUR DIRECTORY");
Cipher decryptionCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, createKey(password));
CipherInputStream ciphIn = new CipherInputtStream(in, decryptionCipher);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8];
int i = in.read(buffer);
while (i != -1)
{
//just like a file copy
out.write(buffer, 0, i)
i = in.read(buffer);
}
/*
* YOUR NATIVE DATA UNENCRYPTED
*/
byte[] nativeFileData = out.toByteArray();
ciphIn.close();
in.close();
The create key method:
public SecretKey createKey(String password) throws NoSuchAlgorithmException, InvalidKeySpecException
{
//hash the password
MessageDigest msgDigest = MessageDigest.getInstance("SHA-1");
msgDigest.update(key);
byte[] hash = msgDigest.digest();
byte[] salt = new byte[8]{};
new SecureRandom(hash).nextBytes(salt);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec keySpec = new PBEKeySpec(hash, salt, 65536, 128);
SecretKey tmp = factory.generateSecret(keySpec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
return secret;
}
You would now have a byte array containing your native unencrypted bytes. So now you could run this (assuming its like an exe or something) using a JNI/JNA class. It is possible to load native code into memory. That memory is then allocated as executable and you can run it as assembly instructions by using a native system call. There's is already a stack overflow article about doing this located here. It will be up to you to implement it in JNI format.
In terms of opening a PDF/DOCS file, you're talking about reading a proprietary file format, using a proprietary program who's system call interface you know nothing about. I am also confused as to why the user can open these files and view the content but they cant have access to the file. If you could clarify that would be great. What you could do is take this byte array and use a library to render the pdf to png images, then use javafx to display the images.
I know this answer isn't spot on but I hope it helps or at least points you in the right direction.
Cheers.