code: public static Node createResourceFile(Node parentNode, String relPath, Object data, String mimeType)
        throws Exception
     {
  
        Node file = parentNode.addNode(relPath, "nt:file");
        Node contentNode = file.addNode("jcr:content", "nt:resource");
  
        if (data instanceof InputStream)
           contentNode.setProperty("jcr:data", (InputStream)data);
        else if (data instanceof String)
           contentNode.setProperty("jcr:data", (String)data);
        // else if(data instanceof BinaryValue)
        // contentNode.setProperty("jcr:data", (BinaryValue)data);
        else
           throw new Exception("Invalid object for jcr:data " + data);
  
        contentNode.setProperty("jcr:mimeType", mimeType);
        contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
        return file;
  
     }
docs: creates nt:file node and fills it with incoming data
  
  @param parentNode
  @param relPath
  @param data
  @param mimeType
  @return
  @throws Exception