/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.redditprog.webcrawler;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 *
 * @author ryan
 */
public class SubRedditChecker {

    public static boolean verifySubReddit(String sub) {

        try {
            // set the full url of the user input subreddit
            final URL url = new URL("http://reddit.com/r/" + sub);

            // create a new connection
            HttpURLConnection huc = (HttpURLConnection) url.openConnection();

            // disable any redirect, since reddit automatically use search if
            // subreddit does not exist
            // Uses HEAD as request for faster link check
            huc.setRequestMethod("HEAD");
            
            // connects to the http
            huc.connect();

            // Possible solution (do not delete)
            //System.out.println("connected url: " + huc.getURL());

            // Extract the redirect url in string
            InputStream is = huc.getInputStream();
            String redirectURL = huc.getURL().getPath();
            is.close();
            
            // checks if it is a redirect and return boolean value
            return redirectURL.contains("/r/");

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

}

@@ -678,227 +678,8 @@
 n();
-%0A%0A            // disable any redirect, since reddit automatically use search if%0A            // subreddit does not exist%0A            // Uses HEAD as request for faster link check%0A            huc.setRequestMethod(%22HEAD%22);
 %0A   

Remove unnecessary code