Created
September 24, 2015 21:13
-
-
Save paynegreen/34f5252b5bc911b7b99c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface URLProcessor { | |
public void process(URL url) throws IOException; | |
public abstract class URLProcessorBase implements URLProcessor { | |
public void process(URL url) throws IOException { | |
URLConnection urlConnection = url.openConnection(); | |
InputStream input = urlConnection.getInputStream(); | |
try{ | |
processURLData(input); | |
} finally { | |
input.close(); | |
} | |
} | |
protected abstract void processURLData(InputStream input) | |
throws IOException; | |
} | |
public class URLProcessorImpl extends URLProcessorBase { | |
@Override | |
protected void processURLData(InputStream input) throws IOException { | |
int data = input.read(); | |
while(data != -1){ | |
System.out.println((char) data); | |
data = input.read(); | |
} | |
} | |
} | |
public static void main(String[] args){ | |
URLProcessor urlProcessor = new URLProcessorImpl(); | |
urlProcessor.process(new URL("http://gitbhub.com")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment