KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > contentassist > display > SingleCharReader


1 /*******************************************************************************
2  * Copyright (c) 2006 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.pde.internal.ui.editor.contentassist.display;
12
13
14 import java.io.IOException JavaDoc;
15 import java.io.Reader JavaDoc;
16
17 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                 return i - off;
35             }
36             cbuf[i]= (char)ch;
37         }
38         return len;
39     }
40
41     /**
42      * @see Reader#ready()
43      */

44     public boolean ready() throws IOException JavaDoc {
45         return true;
46     }
47
48     /**
49      * Returns the readable content as string.
50      * @return the readable content as string
51      * @exception IOException in case reading fails
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