hi fernando
On Tue, Jul 28, 2009 at 11:02 PM, Fernando Cabredo<[email protected]> 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