PositionInputStream.java revision 2224:2a8815d86b93
1204431Sraj/* 2204431Sraj * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3204431Sraj * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4204431Sraj * 5204431Sraj * This code is free software; you can redistribute it and/or modify it 6204431Sraj * under the terms of the GNU General Public License version 2 only, as 7204431Sraj * published by the Free Software Foundation. Oracle designates this 8204431Sraj * particular file as subject to the "Classpath" exception as provided 9204431Sraj * by Oracle in the LICENSE file that accompanied this code. 10204431Sraj * 11204431Sraj * This code is distributed in the hope that it will be useful, but WITHOUT 12204431Sraj * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13204431Sraj * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14204431Sraj * version 2 for more details (a copy is included in the LICENSE file that 15204431Sraj * accompanied this code). 16204431Sraj * 17204431Sraj * You should have received a copy of the GNU General Public License version 18204431Sraj * 2 along with this work; if not, write to the Free Software Foundation, 19204431Sraj * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20204431Sraj * 21204431Sraj * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22204431Sraj * or visit www.oracle.com if you need additional information or have any 23204431Sraj * questions. 24204431Sraj */ 25204431Sraj 26204431Sraj 27204431Sraj/* 28204431Sraj * The Original Code is HAT. The Initial Developer of the 29204431Sraj * Original Code is Bill Foote, with contributions from others 30204431Sraj * at JavaSoft/Sun. 31204431Sraj */ 32204431Sraj 33204431Srajpackage jdk.test.lib.hprof.parser; 34204431Sraj 35204431Srajimport java.io.FilterInputStream; 36204431Srajimport java.io.IOException; 37204431Srajimport java.io.InputStream; 38204431Sraj 39204431Sraj/** 40204431Sraj * InputStream that keeps track of total bytes read (in effect 41204431Sraj * 'position' in stream) from the input stream. 42204431Sraj * 43204431Sraj */ 44204431Srajpublic class PositionInputStream extends FilterInputStream { 45204431Sraj private long position = 0L; 46204431Sraj 47204431Sraj public PositionInputStream(InputStream in) { 48204431Sraj super(in); 49204431Sraj } 50204431Sraj 51204431Sraj public int read() throws IOException { 52204431Sraj int res = super.read(); 53204431Sraj if (res != -1) position++; 54204431Sraj return res; 55204431Sraj } 56204431Sraj 57204431Sraj public int read(byte[] b, int off, int len) throws IOException { 58204431Sraj int res = super.read(b, off, len); 59204431Sraj if (res != -1) position += res; 60204431Sraj return res; 61204431Sraj } 62204431Sraj 63204431Sraj public long skip(long n) throws IOException { 64204431Sraj long res = super.skip(n); 65204431Sraj position += res; 66204431Sraj return res; 67204431Sraj } 68204431Sraj 69204431Sraj public boolean markSupported() { 70204431Sraj return false; 71204431Sraj } 72204431Sraj 73204431Sraj public void mark(int readLimit) { 74204431Sraj throw new UnsupportedOperationException("mark"); 75204431Sraj } 76204431Sraj 77318102Sgonzo public void reset() { 78204431Sraj throw new UnsupportedOperationException("reset"); 79204431Sraj } 80204431Sraj 81204431Sraj public long position() { 82204431Sraj return position; 83238742Simp } 84238742Simp} 85204431Sraj