View Javadoc
1   /*
2    * Copyright (C) 2009 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  
15  package com.google.common.io;
16  
17  import com.google.common.annotations.GwtIncompatible;
18  import com.google.errorprone.annotations.CanIgnoreReturnValue;
19  import java.io.DataInput;
20  import java.io.IOException;
21  
22  /**
23   * An extension of {@code DataInput} for reading from in-memory byte arrays; its methods offer
24   * identical functionality but do not throw {@link IOException}.
25   *
26   * <p><b>Warning:</b> The caller is responsible for not attempting to read past the end of the
27   * array. If any method encounters the end of the array prematurely, it throws
28   * {@link IllegalStateException} to signify <i>programmer error</i>. This behavior is a technical
29   * violation of the supertype's contract, which specifies a checked exception.
30   *
31   * @author Kevin Bourrillion
32   * @since 1.0
33   */
34  @GwtIncompatible
35  public interface ByteArrayDataInput extends DataInput {
36    @Override
37    void readFully(byte b[]);
38  
39    @Override
40    void readFully(byte b[], int off, int len);
41  
42    // not guaranteed to skip n bytes so result should NOT be ignored
43    // use ByteStreams.skipFully or one of the read methods instead
44    @Override
45    int skipBytes(int n);
46  
47    @CanIgnoreReturnValue // to skip a byte
48    @Override
49    boolean readBoolean();
50  
51    @CanIgnoreReturnValue // to skip a byte
52    @Override
53    byte readByte();
54  
55    @CanIgnoreReturnValue // to skip a byte
56    @Override
57    int readUnsignedByte();
58  
59    @CanIgnoreReturnValue // to skip some bytes
60    @Override
61    short readShort();
62  
63    @CanIgnoreReturnValue // to skip some bytes
64    @Override
65    int readUnsignedShort();
66  
67    @CanIgnoreReturnValue // to skip some bytes
68    @Override
69    char readChar();
70  
71    @CanIgnoreReturnValue // to skip some bytes
72    @Override
73    int readInt();
74  
75    @CanIgnoreReturnValue // to skip some bytes
76    @Override
77    long readLong();
78  
79    @CanIgnoreReturnValue // to skip some bytes
80    @Override
81    float readFloat();
82  
83    @CanIgnoreReturnValue // to skip some bytes
84    @Override
85    double readDouble();
86  
87    @CanIgnoreReturnValue // to skip a line
88    @Override
89    String readLine();
90  
91    @CanIgnoreReturnValue // to skip a field
92    @Override
93    String readUTF();
94  }