87340b4f03919b5add81ac4204b6a1af34078f75
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / phpdoc / SingleCharReader.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.corext.phpdoc;
12
13
14 import java.io.IOException;
15 import java.io.Reader;
16
17 public abstract class SingleCharReader extends Reader {
18         
19         /**
20          * @see Reader#read()
21          */
22         public abstract int read() throws IOException;
23
24         /**
25          * @see Reader#read(char[],int,int)
26          */
27         public int read(char cbuf[], int off, int len) throws IOException {
28                 int end= off + len;
29                 for (int i= off; i < end; i++) {
30                         int ch= read();
31                         if (ch == -1) {
32                                 if (i == off) {
33                                         return -1;
34                                 } else {
35                                         return i - off;
36                                 }
37                         }
38                         cbuf[i]= (char)ch;
39                 }
40                 return len;
41         }               
42         
43         /**
44          * @see Reader#ready()
45          */             
46     public boolean ready() throws IOException {
47                 return true;
48         }
49         
50         /**
51          * Gets the content as a String
52          */
53         public String getString() throws IOException {
54                 StringBuffer buf= new StringBuffer();
55                 int ch;
56                 while ((ch= read()) != -1) {
57                         buf.append((char)ch);
58                 }
59                 return buf.toString();
60         }
61 }