jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Guggisberg <stefan.guggisb...@gmail.com>
Subject Re: Using InputStream
Date Wed, 29 Jul 2009 07:42:44 GMT
hi fernando

On Tue, Jul 28, 2009 at 11:02 PM, Fernando Cabredo<fcabredoph@yahoo.com> wrote:
> 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")) {

                      if (node.isNodeType("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 read;
            while ((read = attachFileIS.read(readData)) > 0) {
                fout.write(readData, 0, read);
            }
            attachFileIS.close();
            fout.close();

>                        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();
>            }
>
>
>
>

cheers
stefan

Mime
View raw message