Writing from Datahandler to file

I created a web service using CXF/MTOM for transfering large files (over 700Mo), i managed to transfer the file to the server , now my question is to optimze writing data in disk, i will give examples :

DataHandler handler = fichier.getFichier();

InputStream is = handler.getInputStream();

OutputStream os = new FileOutputStream(new File("myFile"));

byte[] buffer = new byte[BUFFER];
int bytesRead = 0;
while ((bytesRead = is.read(buffer)) != -1) {

Using bytes can lead me to an OutOfMemory, so i'd rather use this one :

DataHandler handler = fichier.getFichier();


this take 2 minutes for uploading 700Mo.

what are other efficient ways ?



I suggest you to use the class IOUtils of Apache Commons IO https://commons.apache.org/proper/commons-io/javadocs/api-release/index.html?org/apache/commons/io/input/package-summary.html

QN: org.apache.commons.io.IOUtils

DataHandler handler = docClient.getContent(sid, docId);

InputStream is = handler.getInputStream();
OutputStream os = new FileOutputStream(new File("C:/tmp/myFile.raw"));

// This will copy the file from the two streams
IOUtils.copy(is, os);

// This will close two streams catching exception

Need Your Help

Calling " getContentResolver " in an Android Java class

android multithreading service android-contentresolver android-context

I have an Service S which contains a Thread T. I also have a Java Class C. I would like to call a method of the class C from the thread T. The method is supposed to contain the lines :