private static long bytesToLongBE(InputStream input, int n)
            throws IOException
    {
        long out = 0;
        long val;
        while (n > 0) {
            n--;
            // store it in a long and then shift else integer overflow will occur
            val = input.read();
            out |= (val << (n * 8));
        }
        return out;
    }
private static long bytesToLongBE ( InputStream input , int n ) throws IOException { long out = 0 ; long val ; while ( n > 0 ) { n -- ; val = input . read ( ) ; out |= ( val << ( n * 8 ) ) ; } return out ; }
Read n bytes in big endian order and convert to long.