/*
@see com.marklogic.contentpump.DocBuilder#checkDocumentHeader()
@throws IOException
766019
@Override
    public void configFields(Configuration conf, String[] fields) 
            throws IllegalArgumentException, IOException {
        if (null != fields) {
            super.configFields(conf, fields);
        } else {
            throw new IOException("Fields not defined");
        }
        
        datatypeMap = new HashMap<String,ColumnDataType>();
        for (String s: fields) {
            datatypeMap.put(s, ColumnDataType.STRING);
        }
        String list = conf.get(ConfigConstants.CONF_DELIMITED_DATA_TYPE);
        if (list == null) {
            return;
        }
        String pairs[] = list.split(",");
        for (int i = 0; i < pairs.length; i += 2) {
            String colName = pairs[i].trim();
            String colDataType = pairs[i+1].trim();
            if (!datatypeMap.containsKey(colName)) {
                throw new IllegalArgumentException("Column name " + colName + " not found.");
            }
            if ("Number".equalsIgnoreCase(colDataType)) {
                datatypeMap.put(colName, ColumnDataType.NUMBER);
            } else if ("Boolean".equalsIgnoreCase(colDataType)) {
                datatypeMap.put(colName, ColumnDataType.BOOLEAN);
            } else if (!"String".equalsIgnoreCase(colDataType)) {
                throw new IllegalArgumentException("Unsupported column data type " + colDataType);
            }
        }
    }
1110832
private boolean goToNextDoc() throws IOException {
    reset();
    if (docId == NO_MORE_DOCS) {
      minPosition = NO_MORE_POSITIONS;
      maxPosition = NO_MORE_POSITIONS;
      return true;
    } else {
      docId = subSpans.nextDoc();
      if (docId == NO_MORE_DOCS) {
        minPosition = NO_MORE_POSITIONS;
        maxPosition = NO_MORE_POSITIONS;
        return true;
      } else {
        IndexDoc doc = mtasCodecInfo.getDoc(field, docId);
        if (doc != null) {
          minPosition = doc.minPosition;
          maxPosition = doc.maxPosition;
        } else {
          minPosition = NO_MORE_POSITIONS;
          maxPosition = NO_MORE_POSITIONS;
        }
        if (goToNextStartPosition()) {
          return true;
        } else {
          return false;
        }
      }
    }
  }
1373514
public void writeHeader(Writer writer) throws IOException
    {
        if (_state != __MSG_EDITABLE) throw new IllegalStateException("Not MSG_EDITABLE");

        _state = __MSG_BAD;
        writeRequestLine(writer);
        writer.write(HttpFields.__CRLF);
        _header.write(writer);
        _state = __MSG_SENDING;
    }
1139109
public void writeHeader(Writer writer) 
        throws IOException
    {
        if (_state!=__MSG_EDITABLE)
            throw new IllegalStateException(__state[_state]+
                                            " is not EDITABLE");
        if (_header==null)
            throw new IllegalStateException("Response is destroyed");

        if (getHttpRequest().getDotVersion()>=0)
        {
            _state=__MSG_BAD;
            writer.write(_version);
            writer.write(' ');
            writer.write('0'+((_status/100)%10));
            writer.write('0'+((_status/10)%10));
            writer.write('0'+(_status%10));
            writer.write(' ');
            writer.write(getReason());
            writer.write(HttpFields.__CRLF);
            _header.write(writer);
        }
        _state=__MSG_SENDING;
    }
1193422
private void checkInclusion()
        throws XMLStreamException
    {
        String keyword;

        // INCLUDE/IGNORE not allowed in internal subset...
        /* 18-Jul-2004, TSa: Except if it's in an expanded parsed external
         *   entity...
         */
        if (!mIsExternal && mInput == mRootInput) {
            _reportWFCViolation("Internal DTD subset can not use (INCLUDE/IGNORE) directives (except via external entities)");
        }

        char c = skipDtdWs(true);
        if (c != 'I') {
            // let's obtain the keyword for error reporting purposes:
            keyword = readDTDKeyword(String.valueOf(c));
        } else {
            c = dtdNextFromCurr();
            if (c == 'G') {
                keyword = checkDTDKeyword("NORE");
                if (keyword == null) {
                    handleIgnored();
                    return;
                }
                keyword = "IG"+keyword;
            } else if (c == 'N') {
                keyword = checkDTDKeyword("CLUDE");
                if (keyword == null) {
                    handleIncluded();
                    return;
                }
                keyword = "IN"+keyword;
            } else {
                --mInputPtr;
                keyword = readDTDKeyword("I");
            }
        }

        // If we get here, it was an error...
        _reportWFCViolation("Unrecognized directive '"+keyword+"'; expected either 'IGNORE' or 'INCLUDE'");
    }
477482
@Override
  public void readHeader(byte[] data) {
    if(ByteArrayUtil.readInt(data, 0) != FILE_VERSION) {
      throw new RuntimeException("PersistentPageFile version does not match!");
    }

    this.pageSize = ByteArrayUtil.readInt(data, 4);
  }
671302
public String readHeader()
        throws IOException
    {
        int tag = read();

        if (tag == 'H') {
            _isLastChunk = true;
            _chunkLength = (read() << 8) + read();

            _sbuf.setLength(0);
            int ch;
            while ((ch = parseChar()) >= 0)
                _sbuf.append((char) ch);

            return _sbuf.toString();
        }

        _peek = tag;

        return null;
    }
977792
public void writeHeader(OutputStreamCounter os) throws IOException {
		if (appendmode) {
			os.write(HEADER[0]);
		}
		else {
			os.write(HEADER[1]);
			os.write(getVersionAsByteArray(header_version));
			os.write(HEADER[2]);
			headerWasWritten = true;
		}
	}
450616
protected void validateHeader(final String[] sourceHeader, final String[] definedHeader) {
        
        // check column size.
        if(sourceHeader.length != definedHeader.length) {
            final CsvContext context = new CsvContext(1, 1, 1);
            throw new SuperCsvNoMatchColumnSizeException(sourceHeader.length, definedHeader.length, context);
            
        }
        
        // check header value
        for(int i=0; i < sourceHeader.length; i++) {
            if(!sourceHeader[i].equals(definedHeader[i])) {
                final CsvContext context = new CsvContext(1, 1, i+1);
                throw new SuperCsvNoMatchHeaderException(sourceHeader, definedHeader, context);
            }
        }
        
    }
1275702
public void resetHeader() {
        this.header = null;
        DocListener listener;
		for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
            listener = (DocListener) iterator.next();
            listener.resetHeader();
        }
    }
958676
void readHeader() throws IOException {
    int version = in.readInt();
    if (version != BlockCrcInfoWritable.LATEST_BLOCK_CRC_FILE_VERSION) {
      throw new IOException("Version " + version + " is not supported.");
    }
    numBuckets = in.readInt();
    currentBucket = -1;
    numRecordsReadInBucket = 0;
    numRecordsInBucket = 0;    
  }
699073
static BlockMetadataHeader readHeader(File file) throws IOException {
    DataInputStream in = null;
    try {
      in = new DataInputStream(new BufferedInputStream(
                               new FileInputStream(file)));
      return readHeader(in);
    } finally {
      IOUtils.closeStream(in);
    }
  }
241437
private static void copyHeader(
		final Document doc,
		final Document ndoc) {
		NodeList headnl = doc.getElementsByTagName("head");

		if (headnl.getLength() > 0) {
			Element head = (Element) headnl.item(0);
			ndoc.getDocumentElement()
					.insertBefore(ndoc.adoptNode(head.cloneNode(true)),
					ndoc.getDocumentElement().getFirstChild());
		} // end if
	}
237122
private static boolean checkHeader(InputStream input, int[] header) throws IOException
    {
        for (final int b : header)
        {
            if (b != input.read())
            {
                return false;
            }
        }
        return true;
    }
151038
private boolean goToNextDoc() throws IOException {
    if (docId == NO_MORE_DOCS) {
      return true;
    } else {
      docId = spans1.spans.nextDoc();
      if (docId == NO_MORE_DOCS) {
        return true;
      } else {
        int spans2DocId = spans2.spans.docID();
        if (spans2DocId < docId) {
          spans2DocId = spans2.spans.advance(docId);
        }
        if (docId != spans2DocId) {
          return spans1.spans.nextStartPosition() != NO_MORE_POSITIONS;
        } else if (goToNextStartPosition()) {
          return true;
        } else {
          reset();
          return false;
        }
      }
    }
  }
418077
private void writeHeader(final String dtd) throws IOException {
    if (forHtml){
      wtr.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
      return;
    }
    
    wtr.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");

    if (dtd == null) {
      return;
    }

    wtr.write("<!DOCTYPE properties SYSTEM \"");
    wtr.write(dtd);
    wtr.write("\">\n");
  }
201595
public void writeHeader() throws IOException, ConverterException {
        if (append) {
            return;
        }
        try {
            CompoundTag ebml = TagFactory.<CompoundTag> create("EBML").add(TagFactory.<UnsignedIntegerTag> create("EBMLVersion").setValue(1)).add(TagFactory.<UnsignedIntegerTag> create("EBMLReadVersion").setValue(1)).add(TagFactory.<UnsignedIntegerTag> create("EBMLMaxIDLength").setValue(4)).add(TagFactory.<UnsignedIntegerTag> create("EBMLMaxSizeLength").setValue(8))
                    .add(TagFactory.<StringTag> create("DocType").setValue("webm")).add(TagFactory.<UnsignedIntegerTag> create("DocTypeVersion").setValue(3)).add(TagFactory.<UnsignedIntegerTag> create("DocTypeReadVersion").setValue(2));
            byte[] hb = ebml.encode();
            bytesWritten += hb.length;
            dataFile.write(hb);
        } catch (IOException | ConverterException e) {
            log.error("Failed to write header", e);
            throw e;
        }
    }