KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > derived > 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.ant.internal.ui.editor.derived;
12
13
14 import java.io.IOException JavaDoc;
15 import java.io.Reader JavaDoc;
16
17 /**
18  * @see org.eclipse.jdt.internal.corext.javadoc.SingleCharReader
19  */

20 public abstract class SingleCharReader extends Reader JavaDoc {
21     
22     /**
23      * @see Reader#read()
24      */

25     public abstract int read() throws IOException JavaDoc;
26
27     /**
28      * @see Reader#read(char[],int,int)
29      */

30     public int read(char cbuf[], int off, int len) throws IOException JavaDoc {
31         int end= off + len;
32         for (int i= off; i < end; i++) {
33             int ch= read();
34             if (ch == -1) {
35                 if (i == off) {
36                     return -1;
37                 }
38                 return i - off;
39             }
40             cbuf[i]= (char)ch;
41         }
42         return len;
43     }
44     
45     /**
46      * @see Reader#ready()
47      */

48     public boolean ready() throws IOException JavaDoc {
49         return true;
50     }
51     
52     /**
53      * Gets the content as a String
54      */

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