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.common.annotations.J2ktIncompatible;
019import com.google.errorprone.annotations.CanIgnoreReturnValue;
020import java.io.DataInput;
021import java.io.IOException;
022import org.jspecify.annotations.Nullable;
023
024/**
025 * An extension of {@code DataInput} for reading from in-memory byte arrays; its methods offer
026 * identical functionality but do not throw {@link IOException}.
027 *
028 * <p>To create an instance, use {@link ByteStreams#newDataInput(byte[])} or another overload of
029 * that method.
030 *
031 * <p><b>Warning:</b> The caller is responsible for not attempting to read past the end of the
032 * array. If any method encounters the end of the array prematurely, it throws {@link
033 * IllegalStateException} to signify <i>programmer error</i>. This behavior is a technical violation
034 * of the supertype's contract, which specifies a checked exception.
035 *
036 * @author Kevin Bourrillion
037 * @since 1.0
038 */
039@J2ktIncompatible
040@GwtIncompatible
041public interface ByteArrayDataInput extends DataInput {
042  @Override
043  void readFully(byte[] b);
044
045  @Override
046  void readFully(byte[] b, int off, int len);
047
048  // not guaranteed to skip n bytes so result should NOT be ignored
049  // use ByteStreams.skipFully or one of the read methods instead
050  @Override
051  int skipBytes(int n);
052
053  @CanIgnoreReturnValue // to skip a byte
054  @Override
055  boolean readBoolean();
056
057  @CanIgnoreReturnValue // to skip a byte
058  @Override
059  byte readByte();
060
061  @CanIgnoreReturnValue // to skip a byte
062  @Override
063  int readUnsignedByte();
064
065  @CanIgnoreReturnValue // to skip some bytes
066  @Override
067  short readShort();
068
069  @CanIgnoreReturnValue // to skip some bytes
070  @Override
071  int readUnsignedShort();
072
073  @CanIgnoreReturnValue // to skip some bytes
074  @Override
075  char readChar();
076
077  @CanIgnoreReturnValue // to skip some bytes
078  @Override
079  int readInt();
080
081  @CanIgnoreReturnValue // to skip some bytes
082  @Override
083  long readLong();
084
085  @CanIgnoreReturnValue // to skip some bytes
086  @Override
087  float readFloat();
088
089  @CanIgnoreReturnValue // to skip some bytes
090  @Override
091  double readDouble();
092
093  @CanIgnoreReturnValue // to skip a line
094  @Override
095  @Nullable String readLine();
096
097  @CanIgnoreReturnValue // to skip a field
098  @Override
099  String readUTF();
100}