Advertisement
Arduqq

netspeak-loader

Apr 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3. import java.util.Scanner;
  4.  
  5. public class SiteLoader {
  6.     public static String load(String x) throws IOException{
  7.         URL url = new URL(x);
  8.         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  9.         System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
  10.  
  11.         InputStream in = connection.getInputStream();
  12.         BufferedReader br = new BufferedReader(new InputStreamReader(in));
  13.         String curline;
  14.         StringBuilder content = new StringBuilder();
  15.         while( (curline = br.readLine()) != null ){
  16.  
  17.             content.append(curline + '\n');
  18.         }
  19.         br.close();
  20.         connection.disconnect();
  21.  
  22.         return content.toString();
  23.     }
  24.  
  25.     public static void main(String[] args){
  26.  
  27.         System.out.println("netspeak request:");
  28.  
  29.         Scanner input = new Scanner(System.in);
  30.         String answer = input.nextLine().toLowerCase();
  31.  
  32.         try{  
  33.             String request = URLEncoder.encode(answer, "UTF-8");
  34.             String content = SiteLoader.load("http://api.netspeak.org/netspeak3/search?query="+request);
  35.  
  36.             System.out.println(content);
  37.  
  38.         }catch(MalformedURLException e) {
  39.  
  40.             System.out.println("MalformedURLException:" + e.getMessage());
  41.         }catch(IOException e) {
  42.            
  43.             System.out.println("IOException:" + e.getMessage());
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement