Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:48:52+00:00 2026-06-11T16:48:52+00:00

I’ve developed a HTTP communication object for the purpose pof downloading files via a

  • 0

I’ve developed a HTTP communication object for the purpose pof downloading files via a GET request.

This works just fine when downloading a text file. However, downloading a compressed file such as zip, gz or tar.gz appears to download the file but the file is not valid.

In the case zip I get a meesage saying it tried to move the pointer before the beginnning of the file.
In the case of .tar.gz the message is Data error in file.tar. File is broken.

In all cases the download links I use do allow a complete and correct download from the URL. Yet, the Java code based download brings the file down but it is not valid.

The code is as follows:

public class HTTPCommunicationGet {

    private URIBuilder sendData;
    private URI target;
    private HttpGet getConnection;

    public HTTPCommunicationGet(String url, TreeMap<String, String> components) {
        super(url, components);
    }

    public HTTPCommunicationGet(String url, String queryString) {
        super(url, queryString);
    }

    protected void defineSendData() throws URISyntaxException, IOException {
        this.sendData = new URIBuilder(new URI(this.getUrl()));
        if (this.getComponents() != null && this.getComponents().size() > 0) {
            for (Map.Entry<String, String> component : this.getComponents().entrySet()) {
                this.sendData.setParameter(component.getKey(), component.getValue());
            }
        }
    }

    protected void retrieveRemoteData() throws IOException, MalformedURLException, URISyntaxException, DataMapHTTPGetException {

        this.target = this.sendData.build();
        this.getConnection = new HttpGet(target);
        HttpResponse response = client.execute(this.getConnection);
        if (response.getStatusLine().toString().toUpperCase().contains("200 OK")) {
            this.setResponse(response.getStatusLine().toString(), "Data Retrieved");
            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line = "";
            while ((line = rd.readLine()) != null) {
                this.remoteData.append(line);
            }
        } else {
            String message = String.format("%s: Provider connection exception; response returned was not 200 OK", this.target.toASCIIString());
            this.setResponse(response.getStatusLine().toString(), message);
            DataMapHTTPGetException ex = new DataMapHTTPGetException(target.toString(), message);
            throw ex;
        }
    }

    public void downloadFiles(String localFile) throws DataMapConnectionException, FileNotFoundException, IOException, URISyntaxException {
        // check that we have remoteData set
        this.defineSendData();
        this.retrieveRemoteData(); // everything is bubbled up to the controller class that is calling this.

        File localMetaFile = new File(localFile);
        switch (this.archiveMetaFile(localMetaFile)) {
            case -1:
                IOException ex = new IOException(String.format("The file %s could not be moved", localFile));
                throw ex;
            //break;
            case 0:
                infoLog.info(String.format("%s: this file did not already exist", localFile));
                break;
            case 1:
                infoLog.info(String.format("%s: this file was found and successfully archived to the processed directory", localFile));
                break;
        }

        BufferedWriter fileWriter = new BufferedWriter(new FileWriter(localFile));
        fileWriter.write(this.remoteData.toString());
        fileWriter.close();
    }
}

As you can see this is called via downloadFiles after the object has been initialised. I’ve cut out the code that is not needed for this example such as the archiveMetaFile method.

Any pointers on why this is not working for compressed files is much appreciated.

Cheers
Nathan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:48:53+00:00Added an answer on June 11, 2026 at 4:48 pm

    The problem is likely that you are using a BufferedReader instead of an InputStream. Readers are used for text data and impose a character encoding whereas InputStreams can handle raw binary data.

    Try switching to a BufferedInputStream instead. The use of any Reader class will corrupt binary data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.