KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > text > html > SingleCharReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jface.internal.text.html;
12
13 import java.io.IOException JavaDoc;
14 import java.io.Reader JavaDoc;
15
16
17 /**
18  * <p>
19  * Moved into this package from <code>org.eclipse.jface.internal.text.revisions</code>.</p>
20  */

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

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

31     public int read(char cbuf[], int off, int len) throws IOException JavaDoc {
32         int end= off + len;
33         for (int i= off; i < end; i++) {
34             int ch= read();
35             if (ch == -1) {
36                 if (i == off)
37                     return -1;
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      * Returns the readable content as string.
54      * @return the readable content as string
55      * @exception IOException in case reading fails
56      */

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