342N/A/*
1625N/A * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A */
342N/A
342N/A/**/
1879N/A
1879N/Aimport java.io.*;
1879N/A
1879N/A
1879N/Apublic class ABCInputStream extends InputStream {
1879N/A
342N/A int len;
342N/A int chunk;
342N/A int count = 0;
342N/A char next = firstChar();
3863N/A
342N/A ABCInputStream(int len) {
342N/A this(len, len);
342N/A }
342N/A
342N/A ABCInputStream(int len, int chunk) {
342N/A this.len = len;
342N/A this.chunk = chunk;
342N/A }
342N/A
342N/A static char firstChar() {
1762N/A return 'a';
1762N/A }
1762N/A
1762N/A static char nextChar(char c) {
342N/A if (c == 'z')
342N/A return '0';
342N/A else if (c == '9')
342N/A return 'a';
342N/A else
342N/A return (char)(c + 1);
342N/A }
342N/A
342N/A public int read() {
342N/A if (count >= len)
342N/A return -1;
342N/A char c = next;
342N/A next = nextChar(c);
342N/A count++;
342N/A return (byte) c;
342N/A }
342N/A
342N/A public int read(byte buf[], int off, int len) {
342N/A int n = (len > chunk) ? chunk : len;
342N/A for (int i = off; i < off + n; i++) {
342N/A int c = read();
342N/A if (c == -1) {
342N/A if (i > off)
342N/A return i - off;
342N/A else
342N/A return -1;
342N/A }
342N/A buf[i] = (byte) c;
342N/A }
342N/A return n;
342N/A }
342N/A
342N/A public int available() {
342N/A int remaining = len - count;
342N/A return (remaining > chunk) ? chunk : remaining;
342N/A }
342N/A
342N/A public void close() throws IOException {
342N/A if (len == 0)
342N/A throw new IOException("Already closed");
342N/A len = 0;
342N/A }
1111N/A
342N/A}
342N/A