@Override
	public void parse(InputStream in) throws FormatNotUnderstoodException {
		// read xls
	
			try {
				this.currentWorkbook=WorkbookFactory.create(in,this.hocr.getPassword());
			} catch (EncryptedDocumentException  | IOException e) {
				LOG.error(e);
				throw new FormatNotUnderstoodException(e.toString());
			} finally 
			{
				if (this.in!=null) {
					try {
						this.in.close();
					} catch (IOException e) {
						LOG.error(e);
					}
				}
			}
			// check if signature should be verified
			if (this.hocr.getVerifySignature()) {
				LOG.info("Verifying signature of document");
				if (!(this.currentWorkbook instanceof XSSFWorkbook)) {
					throw new FormatNotUnderstoodException("Can only verify signatures for files using the OOXML (.xlsx) format");
				} else {
					//
					OPCPackage pgk = ((XSSFWorkbook)this.currentWorkbook).getPackage();
					SignatureConfig sic = new SignatureConfig();
					sic.setOpcPackage(pgk);
					SignatureInfo si = new SignatureInfo();
					si.setSignatureConfig(sic);
					if (!si.verifySignature()) {
						throw new FormatNotUnderstoodException("Cannot verify signature of OOXML (.xlsx) file: "+this.hocr.getFileName());
					} else {
						LOG.info("Successfully verifed first part signature of OXXML (.xlsx) file: "+this.hocr.getFileName());
					}
					 Iterator<SignaturePart> spIter = si.getSignatureParts().iterator();
					 while (spIter.hasNext()) {
						 SignaturePart currentSP = spIter.next();
						 if (!(currentSP.validate())) {
							 throw new FormatNotUnderstoodException("Could not validate all signature parts for file: "+this.hocr.getFileName());
						 } else {
							 X509Certificate currentCertificate = currentSP.getSigner();
							 try {
								if ((this.hocr.getX509CertificateChain().size()>0) && (!CertificateChainVerificationUtil.verifyCertificateChain(currentCertificate, this.hocr.getX509CertificateChain()))) {
									 throw new FormatNotUnderstoodException("Could not validate signature part for principal \""+currentCertificate.getSubjectX500Principal().getName()+"\" : "+this.hocr.getFileName());
								 }
							} catch (CertificateException | NoSuchAlgorithmException | NoSuchProviderException
									| InvalidAlgorithmParameterException e) {
								LOG.error("Could not validate signature part for principal \""+currentCertificate.getSubjectX500Principal().getName()+"\" : "+this.hocr.getFileName(), e);
								 throw new FormatNotUnderstoodException("Could not validate signature part for principal \""+currentCertificate.getSubjectX500Principal().getName()+"\" : "+this.hocr.getFileName());
									
							}
						 }
					 }
					 LOG.info("Successfully verifed all signatures of OXXML (.xlsx) file: "+this.hocr.getFileName());
				}
			}
		// formulaEvaluator
		 this.formulaEvaluator = this.currentWorkbook.getCreationHelper().createFormulaEvaluator();
		  // add the formulator evaluator of this file as well or we will see a strange Exception
		 this.addedFormulaEvaluators.put(this.hocr.getFileName(),this.formulaEvaluator);
		 this.formulaEvaluator.setIgnoreMissingWorkbooks(this.hocr.getIgnoreMissingLinkedWorkbooks());
		 this.filtered=this.checkFiltered();
		 this.currentRow=0;
		 if (this.sheets==null) {
			this.currentSheetName=this.currentWorkbook.getSheetAt(0).getSheetName();
		 } else if (sheets.length<1) {
			throw new FormatNotUnderstoodException("Error: no sheets selected");
		 } else  {
			this.currentSheetName=sheets[0];
		 }
		 // check skipping of additional lines
		 this.currentRow+=this.hocr.getSkipLines();
		 // check header
		 if (this.hocr.getReadHeader()) {
			
			 LOG.debug("Reading header...");
			 Object[] firstRow = this.getNext();
			 if (firstRow!=null) {
				 this.header=new String[firstRow.length];
				 for (int i=0;i<firstRow.length;i++) {
					 if ((firstRow[i]!=null) && (!"".equals(((SpreadSheetCellDAO)firstRow[i]).getFormattedValue()))) {
						 this.header[i]=((SpreadSheetCellDAO)firstRow[i]).getFormattedValue();
					 }
				 }
				 this.header=MSExcelParser.sanitizeHeaders(this.header, this.hocr.getColumnNameRegex(), this.hocr.getColumnNameReplace());
			 } else {
				 this.header=new String[0];
			 }
		 }

	
	}
@ Override public void parse ( InputStream in ) throws FormatNotUnderstoodException { try { this . currentWorkbook = WorkbookFactory . create ( in , this . hocr . getPassword ( ) ) ; } catch ( EncryptedDocumentException | IOException e ) { LOG . error ( e ) ; throw new FormatNotUnderstoodException ( e . toString ( ) ) ; } finally { if ( this . in != null ) { try { this . in . close ( ) ; } catch ( IOException e ) { LOG . error ( e ) ; } } } if ( this . hocr . getVerifySignature ( ) ) { LOG . info ( "Verifying signature of document" ) ; if ( ! ( this . currentWorkbook instanceof XSSFWorkbook ) ) { throw new FormatNotUnderstoodException ( "Can only verify signatures for files using the OOXML (.xlsx) format" ) ; } else { OPCPackage pgk = ( ( XSSFWorkbook ) this . currentWorkbook ) . getPackage ( ) ; SignatureConfig sic = new SignatureConfig ( ) ; sic . setOpcPackage ( pgk ) ; SignatureInfo si = new SignatureInfo ( ) ; si . setSignatureConfig ( sic ) ; if ( ! si . verifySignature ( ) ) { throw new FormatNotUnderstoodException ( "Cannot verify signature of OOXML (.xlsx) file: " + this . hocr . getFileName ( ) ) ; } else { LOG . info ( "Successfully verifed first part signature of OXXML (.xlsx) file: " + this . hocr . getFileName ( ) ) ; } Iterator < SignaturePart > spIter = si . getSignatureParts ( ) . iterator ( ) ; while ( spIter . hasNext ( ) ) { SignaturePart currentSP = spIter . next ( ) ; if ( ! ( currentSP . validate ( ) ) ) { throw new FormatNotUnderstoodException ( "Could not validate all signature parts for file: " + this . hocr . getFileName ( ) ) ; } else { X509Certificate currentCertificate = currentSP . getSigner ( ) ; try { if ( ( this . hocr . getX509CertificateChain ( ) . size ( ) > 0 ) && ( ! CertificateChainVerificationUtil . verifyCertificateChain ( currentCertificate , this . hocr . getX509CertificateChain ( ) ) ) ) { throw new FormatNotUnderstoodException ( "Could not validate signature part for principal \"" + currentCertificate . getSubjectX500Principal ( ) . getName ( ) + "\" : " + this . hocr . getFileName ( ) ) ; } } catch ( CertificateException | NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException e ) { LOG . error ( "Could not validate signature part for principal \"" + currentCertificate . getSubjectX500Principal ( ) . getName ( ) + "\" : " + this . hocr . getFileName ( ) , e ) ; throw new FormatNotUnderstoodException ( "Could not validate signature part for principal \"" + currentCertificate . getSubjectX500Principal ( ) . getName ( ) + "\" : " + this . hocr . getFileName ( ) ) ; } } } LOG . info ( "Successfully verifed all signatures of OXXML (.xlsx) file: " + this . hocr . getFileName ( ) ) ; } } this . formulaEvaluator = this . currentWorkbook . getCreationHelper ( ) . createFormulaEvaluator ( ) ; this . addedFormulaEvaluators . put ( this . hocr . getFileName ( ) , this . formulaEvaluator ) ; this . formulaEvaluator . setIgnoreMissingWorkbooks ( this . hocr . getIgnoreMissingLinkedWorkbooks ( ) ) ; this . filtered = this . checkFiltered ( ) ; this . currentRow = 0 ; if ( this . sheets == null ) { this . currentSheetName = this . currentWorkbook . getSheetAt ( 0 ) . getSheetName ( ) ; } else if ( sheets . length < 1 ) { throw new FormatNotUnderstoodException ( "Error: no sheets selected" ) ; } else { this . currentSheetName = sheets [ 0 ] ; } this . currentRow += this . hocr . getSkipLines ( ) ; if ( this . hocr . getReadHeader ( ) ) { LOG . debug ( "Reading header..." ) ; Object [ ] firstRow = this . getNext ( ) ; if ( firstRow != null ) { this . header = new String [ firstRow . length ] ; for ( int i = 0 ; i < firstRow . length ; i ++ ) { if ( ( firstRow [ i ] != null ) && ( ! "" . equals ( ( ( SpreadSheetCellDAO ) firstRow [ i ] ) . getFormattedValue ( ) ) ) ) { this . header [ i ] = ( ( SpreadSheetCellDAO ) firstRow [ i ] ) . getFormattedValue ( ) ; } } this . header = MSExcelParser . sanitizeHeaders ( this . header , this . hocr . getColumnNameRegex ( ) , this . hocr . getColumnNameReplace ( ) ) ; } else { this . header = new String [ 0 ] ; } } }
/*

Parses the given InputStream containing Excel data. The type of InputStream (e.g. FileInputStream, BufferedInputStream etc.) does not matter here, but it is recommended to use an appropriate
type to avoid performance issues.

@param in InputStream containing Excel data

@throws org.zuinnote.hadoop.office.format.common.parser.FormatNotUnderstoodException in case there are issues reading from the Excel file, e.g. wrong password or unknown format