129
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.internal.text.html.SingleCharReader;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.io.IOException;
|
|
18 import java.io.Reader;
|
|
19
|
|
20
|
|
21 /**
|
|
22 * <p>
|
|
23 * Moved into this package from <code>dwtx.jface.internal.text.revisions</code>.</p>
|
|
24 */
|
|
25 public abstract class SingleCharReader : Reader {
|
|
26
|
|
27 /**
|
|
28 * @see Reader#read()
|
|
29 */
|
|
30 public abstract int read() throws IOException;
|
|
31
|
|
32 /**
|
|
33 * @see Reader#read(char[],int,int)
|
|
34 */
|
|
35 public int read(char cbuf[], int off, int len) throws IOException {
|
|
36 int end= off + len;
|
|
37 for (int i= off; i < end; i++) {
|
|
38 int ch= read();
|
|
39 if (ch is -1) {
|
|
40 if (i is off)
|
|
41 return -1;
|
|
42 return i - off;
|
|
43 }
|
|
44 cbuf[i]= (char)ch;
|
|
45 }
|
|
46 return len;
|
|
47 }
|
|
48
|
|
49 /**
|
|
50 * @see Reader#ready()
|
|
51 */
|
|
52 public bool ready() throws IOException {
|
|
53 return true;
|
|
54 }
|
|
55
|
|
56 /**
|
|
57 * Returns the readable content as string.
|
|
58 * @return the readable content as string
|
|
59 * @exception IOException in case reading fails
|
|
60 */
|
|
61 public String getString() throws IOException {
|
|
62 StringBuffer buf= new StringBuffer();
|
|
63 int ch;
|
|
64 while ((ch= read()) !is -1) {
|
|
65 buf.append((char)ch);
|
|
66 }
|
|
67 return buf.toString();
|
|
68 }
|
|
69 }
|