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
?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.