View Javadoc
1 /*** 2 * Created by IntelliJ IDEA. 3 * User: Lennart 4 * Date: 22-nov-2003 5 * Time: 15:37:55 6 */ 7 package comics.core; 8 9 import comics.interfaces.ComicGrabberEngine; 10 11 import java.io.*; 12 import java.net.URL; 13 import java.util.GregorianCalendar; 14 15 /* 16 * CVS information: 17 * 18 * $Revision: 1.1 $ 19 * $Date: 2003/12/04 14:29:44 $ 20 */ 21 22 /*** 23 * This class provides a generic implementation of the ComicGrabberEngine interface. 24 * 25 * @author Lennart Martens 26 */ 27 public class ComicGrabberEngineImplementation implements ComicGrabberEngine { 28 29 /*** 30 * Default constructor. 31 */ 32 public ComicGrabberEngineImplementation() { 33 } 34 35 /*** 36 * This method returns the ComicImage for the comic file at the specified URL. 37 * 38 * @param aUrl URL to locate the comic image on. 39 * @return ComicImage with the filename and contents of the image. 40 * @throws IOException when something goes wrong during the retrieve. 41 */ 42 public ComicImage grabComic(URL aUrl) throws IOException { 43 // Reading the file (if any). 44 InputStream input = aUrl.openStream(); 45 BufferedInputStream bis = new BufferedInputStream(input); 46 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 47 BufferedOutputStream bos = new BufferedOutputStream(baos); 48 int readByte = -1; 49 // Reading. 50 while((readByte = bis.read()) != -1) { 51 // Writing. 52 bos.write(readByte); 53 } 54 bos.flush(); 55 baos.flush(); 56 // Create the filename. 57 String filename = aUrl.getFile(); 58 filename = filename.substring(filename.lastIndexOf("/")+1); 59 // Create the ComicImage instance. 60 ComicImage result = new ComicImage(filename, baos.toByteArray()); 61 // Cleaning up. 62 bos.close(); 63 baos.close(); 64 bis.close(); 65 input.close(); 66 67 return result; 68 } 69 }

This page was automatically generated by Maven