1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package org.apache.bcel.util;
18  
19  import java.io.ByteArrayInputStream;
20  import java.io.DataInputStream;
21  
22  /***
23   * Utility class that implements a sequence of bytes which can be read
24   * via the `readByte()' method. This is used to implement a wrapper for the 
25   * Java byte code stream to gain some more readability.
26   *
27   * @version $Id: ByteSequence.java 386056 2006-03-15 11:31:56Z tcurdt $
28   * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29   */
30  public final class ByteSequence extends DataInputStream {
31  
32      private ByteArrayStream byte_stream;
33  
34  
35      public ByteSequence(byte[] bytes) {
36          super(new ByteArrayStream(bytes));
37          byte_stream = (ByteArrayStream) in;
38      }
39  
40  
41      public final int getIndex() {
42          return byte_stream.getPosition();
43      }
44  
45  
46      final void unreadByte() {
47          byte_stream.unreadByte();
48      }
49  
50      private static final class ByteArrayStream extends ByteArrayInputStream {
51  
52          ByteArrayStream(byte[] bytes) {
53              super(bytes);
54          }
55  
56  
57          final int getPosition() {
58              return pos;
59          } 
60  
61  
62          final void unreadByte() {
63              if (pos > 0) {
64                  pos--;
65              }
66          }
67      }
68  }