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.checkerframework.checker.nullness.qual.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><b>Warning:</b> The caller is responsible for not attempting to read past the end of the
029 * array. If any method encounters the end of the array prematurely, it throws {@link
030 * IllegalStateException} to signify <i>programmer error</i>. This behavior is a technical violation
031 * of the supertype's contract, which specifies a checked exception.
032 *
033 * @author Kevin Bourrillion
034 * @since 1.0
035 */
036@J2ktIncompatible
037@GwtIncompatible
038public interface ByteArrayDataInput extends DataInput {
039  @Override
040  void readFully(byte b[]);
041
042  @Override
043  void readFully(byte b[], int off, int len);
044
045  // not guaranteed to skip n bytes so result should NOT be ignored
046  // use ByteStreams.skipFully or one of the read methods instead
047  @Override
048  int skipBytes(int n);
049
050  @CanIgnoreReturnValue // to skip a byte
051  @Override
052  boolean readBoolean();
053
054  @CanIgnoreReturnValue // to skip a byte
055  @Override
056  byte readByte();
057
058  @CanIgnoreReturnValue // to skip a byte
059  @Override
060  int readUnsignedByte();
061
062  @CanIgnoreReturnValue // to skip some bytes
063  @Override
064  short readShort();
065
066  @CanIgnoreReturnValue // to skip some bytes
067  @Override
068  int readUnsignedShort();
069
070  @CanIgnoreReturnValue // to skip some bytes
071  @Override
072  char readChar();
073
074  @CanIgnoreReturnValue // to skip some bytes
075  @Override
076  int readInt();
077
078  @CanIgnoreReturnValue // to skip some bytes
079  @Override
080  long readLong();
081
082  @CanIgnoreReturnValue // to skip some bytes
083  @Override
084  float readFloat();
085
086  @CanIgnoreReturnValue // to skip some bytes
087  @Override
088  double readDouble();
089
090  @CanIgnoreReturnValue // to skip a line
091  @Override
092  @Nullable String readLine();
093
094  @CanIgnoreReturnValue // to skip a field
095  @Override
096  String readUTF();
097}