What is the correct way to read the input stream into a node property in JCR 2?

In JCR 1 you can do:

final InputStream in = zip.getInputStream(zip.getEntry(zipEntryName)); node.setProperty(JcrConstants.JCR_CONTENT, in); 

But this is deprecated in JCR 2, as described in http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setProperty%28java.lang.String,%20java.io .InputStream% 29

This says that I should use node.setProperty(String, Binary) , but I see no way to turn my input stream into a binary file. Can someone point me to a document or sample code for this?

+4
source share
2 answers
 ValueFactory.createBinary(InputStream stream) 

You get ValueFactory through the session returned by Repository.login ()

+7
source

Just a hint after Rob's answer, if you are wondering where to get the ValueFactory , you can use:

 node.getSession().getValueFactory().createBinary(inputStream) 
+2
source

Source: https://habr.com/ru/post/1305881/


All Articles