X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FJcrUtils.java;h=3e7c8737403ed969378e9c93972508abea85293b;hb=5ec9d72c96b13bf18d702bf01dc2c03b0aee43a4;hp=331164cf2b442dec485bb7a71ebb0d7a0c50dd65;hpb=0d7fc7eb22801c253675c7c11da181ad0f4e5704;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java b/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java index 331164cf2..3e7c87374 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java +++ b/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java @@ -991,16 +991,26 @@ public class JcrUtils { /** Writes a {@link Binary} from a byte array */ public static void setBinaryAsBytes(Node node, String property, byte[] bytes) { - // InputStream in = null; Binary binary = null; try (InputStream in = new ByteArrayInputStream(bytes)) { - // in = new ByteArrayInputStream(bytes); binary = node.getSession().getValueFactory().createBinary(in); node.setProperty(property, binary); } catch (Exception e) { - throw new ArgeoJcrException("Cannot read binary " + property + " as bytes", e); + throw new ArgeoJcrException("Cannot set binary " + property + " as bytes", e); + } finally { + closeQuietly(binary); + } + } + + /** Writes a {@link Binary} from a byte array */ + public static void setBinaryAsBytes(Property prop, byte[] bytes) { + Binary binary = null; + try (InputStream in = new ByteArrayInputStream(bytes)) { + binary = prop.getSession().getValueFactory().createBinary(in); + prop.setValue(binary); + } catch (RepositoryException | IOException e) { + throw new ArgeoJcrException("Cannot set binary " + prop + " as bytes", e); } finally { - // IOUtils.closeQuietly(in); closeQuietly(binary); } }