// Path: src/main/java/be/fror/common/base/Preconditions.java
// public static <T> T checkNotNull(@Nullable T reference) {
//   if (reference != null) {
//     return reference;
//   } else {
//     throw new NullPointerException();
//   }
// }


import static be.fror.common.base.Preconditions.checkNotNull;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
  }

  public static byte[] readFully(InputStream in, byte[] bytes) throws IOException {
    return readFully(in, bytes, 0, bytes.length);
  }

  public static byte[] readFully(InputStream in, byte[] bytes, int off, int len) throws IOException {
    int read = read(in, bytes, off, len);
    if (read != len) {
      String message = String.format("reached end of stream after reading %d bytes; %d bytes expected", read, len);
      throw new EOFException(message);
    }
    return bytes;
  }

  public static int read(InputStream in, byte[] bytes, int off, int len)
      throws IOException {
    checkNotNull(in);
    checkNotNull(bytes);
    if (len < 0) {
      throw new IndexOutOfBoundsException("len is negative");
    }
    int total = 0;
    while (total < len) {
      int result = in.read(bytes, off + total, len - total);
      if (result == -1) {
        break;
      }
      total += result;
    }
// Path: src/main/java/be/fror/common/base/Preconditions.java
// public static <T> T checkNotNull(@Nullable T reference) {
//   if (reference != null) {
//     return reference;
//   } else {
//     throw new NullPointerException();
//   }
// }


// Path: src/main/java/be/fror/common/io/ByteStreams.java
import static be.fror.common.base.Preconditions.checkNotNull;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

  }

  public static byte[] readFully(InputStream in, byte[] bytes) throws IOException {
    return readFully(in, bytes, 0, bytes.length);
  }

  public static byte[] readFully(InputStream in, byte[] bytes, int off, int len) throws IOException {
    int read = read(in, bytes, off, len);
    if (read != len) {
      String message = String.format("reached end of stream after reading %d bytes; %d bytes expected", read, len);
      throw new EOFException(message);
    }
    return bytes;
  }

  public static int read(InputStream in, byte[] bytes, int off, int len)
      throws IOException {
    checkNotNull(in);
    checkNotNull(bytes);
    if (len < 0) {
      throw new IndexOutOfBoundsException("len is negative");
    }
    int total = 0;
    while (total < len) {
      int result = in.read(bytes, off + total, len - total);
      if (result == -1) {
        break;
      }
      total += result;
    }
    return total;