4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.util; 23 24 import java.io.*; 25 26 /** 27 * Utility class that implements a sequence of bytes which can be read 28 * via the `readByte()' method. This is used to implement a wrapper for the 29 * Java byte code stream to gain some more readability. 30 * 31 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 32 */ 33 public final class ByteSequence extends DataInputStream { 34 private ByteArrayStream byte_stream; 35 36 public ByteSequence(byte[] bytes) { 37 super(new ByteArrayStream(bytes)); 38 byte_stream = (ByteArrayStream)in; 39 } 40 41 public final int getIndex() { return byte_stream.getPosition(); } 42 final void unreadByte() { byte_stream.unreadByte(); } 43 44 private static final class ByteArrayStream extends ByteArrayInputStream { 45 ByteArrayStream(byte[] bytes) { super(bytes); } 46 final int getPosition() { return pos; } // is protected in ByteArrayInputStream 47 final void unreadByte() { if(pos > 0) pos--; } 48 } 49 } | 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.util; 23 24 import java.io.ByteArrayInputStream; 25 import java.io.DataInputStream; 26 27 /** 28 * Utility class that implements a sequence of bytes which can be read 29 * via the `readByte()' method. This is used to implement a wrapper for the 30 * Java byte code stream to gain some more readability. 31 * 32 * @version $Id: ByteSequence.java 1747278 2016-06-07 17:28:43Z britter $ 33 */ 34 public final class ByteSequence extends DataInputStream { 35 36 private final ByteArrayStream byteStream; 37 38 39 public ByteSequence(final byte[] bytes) { 40 super(new ByteArrayStream(bytes)); 41 byteStream = (ByteArrayStream) in; 42 } 43 44 45 public final int getIndex() { 46 return byteStream.getPosition(); 47 } 48 49 50 final void unreadByte() { 51 byteStream.unreadByte(); 52 } 53 54 private static final class ByteArrayStream extends ByteArrayInputStream { 55 56 ByteArrayStream(final byte[] bytes) { 57 super(bytes); 58 } 59 60 final int getPosition() { 61 // pos is protected in ByteArrayInputStream 62 return pos; 63 } 64 65 final void unreadByte() { 66 if (pos > 0) { 67 pos--; 68 } 69 } 70 } 71 } |