jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernando Cabredo <fcabred...@yahoo.com>
Subject Using InputStream
Date Tue, 28 Jul 2009 21:02:23 GMT
Hi,

I have the code below which lists files under a folder node and copy the files into my c:\
drive. However, I am not getting right the use of InputStream and FileOutputStream.this is
why the file that is being copied into my c:\ is incorrect. 

Can anybody please help me on this? 

Thank you.


Fernando Cabredo

  
-----------------------------------------------------------------------------------------------------
            String nodeType;
            Node n;
            Node root = session.getRootNode(); 
            if(selectedNode.equals("")){
                n = root;
            }else{
                selectedNode = selectedNode.substring(1, selectedNode.length());
                n = root.getNode(selectedNode);
            }
            NodeIterator nodes = n.getNodes();
            System.out.println("Listing Files of Folder Nodes under ---->"+ n.getName());
            while (nodes.hasNext()) {
                    Node node;
                    node = nodes.nextNode();
                    String nodename = node.getName();
                    nodeType = node.getProperty("jcr:primaryType").getString();
                    if (nodeType.equals("nt:file")) {
                        System.out.println("Node name ----->"+nodename);
                        InputStream attachFileIS = null;
                        Node resNode = node.getNode("jcr:content");
                        Value attachFileValue = resNode.getProperty("jcr:data").getValue();
                        attachFileIS = attachFileValue.getStream();
                        fout = new FileOutputStream("c://"+nodename);
                        byte[] readData = new byte[1024];
                        int i = attachFileIS.read(readData);
                        while (i != -1) {
                            fout.write(i);
                            i = attachFileIS.read(readData);
                        }
                        fout.close();
                   }
                    //aList.add(nodeProperty);
                }
            }catch (Exception e) {
                e.printStackTrace();
            }



      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message