base64 - OutOfMemory Exception while executing JAVA Mapping -


i have transfer big files (500 mb+...can of 1gb in size). these files have base64 encoded , encoded string has put in xml file. while below code works smaller files (30 - 50 mb) fails files great 100 mb. using base64 encoder sun (sun.misc.base64encoder).

public void execute(inputstream inputstream, outputstream outputstream) throws streamtransformationexception{         try         {             string sourcefilename = "test_file";             string receiverstr = "";             //2. convert input data in base64encoded string             base64encoder encoder = new base64encoder();             byte input[] = new byte[inputstream.available()];              inputstream.read(input);             string base64encoded = encoder.encode(input);             //3. build soap request format             string serverurl = "http://website/url";              string soapenvelope = "<soapenv:envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.microsoft.com/sharepoint/soap/\">";             string soapheader = "<soapenv:header/><soapenv:body><soap:copyintoitems><soap:sourceurl>c:\\users\\desktop\\test_file.txt</soap:sourceurl><soap:destinationurls><soap:string>" + serverurl + "</soap:string></soap:destinationurls><soap:fields><soap:fieldinformation " + "type=" + "\"text\"" + " displayname=\"" + sourcefilename + "\"" + " internalname=\"" + sourcefilename + "\"" + " id=\"deff4b5c-b727-414c-893d-c56a8e12455f\"" + " value=\"" + sourcefilename + "\"/></soap:fields>";             string soapstream = "<soap:stream>" + base64encoded + "</soap:stream>";             receiverstr = soapenvelope + soapheader + soapstream + "</soap:copyintoitems></soapenv:body></soapenv:envelope>";             //4. write soap request receiver channel             outputstream.write(receiverstr.getbytes());         }         catch(exception e) {             throw new streamtransformationexception(e.tostring());           }     } 

when try see message @ run-time, entire message not displayed , truncated in-between in base64encoded string. below error seen in system on executing java code. enter image description here please note server settings can otherwise transfer 1gb+ files without java heap size error or file truncation. can please let me know how can process big files using above logic?

thanks,

abhishek.

taking @ code store data 3 times:

the first time in byte array input stream. second time in encoded string , write output stream.

what can optimize bit split reading input stream/encoding , writing of encoded string output stream. way can let go of input byte array once encoded , memory can freed. better solution when encoder directly writes output stream or directly write encoding output stream.

however still have consider maximum file size should can processed , adjust heap setting accordingly: how deal "java.lang.outofmemoryerror: java heap space" error (64mb heap size)


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -