private int readFixnumBody(int nBytes, final boolean shouldBeNegative)
          throws IOException {
    if (trace == API_TRACE_DETAILED) {
      debugNote("readFixnumBody isNegative=" + shouldBeNegative + " length=" + nBytes);
    }

    if (nBytes > 4) {
      throw new ArithmeticException("Cannot fit " + nBytes + " bytes into an int");
    }

    int num = 0;

    for (int i = 0; i < nBytes; i++) {
      int j = read();

      if (trace == API_TRACE_DETAILED) {
        debugNote("\t" + j);
      }

      num |= (j << (8 * i));
    }

    // num should always be positive here.  Negatives indicate overflows.
    if (num < 0) {
      throw new ArithmeticException("Overflow: " + ((long) num & 0xFFFFFFFFL)
              + " does not fit into an int");
    }

    return (shouldBeNegative) ? (-num) : num;

  }