001/*
002 * Copyright (C) 2009 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.io;
016
017import com.google.common.annotations.GwtIncompatible;
018import com.google.errorprone.annotations.CanIgnoreReturnValue;
019import java.io.DataInput;
020import java.io.IOException;
021import javax.annotation.CheckForNull;
022
023/**
024 * An extension of {@code DataInput} for reading from in-memory byte arrays; its methods offer
025 * identical functionality but do not throw {@link IOException}.
026 *
027 * <p><b>Warning:</b> The caller is responsible for not attempting to read past the end of the
028 * array. If any method encounters the end of the array prematurely, it throws {@link
029 * IllegalStateException} to signify <i>programmer error</i>. This behavior is a technical violation
030 * of the supertype's contract, which specifies a checked exception.
031 *
032 * @author Kevin Bourrillion
033 * @since 1.0
034 */
035@GwtIncompatible
036@ElementTypesAreNonnullByDefault
037public interface ByteArrayDataInput extends DataInput {
038  @Override
039  void readFully(byte b[]);
040
041  @Override
042  void readFully(byte b[], int off, int len);
043
044  // not guaranteed to skip n bytes so result should NOT be ignored
045  // use ByteStreams.skipFully or one of the read methods instead
046  @Override
047  int skipBytes(int n);
048
049  @CanIgnoreReturnValue // to skip a byte
050  @Override
051  boolean readBoolean();
052
053  @CanIgnoreReturnValue // to skip a byte
054  @Override
055  byte readByte();
056
057  @CanIgnoreReturnValue // to skip a byte
058  @Override
059  int readUnsignedByte();
060
061  @CanIgnoreReturnValue // to skip some bytes
062  @Override
063  short readShort();
064
065  @CanIgnoreReturnValue // to skip some bytes
066  @Override
067  int readUnsignedShort();
068
069  @CanIgnoreReturnValue // to skip some bytes
070  @Override
071  char readChar();
072
073  @CanIgnoreReturnValue // to skip some bytes
074  @Override
075  int readInt();
076
077  @CanIgnoreReturnValue // to skip some bytes
078  @Override
079  long readLong();
080
081  @CanIgnoreReturnValue // to skip some bytes
082  @Override
083  float readFloat();
084
085  @CanIgnoreReturnValue // to skip some bytes
086  @Override
087  double readDouble();
088
089  @CanIgnoreReturnValue // to skip a line
090  @Override
091  @CheckForNull
092  String readLine();
093
094  @CanIgnoreReturnValue // to skip a field
095  @Override
096  String readUTF();
097}