jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From garihood <garih...@flambeau.com>
Subject Re: AW: Learning Jackrabbit - Extracted files are length zero
Date Mon, 22 Apr 2013 16:05:15 GMT
Thanks for the reply.

I've created an InputStream variable:
   InputStream input = new FileInputStream(file);

and replaced my old code:
   resNode.setProperty("jcr:data", new FileInputStream(file));

with your suggestion:
   resNode.setProperty(JcrConstants.JCR_DATA,
                     
resNode.getSession().getValueFactory().createBinary(input));

Unfortunately, the files I try to extract remain 0 bytes long.



This is the current importFile() method:

    public static void importFile(Node parentnode,
                                  File file) throws RepositoryException,
                                                    IOException {
        InputStream input = new FileInputStream(file);

        MimeTable mt = MimeTable.getDefaultTable();
        String mimeType = mt.getContentTypeFor(file.getName());
        if (mimeType == null)
            mimeType = "application/octet-stream";

        Node fileNode = parentnode.addNode(file.getName(), "nt:file");
        Node resNode = fileNode.addNode("jcr:content", "nt:resource");
        resNode.setProperty("jcr:mimeType", mimeType);
        resNode.setProperty("jcr:encoding", "");
        resNode.setProperty(JcrConstants.JCR_DATA,
                           
resNode.getSession().getValueFactory().createBinary(input));
        Calendar lastModified = Calendar.getInstance();
        lastModified.setTimeInMillis(file.lastModified());
        resNode.setProperty("jcr:lastModified", lastModified);
        System.out.println(fileNode.getPath());
    }




--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Learning-Jackrabbit-Extracted-files-are-length-zero-tp4658373p4658375.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Mime
View raw message