1 17 package org.apache.commons.collections.primitives.adapters.io; 18 19 import java.io.Reader ; 20 21 import org.apache.commons.collections.primitives.CharIterator; 22 23 29 public class CharIteratorReader extends Reader { 30 31 public CharIteratorReader(CharIterator in) { 32 this.iterator= in; 33 } 34 35 public int read(char[] buf, int off, int len) { 36 if(iterator.hasNext()) { 37 int count = 0; 38 while(iterator.hasNext() && count < len) { 39 buf[off + count] = iterator.next(); 40 count++; 41 } 42 return count; 43 } else { 44 return -1; 45 } 46 } 47 48 public void close() { 49 } 50 51 public static Reader adapt(CharIterator in) { 52 return null == in ? null : new CharIteratorReader(in); 53 } 54 55 private CharIterator iterator = null; 56 57 } 58 | Popular Tags |