1 18 package net.sf.mybatchfwk.history; 19 20 import java.io.BufferedReader ; 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 24 30 public class LineIterator implements Iterator { 31 32 private final BufferedReader reader; 33 34 private String line = null; 35 36 39 public LineIterator(BufferedReader reader) { 40 this.reader = reader; 41 } 42 43 46 public Object next() { 47 if ((this.line == null) && (!this.hasNext())) { 48 return null; 49 } else { 50 String toReturn = this.line; 51 this.line = null; 52 return toReturn; 53 } 54 } 55 56 59 public boolean hasNext() throws IOEWrapper { 60 if (this.line == null) { 61 try { 62 line = this.reader.readLine(); 63 } catch (IOException e) { 64 throw new IOEWrapper(e); 65 } 66 return (line != null); 67 } else { 68 return true; 69 } 70 } 71 72 75 public void remove() { 76 throw new UnsupportedOperationException ( 77 "LineIterator does not support remove()"); 78 } 79 80 83 public void close() { 84 try { 85 this.reader.close(); 86 } catch (IOException e) { 87 } 88 } 89 90 93 public static class IOEWrapper extends RuntimeException { 94 95 private static final long serialVersionUID = 4963463932839852732L; 96 97 private final IOException ioe; 98 99 public IOEWrapper(IOException ioe) { 100 this.ioe = ioe; 101 } 102 103 public IOException getIOException() { 104 return this.ioe; 105 } 106 } 107 } 108 | Popular Tags |