Apache HttpComponents Asyn GET:实体内容太长

时间:2014-06-04 22:09:42

标签: apache-camel large-files apache-httpcomponents

我在Camel的bean内部使用Apache HttpComponents来尝试编写一份工作来下载Apple的元数据数据库文件。这是iTunes中每首歌曲的列表。所以,显然它很大。 3.5+ GB。我正在尝试使用Apache HttpComponents来发出异步获取请求。但是,似乎返回的文件的大小太大。

try {
        httpclient.start();

        FileOutputStream fileOutputStream = new FileOutputStream(download);

        //Grab the archive.
        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder.setScheme("https");
        uriBuilder.setHost("feeds.itunes.apple.com");
        uriBuilder.setPath("/feeds/epf-flat/v1/full/usa/" + iTunesDate + "/song-usa-" + iTunesDate + ".tbz");

        String endpoint = uriBuilder.build().toURL().toString();

        HttpGet getCall = new HttpGet(endpoint);

        String creds64 = new String(Base64.encodeBase64((user + ":" + password).getBytes()));
        log.debug("Auth: " + "Basic " + creds64);
        getCall.setHeader("Authorization", "Basic " + creds64);

        log.debug("About to download file from Apple: " + endpoint);

        Future<HttpResponse> future = httpclient.execute(getCall, null);

        HttpResponse response = future.get();

        fileOutputStream.write(EntityUtils.toByteArray(response.getEntity()));
        fileOutputStream.close();

每次返回时:

java.util.concurrent.ExecutionException: org.apache.http.ContentTooLongException: Entity content is too long: 3776283429
at org.apache.http.concurrent.BasicFuture.getResult(BasicFuture.java:68)
at org.apache.http.concurrent.BasicFuture.get(BasicFuture.java:77)
at com.decibly.hive.songs.iTunesWrapper.getSongData(iTunesWrapper.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:407)

因此,对于Java整数,文件的大小(以字节为单位)是大的,HttpComponents用它来跟踪响应大小。我明白了,除了退回一层并直接调用Java Net库之外,还想知道是否有任何变通方法。

0 个答案:

没有答案