1 3 package gnu.jemacs.swt; 4 5 import java.io.IOException ; 6 import java.io.Reader ; 7 8 12 public class BufferContentReader extends Reader 13 { 14 15 private boolean closed = false; 16 private BufferContent bufferContent; 17 private int start; 18 private int count; 19 20 23 public BufferContentReader(BufferContent bufferContent, int start, int count) 24 { 25 super(); 26 this.bufferContent = bufferContent; 27 this.start = start; 28 this.count = Math.min(bufferContent.size() - start, count); 29 } 30 31 34 public void close() throws IOException 35 { 36 closed = true; 37 } 38 39 42 public int read(char[] cbuf, int off, int len) throws IOException 43 { 44 if (closed) 45 { 46 throw new IOException (); 47 } 48 49 if (count <= 0) 50 { 51 return -1; 52 } 53 else 54 { 55 int chars = Math.min(this.count, len); 56 bufferContent.getChars(start, start + chars, cbuf, off); 57 start += chars; 58 count -= chars; 59 return chars; 60 } 61 } 62 } 63 | Popular Tags |