class XlsUtils {

    public static int getColumnsNumber(InputStream inputStream) throws XMLStreamException, IOException {
        // If doesn't support mark, wrap up
        if (!inputStream.markSupported()) {
            inputStream = new PushbackInputStream(inputStream, 8);
        }

        int colNumber = 0;

        // TDP-1781 xlsx files may not containing dimension so we fallback to col element number

        XMLStreamReader streamReader = XML_INPUT_FACTORY.createXMLStreamReader(inputStream);
        try {
            while (streamReader.hasNext()) {
                switch (streamReader.next()) {
                case START_ELEMENT:
                    if (StringUtils.equals(streamReader.getLocalName(), "dimension")) {
                        Map<String, String> attributesValues = getAttributesNameValue(streamReader);
                        if (!attributesValues.isEmpty()) {
                            return getColumnsNumberFromDimension(attributesValues.get("ref"));
                        }
                    }
                    if (StringUtils.equals(streamReader.getLocalName(), "col")) {
                        colNumber++;
                    }
                    break;
                case END_ELEMENT:
                    if (StringUtils.equals(streamReader.getLocalName(), "cols")) {
                        return colNumber;
                    }
                default:
                    // no op
                }
            }
        } finally {
            if (streamReader != null) {
                streamReader.close();
            }
        }
        return -1;
    }

    private  XlsUtils();

}