My URL Reader Class runs too slowly

32 views Asked by At

Here, i take String url as a parameter. This is imdb link such as MovieURL imitation = new MovieURL("http://www.imdb.com/title/tt3477064/");

And I take name, point and year information. But it runs too slowly. Which method makes it slow. How can I faster this ?

import java.net.*;
import java.io.*;

public class MovieURL {

// PROPERTIES

private String name;
private String year;
private String point;

private URL link;

private String data;

// CONSTRUCTOR

public MovieURL ( String url )
{

    try {

        link = new URL( url );

        URLConnection connection = link.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));

        String inputLine;

        while ((inputLine = br.readLine()) != null) 
        {
            data = data + inputLine;                
        }
        br.close();
    }
    catch ( Exception e ) {
        e.printStackTrace();
    }

    name = findName();
    year = findYear();
    point = findPoint();
}

// METHODS

public String findName() {

    int pos = data.indexOf("Discuss");
    int indexOfPar = data.indexOf('(', pos);

    String name = data.substring(pos+8, indexOfPar-1);

    return name;
}

public String getName() {
    return name;
}

public String findYear() {

    int pos = data.indexOf("Discuss");
    int indexOfPar = data.indexOf('(', pos);

    String year = data.substring(indexOfPar+1, indexOfPar+5);

    return year;

}

public String getYear() {
    return year;
}    

public String findPoint() {

    int pos = data.indexOf("Users rated this");

    String point = data.substring(pos+17, pos+20);

    return point;
}

public String getPoint() {
    return point;
}   

public String toString()
{
    return name + " | " + point;

}
}
0

There are 0 answers