2012-05-21 34 views
2

我創建了一個使用CXF/MTOM傳輸大文件(超過700Mo)的Web服務,我設法將文件傳輸到服務器,現在我的問題是優化寫入磁盤數據,我會給例子:從Datahandler寫入文件

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) { 
os.write(buffer,0,bytesRead); 
    } 

使用字節會導致我的內存不足,所以我寧願用這一個:

DataHandler handler = fichier.getFichier(); 

handler.writeTo(os); 

這需要2分鐘上傳700Mo。

什麼是其他有效的方法?

感謝

+0

在700MB 2分鐘約50mbps。你確定這不是讓你放慢速度的頻譜開關嗎? – npe

+0

正確,在1分鐘內在本地複製文件 – bazic

回答

0

我建議你使用類IOUtils 阿帕奇百科全書的 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 
IOUtils.closeQuietly(os); 
IOUtils.closeQuietly(is);