Skip to content

Instantly share code, notes, and snippets.

@paynegreen
Created September 24, 2015 21:13
Show Gist options
  • Save paynegreen/34f5252b5bc911b7b99c to your computer and use it in GitHub Desktop.
Save paynegreen/34f5252b5bc911b7b99c to your computer and use it in GitHub Desktop.
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