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