You could create DataHandler directly from InputStream using DataHandler (InputStream, String) constructor.
-----Original Message----- From: Chandolu, Yuva [mailto:[EMAIL PROTECTED] Sent: 12 March 2008 17:56 To: [email protected] Subject: RE: Question regarding attachments with Axis and DataHandler Is there a work around/any other solution for this then? If ByteArrayDataSource reads whole file into memory my service would run out of memory if lots of client access the service at the same time. -----Original Message----- From: Andreas Veithen [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 11, 2008 5:41 PM To: [email protected] Subject: Re: Question regarding attachments with Axis and DataHandler Yuva, The implementation of the ByteArrayDataSource constructor you are using looks as follows: public ByteArrayDataSource(InputStream is, String type) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buf = new byte[8192]; int len; while ((len = is.read(buf)) > 0) os.write(buf, 0, len); this.data = os.toByteArray(); this.type = type; } As you can see, it will indeed read the entire Blob into a ByteArrayOutputStream and then copy it to a byte array. It is therefore not surprising that you run out of memory. Andreas On 11 Mar 2008, at 21:42, Chandolu, Yuva wrote: > Hi, > > I am trying to replace one servlet serving huge files by a > webservice. When request comes in, the servlet opens InputStream to > the file blob in database, read from the input stream and write to > the http output stream. When client starts pulling the data it comes > straight from the input stream of the servlet (pure streaming). In > which case the Servlet can handle 100s of clients because the > Servlet threads are not trying to load the whole file into memory on > the server side and just sending down the data when it is read from > the client side. > > Now I am trying to replace the servlet code by a web service. I am > using DataHanlder for attachements. We have big files in database > (each 10MB or more). When the client call my service > downloadfile(fileName) I need to pull it from the database and > create a datahandler and return to the client. My concern is what > will happen if 100 clients request the all big files (say each 10 MB > in size) using downloadFile() service. My question here is how the > datahandler works, will it read all the file contents from file blob > from database and store in memory before we return it to the client? > Looks like it is because my tomcat is running out of memory when I > tried 20 client threads in parallel requesting for big files. How > can I solve the problem? > > Following is my code snippet > > Blob file_blob = rs.getBlob(1); > ByteArrayDataSource bds = new > ByteArrayDataSource(file_blob.getBinaryStream(), "application/octet- > stream"); > DataHandler data_handler = new DataHandler(bds); > > return data_handler; > > Thanks in advance > Yuva --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ***************************************************** This email is issued by a VocaLink group company. It is confidential and intended for the exclusive use of the addressee only. You should not disclose its contents to any other person. If you are not the addressee (or responsible for delivery of the message to the addressee), please notify the originator immediately by return message and destroy the original message. The contents of this email will have no contractual effect unless it is otherwise agreed between a specific VocaLink group company and the recipient. The VocaLink group companies include, among others: VocaLink Limited (Company No 06119048, VAT No. 907 9619 87) which is registered in England and Wales at registered office Drake House, Homestead Road, Rickmansworth, WD3 1FX. United Kingdom, Voca Limited (Company no 1023742, VAT No. 907 9619 87) which is registered in England and Wales at registered office Drake House, Three Rivers Court, Homestead Road, Rickmansworth, Hertfordshire. WD3 1FX. United Kingdom, LINK Interchange Network Limited (Company No 3565766, VAT No. 907 9619 87) which is registered in England and Wales at registered office Arundel House, 1 Liverpool Gardens, Worthing, West Sussex, BN11 1SL and VocaLink Holdings Limited (Company No 06119036, VAT No. 907 9619 87) which is registered in England and Wales at registered office Drake House, Homestead Road, Rickmansworth, WD3 1FX. United Kingdom. The views and opinions expressed in this email may not reflect those of any member of the VocaLink group. This message and any attachments have been scanned for viruses prior to leaving the VocaLink group network; however, VocaLink does not guarantee the security of this message and will not be responsible for any damages arising as a result of any virus being passed on or arising from any alteration of this message by a third party. The VocaLink group may monitor emails sent to and from the VocaLink group network. This message has been checked for all email viruses by MessageLabs. *************************************************************
