This project has retired. For details please refer to its Attic page.
ExtendedByteArrayDataInput xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.giraph.utils;
19  
20  import java.io.ByteArrayInputStream;
21  import java.io.DataInput;
22  import java.io.DataInputStream;
23  import java.io.IOException;
24  
25  /**
26   * Provides access to a internals of ByteArrayInputStream
27   */
28  public class ExtendedByteArrayDataInput extends ByteArrayInputStream
29    implements ExtendedDataInput {
30    /** Internal data input */
31    private final DataInput dataInput;
32    /**
33     * Constructor
34     *
35     * @param buf Buffer to read
36     */
37    public ExtendedByteArrayDataInput(byte[] buf) {
38      super(buf);
39      dataInput = new DataInputStream(this);
40    }
41  
42    /**
43     * Get access to portion of a byte array
44     *
45     * @param buf Byte array to access
46     * @param offset Offset into the byte array
47     * @param length Length to read
48     */
49    public ExtendedByteArrayDataInput(byte[] buf, int offset, int length) {
50      super(buf, offset, length);
51      dataInput = new DataInputStream(this);
52    }
53  
54    @Override
55    public int getPos() {
56      return pos;
57    }
58  
59    @Override
60    public boolean endOfInput() {
61      return available() == 0;
62    }
63  
64    @Override
65    public void readFully(byte[] b) throws IOException {
66      dataInput.readFully(b);
67    }
68  
69    @Override
70    public void readFully(byte[] b, int off, int len) throws IOException {
71      dataInput.readFully(b, off, len);
72    }
73  
74    @Override
75    public int skipBytes(int n) throws IOException {
76      return dataInput.skipBytes(n);
77    }
78  
79    @Override
80    public boolean readBoolean() throws IOException {
81      return dataInput.readBoolean();
82    }
83  
84    @Override
85    public byte readByte() throws IOException {
86      return dataInput.readByte();
87    }
88  
89    @Override
90    public int readUnsignedByte() throws IOException {
91      return dataInput.readUnsignedByte();
92    }
93  
94    @Override
95    public short readShort() throws IOException {
96      return dataInput.readShort();
97    }
98  
99    @Override
100   public int readUnsignedShort() throws IOException {
101     return dataInput.readUnsignedShort();
102   }
103 
104   @Override
105   public char readChar() throws IOException {
106     return dataInput.readChar();
107   }
108 
109   @Override
110   public int readInt() throws IOException {
111     return dataInput.readInt();
112   }
113 
114   @Override
115   public long readLong() throws IOException {
116     return dataInput.readLong();
117   }
118 
119   @Override
120   public float readFloat() throws IOException {
121     return dataInput.readFloat();
122   }
123 
124   @Override
125   public double readDouble() throws IOException {
126     return dataInput.readDouble();
127   }
128 
129   @Override
130   public String readLine() throws IOException {
131     return dataInput.readLine();
132   }
133 
134   @Override
135   public String readUTF() throws IOException {
136     return dataInput.readUTF();
137   }
138 }