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 javax.annotation.CheckForNull;
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
038@ElementTypesAreNonnullByDefault
039public interface ByteArrayDataInput extends DataInput {
040  @Override
041  void readFully(byte b[]);
042
043  @Override
044  void readFully(byte b[], int off, int len);
045
046  // not guaranteed to skip n bytes so result should NOT be ignored
047  // use ByteStreams.skipFully or one of the read methods instead
048  @Override
049  int skipBytes(int n);
050
051  @CanIgnoreReturnValue // to skip a byte
052  @Override
053  boolean readBoolean();
054
055  @CanIgnoreReturnValue // to skip a byte
056  @Override
057  byte readByte();
058
059  @CanIgnoreReturnValue // to skip a byte
060  @Override
061  int readUnsignedByte();
062
063  @CanIgnoreReturnValue // to skip some bytes
064  @Override
065  short readShort();
066
067  @CanIgnoreReturnValue // to skip some bytes
068  @Override
069  int readUnsignedShort();
070
071  @CanIgnoreReturnValue // to skip some bytes
072  @Override
073  char readChar();
074
075  @CanIgnoreReturnValue // to skip some bytes
076  @Override
077  int readInt();
078
079  @CanIgnoreReturnValue // to skip some bytes
080  @Override
081  long readLong();
082
083  @CanIgnoreReturnValue // to skip some bytes
084  @Override
085  float readFloat();
086
087  @CanIgnoreReturnValue // to skip some bytes
088  @Override
089  double readDouble();
090
091  @CanIgnoreReturnValue // to skip a line
092  @Override
093  @CheckForNull
094  String readLine();
095
096  @CanIgnoreReturnValue // to skip a field
097  @Override
098  String readUTF();
099}