1

I'm trying to get a KeyStore from PrimeFaces UploadFile, but this only returns a byte[]. How can I convert it back to a KeyStore?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

6

Look closer at the KeyStore javadoc. Next to the store() method taking an OutputStream, which you learnt in your previous question, there's also a load() method taking an InputStream.

The PrimeFaces UploadedFile has according the javadoc next to the getContents() method returning a byte[] also a getInputStream() method returning an InputStream.

So, all with all, this should do:

try (InputStream inputStream = uploadedFile.getInputStream()) {
    keyStore.load(inputStream, password);
}

Lesson learnt: learn how to find and interpret the javadocs and do the math :)

By the way, if you would have had really no way to get an InputStream at hands, but only a byte[], then you could always have wrapped it in an ByteArrayInputStream.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555