A massive organize imports and formatting of the sources using default Eclipse code...
[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 import java.io.IOException;
14 import java.io.Reader;
15
16 public abstract class SingleCharReader extends Reader {
17
18         /**
19          * @see Reader#read()
20          */
21         public abstract int read() throws IOException;
22
23         /**
24          * @see Reader#read(char[],int,int)
25          */
26         public int read(char cbuf[], int off, int len) throws IOException {
27                 int end = off + len;
28                 for (int i = off; i < end; i++) {
29                         int ch = read();
30                         if (ch == -1) {
31                                 if (i == off) {
32                                         return -1;
33                                 } else {
34                                         return i - off;
35                                 }
36                         }
37                         cbuf[i] = (char) ch;
38                 }
39                 return len;
40         }
41
42         /**
43          * @see Reader#ready()
44          */
45         public boolean ready() throws IOException {
46                 return true;
47         }
48
49         /**
50          * Gets the content as a String
51          */
52         public String getString() throws IOException {
53                 StringBuffer buf = new StringBuffer();
54                 int ch;
55                 while ((ch = read()) != -1) {
56                         if (ch == '\n' || ch == '\r') {
57                                 buf.append("<br>");
58                         } else {
59                                 buf.append((char) ch);
60                         }
61                 }
62                 return buf.toString();
63         }
64 }