KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > ASCIIReader


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.help.internal.search;
12
13 import java.io.*;
14
15 /**
16  * High performance reader. Assumes the input stream is ASCII.
17  */

18 public class ASCIIReader extends Reader {
19     private InputStream stream;
20     int bufSize;
21     byte[] buf;
22     /**
23      * @param stream
24      * InputStream
25      * @param bufSize
26      * size of internal buffer
27      */

28     public ASCIIReader(InputStream stream, int bufSize) {
29         this.stream = stream;
30         this.bufSize = bufSize;
31         buf = new byte[bufSize];
32     }
33
34     /**
35      * @see java.io.Reader#read(char[], int, int)
36      */

37     public int read(char[] cbuf, int off, int len) throws IOException {
38         int n = stream.read(buf, 0, Math.min(bufSize, len));
39         for (int i = 0; i < n; i++) {
40             cbuf[off + i] = (char) buf[i];
41         }
42         return n;
43     }
44
45     /**
46      * @see java.io.Reader#close()
47      */

48     public void close() throws IOException {
49         stream.close();
50     }
51
52 }
53
Popular Tags