Java Heap Space issue while reading 50MB files

cancel
Showing results for 
Search instead for 
Did you mean: 
yash_patel_c2
Established Member

Java Heap Space issue while reading 50MB files

Hi everyone,

I want to read 50-100 MB CSV file in java script rule to update the details in Alfresco data list. But I am getting Java Heap space issue on the below line of code.

var items = companyhome.childByNamePath("/Sites/datalists/documentLibrary/Demo.csv").content;
Also I tried Java code in the below line as well.
                                             NodeRef csvNodeRef = rs.getNodeRef(0);
                                             System.out.println("csvNodeRef "+csvNodeRef);
                                             ContentReader cr = fileFolderService.getReader(csvNodeRef);
                                             FileInputStream fis = (FileInputStream) cr.getContentInputStream();

How can I solve this issue?

Thanks,

Yash

1 Reply
sanjaybandhniya
Intermediate

Re: Java Heap Space issue while reading 50MB files

Hi,

ContentReader cr = fileFolderService.getReader(new NodeRef("noderef"));
InputStream fis = cr.getContentInputStream();

Scanner sc = new Scanner(fis, "UTF-8");
while (sc.hasNextLine()) {
      String line = sc.nextLine();
      System.out.println(line);
}

With above code 55 MB file reading fine.Without any error.