001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.cldc.i18n;
028:
029: import java.io.*;
030:
031: /**
032: * General prototype for character converting stream readers.
033: *
034: * @version 1.0 11/16/99
035: * @version 1.1 05/24/01
036: */
037: public abstract class StreamReader extends Reader {
038:
039: /** Input stream to read from */
040: public InputStream in;
041:
042: /**
043: * Open the reader
044: */
045: public Reader open(InputStream in, String enc)
046: throws UnsupportedEncodingException {
047:
048: this .in = in;
049: return this ;
050: }
051:
052: /**
053: * Tell whether the underlying byte stream is ready to be read. Return
054: * false for those streams that do not support available(), such as the
055: * Win32 console stream.
056: */
057: public boolean ready() {
058: try {
059: return in.available() > 0;
060: } catch (IOException x) {
061: return false;
062: }
063: }
064:
065: /**
066: * Tell whether this stream supports the mark() operation.
067: */
068: public boolean markSupported() {
069: return in.markSupported();
070: }
071:
072: /**
073: * Mark the present position in the stream.
074: *
075: * @exception IOException If an I/O error occurs
076: */
077: public void mark(int readAheadLimit) throws IOException {
078: if (in.markSupported()) {
079: in.mark(readAheadLimit);
080: } else {
081: throw new IOException(
082: /* #ifdef VERBOSE_EXCEPTIONS */
083: /// skipped "mark() not supported"
084: /* #endif */
085: );
086: }
087: }
088:
089: /**
090: * Reset the stream.
091: *
092: * @exception IOException If an I/O error occurs
093: */
094: public void reset() throws IOException {
095: in.reset();
096: }
097:
098: /**
099: * Close the stream.
100: *
101: * @exception IOException If an I/O error occurs
102: */
103: public void close() throws IOException {
104: in.close();
105: in = null;
106: }
107:
108: /**
109: * Get the size in chars of an array of bytes
110: */
111: public abstract int sizeOf(byte[] array, int offset, int length);
112:
113: }
|