private static int readFileHeader(final InputStream is) throws IOException, ImagingException {
        final byte[] buffer = new byte[4];
        if (is.read(buffer) < 4 || !WebPConstants.RIFF_SIGNATURE.equals(buffer)) {
            throw new ImagingException("Not a valid WebP file");
        }

        final int fileSize = read4Bytes("File Size", is, "Not a valid WebP file", ByteOrder.LITTLE_ENDIAN);
        if (fileSize < 0) {
            throw new ImagingException("File size is too long:" + fileSize);
        }

        if (is.read(buffer) < 4 || !WebPConstants.WEBP_SIGNATURE.equals(buffer)) {
            throw new ImagingException("Not a valid WebP file");
        }

        return fileSize;
    }
Reads the file header of WebP file.

@return file size in file header (including the WebP signature, excluding the TIFF signature and the file size field).
src/main/java/org/apache/commons/imaging/formats/webp/WebPImageParser.java