cdm/src/main/java/ucar/nc2/iosp/dmsp/DMSPHeader.java
private void readHeaderFromFile( ucar.unidata.io.RandomAccessFile raFile )
          throws IOException
  {
    long pos = 0;
    raFile.seek( pos );

    // Read in first record.
    this.headerSizeInBytes = raFile.length() > this.headerSizeInBytesGuess ?
                             this.headerSizeInBytesGuess : (int) raFile.length();
    byte[] b = new byte[this.headerSizeInBytes];
    if ( raFile.read(b) != this.headerSizeInBytes ) throw new IOException( "Invalid DMSP file: could not read first " + this.headerSizeInBytes + " bytes.");
    String fullHeader = new String( b, CDM.utf8Charset);
    // Make sure header starts with the proper item.
    if ( ! fullHeader.startsWith( HeaderInfoTitle.FILE_ID.toString() ) )
    {
      throw new IOException( "Invalid DMSP file: header does not start with \"" + HeaderInfoTitle.FILE_ID.toString() + "\"." );
    }
    // Make sure header contains end-of-header marker.
    int endOfHeaderIndex = fullHeader.indexOf( HeaderInfoTitle.END_HEADER.toString() );
    if ( endOfHeaderIndex == -1 )
    {
      throw new IOException( "Invalid DMSP file: header does not end with \"" + HeaderInfoTitle.END_HEADER.toString() + "\"." );
    }

    // Drop the end-of-header marker and the line feed ('\n') proceeding it.
    header = fullHeader.substring( 0, endOfHeaderIndex - 1 ).split( "\n" );

    int lineSeperatorIndex = 0;
    String curHeaderLine = null;
    String curHeaderTitle = null;
    String curHeaderValue = null;
    for (String aHeader : this.header) {
      curHeaderLine = aHeader.trim();
      lineSeperatorIndex = curHeaderLine.indexOf(':');
      if (lineSeperatorIndex == -1)
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no seperator <:>.");
      if (lineSeperatorIndex == 0)
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no title.");
      if (lineSeperatorIndex == curHeaderLine.length() - 1)
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no value.");

      curHeaderTitle = curHeaderLine.substring(0, lineSeperatorIndex).trim();
      curHeaderValue = curHeaderLine.substring(lineSeperatorIndex + 1).trim();
      if (curHeaderValue.equals(""))
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no value.");

      headerInfo.put(curHeaderTitle, curHeaderValue);
    }
  }
private void readHeaderFromFile( ucar.unidata.io.RandomAccessFile raFile )
          throws IOException
  {
    long pos = 0;
    raFile.seek( pos );

    // Read in first record.
    this.headerSizeInBytes = raFile.length() > this.headerSizeInBytesGuess ?
                             this.headerSizeInBytesGuess : (int) raFile.length();
    byte[] b = new byte[this.headerSizeInBytes];
    if ( raFile.read(b) != this.headerSizeInBytes ) throw new IOException( "Invalid DMSP file: could not read first " + this.headerSizeInBytes + " bytes.");
    String fullHeader = new String( b, CDM.utf8Charset);
    // Make sure header starts with the proper item.
    if ( ! fullHeader.startsWith( HeaderInfoTitle.FILE_ID.toString() ) )
    {
      throw new IOException( "Invalid DMSP file: header does not start with \"" + HeaderInfoTitle.FILE_ID.toString() + "\"." );
    }
    // Make sure header contains end-of-header marker.
    int endOfHeaderIndex = fullHeader.indexOf( HeaderInfoTitle.END_HEADER.toString() );
    if ( endOfHeaderIndex == -1 )
    {
      throw new IOException( "Invalid DMSP file: header does not end with \"" + HeaderInfoTitle.END_HEADER.toString() + "\"." );
    }

    // Drop the end-of-header marker and the line feed ('\n') proceeding it.
    header = fullHeader.substring( 0, endOfHeaderIndex - 1 ).split( "\n" );

    int lineSeperatorIndex = 0;
    String curHeaderLine = null;
    String curHeaderTitle = null;
    String curHeaderValue = null;
    for (String aHeader : this.header) {
      curHeaderLine = aHeader.trim();
      lineSeperatorIndex = curHeaderLine.indexOf(':');
      if (lineSeperatorIndex == -1)
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no seperator <:>.");
      if (lineSeperatorIndex == 0)
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no title.");
      if (lineSeperatorIndex == curHeaderLine.length() - 1)
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no value.");

      curHeaderTitle = curHeaderLine.substring(0, lineSeperatorIndex).trim();
      curHeaderValue = curHeaderLine.substring(lineSeperatorIndex + 1).trim();
      if (curHeaderValue.equals(""))
        throw new IOException("Invalid DMSP file: header line <" + curHeaderLine + "> contains no value.");

      headerInfo.put(curHeaderTitle, curHeaderValue);
    }
  }
Read the header information from the file into name/value pairs.

@param raFile - the file to be read.
@throws IOException if any problems reading the file (or validating the file).