2507032824df9800de4f6f315bcd489d18b41812
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / phpdoc / SingleCharReader.java
1 package net.sourceforge.phpdt.internal.corext.phpdoc;
2
3 /*
4  * (c) Copyright IBM Corp. 2000, 2001.
5  * All Rights Reserved.
6  */
7
8 import java.io.IOException;
9 import java.io.Reader;
10
11 public abstract class SingleCharReader extends Reader {
12         
13         /**
14          * @see Reader#read()
15          */
16         public abstract int read() throws IOException;
17
18         /**
19          * @see Reader#read(char[],int,int)
20          */
21         public int read(char cbuf[], int off, int len) throws IOException {
22                 int end= off + len;
23                 for (int i= off; i < end; i++) {
24                         int ch= read();
25                         if (ch == -1) {
26                                 if (i == off) {
27                                         return -1;
28                                 } else {
29                                         return i - off;
30                                 }
31                         }
32                         cbuf[i]= (char)ch;
33                 }
34                 return len;
35         }               
36         
37         /**
38          * @see Reader#ready()
39          */             
40     public boolean ready() throws IOException {
41                 return true;
42         }
43         
44         /**
45          * Gets the content as a String
46          */
47         public String getString() throws IOException {
48                 StringBuffer buf= new StringBuffer();
49                 int ch;
50                 while ((ch= read()) != -1) {
51                         buf.append((char)ch);
52                 }
53                 return buf.toString();
54         }
55 }