KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > javadoc > SingleCharReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.javadoc;
12
13
14 import java.io.IOException JavaDoc;
15 import java.io.Reader JavaDoc;
16
17 public abstract class SingleCharReader extends Reader JavaDoc {
18     
19     /**
20      * @see Reader#read()
21      */

22     public abstract int read() throws IOException JavaDoc;
23
24     /**
25      * @see Reader#read(char[],int,int)
26      */

27     public int read(char cbuf[], int off, int len) throws IOException JavaDoc {
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 JavaDoc {
47         return true;
48     }
49     
50     /**
51      * Gets the content as a String
52      */

53     public String JavaDoc getString() throws IOException JavaDoc {
54         StringBuffer JavaDoc buf= new StringBuffer JavaDoc();
55         int ch;
56         while ((ch= read()) != -1) {
57             buf.append((char)ch);
58         }
59         return buf.toString();
60     }
61 }
62
Popular Tags