- // int capacity = 1024 * 1024;
- // this.toWrite = ByteBuffer.allocate(capacity);
- if (file.isNodeType(NodeType.NT_FILE)) {
- if (file.hasNode(Property.JCR_CONTENT)) {
- Node data = file.getNode(Property.JCR_CONTENT);
- this.binary = data.getProperty(Property.JCR_DATA).getBinary();
- } else {
- Node data = file.addNode(Property.JCR_CONTENT, NodeType.NT_RESOURCE);
- try (InputStream in = new ByteArrayInputStream(new byte[0])) {
- this.binary = data.getSession().getValueFactory().createBinary(in);
+ Session session = file.getSession();
+ synchronized (session) {
+ if (file.isNodeType(NodeType.NT_FILE)) {
+ if (file.hasNode(Node.JCR_CONTENT)) {
+ Node data = file.getNode(Property.JCR_CONTENT);
+ this.binary = data.getProperty(Property.JCR_DATA).getBinary();
+ } else {
+ Node data = file.addNode(Node.JCR_CONTENT, NodeType.NT_UNSTRUCTURED);
+ data.addMixin(NodeType.MIX_LAST_MODIFIED);
+ try (InputStream in = new ByteArrayInputStream(new byte[0])) {
+ this.binary = data.getSession().getValueFactory().createBinary(in);
+ }
+ data.setProperty(Property.JCR_DATA, this.binary);
+
+ // MIME type
+ String mime = Files.probeContentType(path);
+ // String mime = fileTypeMap.getContentType(file.getName());
+ data.setProperty(Property.JCR_MIMETYPE, mime);
+
+ session.refresh(true);
+ session.save();
+ session.notifyAll();