public static long readLongBE(InputStream stream) throws IOException, BufferUnderrunException {
        int ch1 = stream.read();
        int ch2 = stream.read();
        int ch3 = stream.read();
        int ch4 = stream.read();
        int ch5 = stream.read();
        int ch6 = stream.read();
        int ch7 = stream.read();
        int ch8 = stream.read();
        if ((ch1 | ch2 | ch3 | ch4 | ch5 | ch6 | ch7 | ch8) < 0) {
            throw new BufferUnderrunException();
        }

        return ((long) ch1 << 56) + ((long) ch2 << 48) + ((long) ch3 << 40) + ((long) ch4 << 32) +
                ((long) ch5 << 24) + // cast to long to preserve bit 31 (sign bit for ints)
                (ch6 << 16) + (ch7 << 8) + (ch8);
    }
Get a NE long value from an InputStream

@param stream the InputStream from which the long is to be read
@return the long (64-bit) value
@throws IOException             will be propagated back to the caller
@throws BufferUnderrunException if the stream cannot provide enough bytes
tika-core/src/main/java/org/apache/tika/io/EndianUtils.java