2012-03-04 57 views
1

我想直接将文件流式传输到Web服务。 对于我创建使用无法传输到作家

 URL url = new URL("http://localhost:9200/tree/public/"); 
    URLConnection urlconnection=url.openConnection(); 
    urlconnection.setDoOutput(true); 
    ((HttpURLConnection)urlconnection).setRequestMethod("POST"); 
    ((HttpURLConnection)urlconnection).setRequestProperty("Content-type", "text/html"); 
    Writer out=new OutputStreamWriter(urlconnection.getOutputStream(); 

下一个作家我一直在写数据到它,

while(<Read from file , line>){ 
    out.write(line); 
    out.flush(); 
} 

out.close(); 

在这里我希望主内存不会被用于文件内容作为存储整个。因为一次只有一行文件。

但是随后在执行代码时,内存使用量急剧增加,而且非常清晰,文件内容保存在主内存中的某处。 在堆转储发现PosterOutputStream是持有大部分空间的人。

+1

你在说多少内存?在封面下会有一些不可避免的缓冲。 – 2012-03-04 05:01:36

+0

我正在说GB的记忆。我不在乎轻微的缓冲。如果它是“轻微的” – 2012-03-04 05:17:15

+0

如果您在GB范围内看到内存,则还有其他问题。我们不能没有更多的细节。 – 2012-03-04 05:19:40

回答

1

启用分块流式解决了这个问题。 ((HttpURLConnection)urlconnection).setChunkedStreamingMode(1024 * 1024);