Giter Site home page Giter Site logo

it-ebooks.info's People

Contributors

erjan avatar

Watchers

 avatar  avatar  avatar

it-ebooks.info's Issues

returned empty string

public class ProcessData extends AsyncTask<String, Void, String> {
private final String LOG_TAG = ProcessData.class.getSimpleName();

Uri destinationURL ;
public String createValidURL(String query) {
    Log.d(LOG_TAG, "create Valid url......");
    Log.d(LOG_TAG, "search word: " + query) ;
    String BASE_URL = "http://it-ebooks-api.info/v1/search" ;
    String searchBy = "type";
    destinationURL = Uri.parse(BASE_URL).buildUpon()
            .appendPath(query)
            .appendQueryParameter(searchBy, "title")
            .build();

    String result = destinationURL.toString();
    Log.d(LOG_TAG," actual url we use:" + result);

    Log.d(LOG_TAG, " ");
    return " ";   //THIS WAS STUPID ERROR!
}

public String MakeConnectionAndReadData(String validUrl){
    Log.d(LOG_TAG, "make connection and read data");
    Log.d(LOG_TAG, "VALID url:" + validUrl);

    HttpURLConnection urlConnection = null;
    BufferedReader reader = null;

    try {
        URL url = new URL(validUrl);

        urlConnection = (HttpURLConnection) url.openConnection();
        if(urlConnection == null)
            Log.e(LOG_TAG, "url connection is null! ERROR");
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        InputStream inputStream = urlConnection.getInputStream();
        if(inputStream == null) {
            Log.e(LOG_TAG, "input stream failed to create!!!");
            return null;
        }
        StringBuffer buffer = new StringBuffer();

        reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while((line = reader.readLine()) != null) {
            Log.d(LOG_TAG, line) ;
            Log.d(LOG_TAG, "--->") ;

            buffer.append(line + "\n");
        }
        Log.d(LOG_TAG, " ");
        Log.d(LOG_TAG, "buffer: " + buffer.toString());
        return buffer.toString();

    } catch(IOException e) {
        Log.e(LOG_TAG, "Error", e);
        return null;
    } finally {
        if(urlConnection != null) {
            urlConnection.disconnect();
        }
        if(reader != null) {
            try {
                reader.close();
            } catch(final IOException e) {
                Log.e(LOG_TAG,"Error closing stream", e);
            }
        }
    }
}

public String doInBackground(String ...params){
   String validUrl = createValidURL(params[0]);
    Log.d(LOG_TAG, "the url I got from  createValidUrl() method:" + validUrl);
    Log.d(LOG_TAG, " ");
   String bigData = MakeConnectionAndReadData(validUrl);
    return bigData ;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.