bufr/src/main/java/ucar/nc2/ft/point/bufr/BufrCdmIndex.java
private boolean writeIndex2(String bufrFilename, BufrConfig config, File indexFile) throws IOException {
    if (indexFile.exists()) {
      if (!indexFile.delete())
        log.warn(" BufrCdmIndex cant delete index file {}", indexFile.getPath());
    }
    log.debug(" createIndex for {}", indexFile.getPath());

    try (RandomAccessFile raf = new RandomAccessFile(indexFile.getPath(), "rw")) {
      raf.order(RandomAccessFile.BIG_ENDIAN);
      //// header message
      raf.write(MAGIC_START.getBytes(CDM.utf8Charset));
      raf.writeInt(version);

      // build it
      BufrCdmIndexProto.BufrIndex.Builder indexBuilder = BufrCdmIndexProto.BufrIndex.newBuilder();
      indexBuilder.setFilename(bufrFilename);
      root = buildField(config.getRootConverter());
      indexBuilder.setRoot(root);
      indexBuilder.setStart(config.getStart());
      indexBuilder.setEnd(config.getEnd());
      indexBuilder.setNobs(config.getNobs());

      Map<String,BufrConfig.BufrStation> smaps = config.getStationMap();
      if (smaps != null) {
        List<BufrConfig.BufrStation> stations = new ArrayList<BufrConfig.BufrStation>(smaps.values());
        Collections.sort(stations);
        for (BufrConfig.BufrStation s : stations) {
          indexBuilder.addStations(buildStation(s));
        }
      }

      // write it
      BufrCdmIndexProto.BufrIndex index = indexBuilder.build();
      byte[] b = index.toByteArray();
      NcStream.writeVInt(raf, b.length); // message size
      raf.write(b);  // message  - all in one gulp

      log.debug("  file size =  %d bytes", raf.length());
      return true;
    }
  }
private boolean writeIndex2(String bufrFilename, BufrConfig config, File indexFile) throws IOException {
    if (indexFile.exists()) {
      if (!indexFile.delete())
        log.warn(" BufrCdmIndex cant delete index file {}", indexFile.getPath());
    }
    log.debug(" createIndex for {}", indexFile.getPath());

    try (RandomAccessFile raf = new RandomAccessFile(indexFile.getPath(), "rw")) {
      raf.order(RandomAccessFile.BIG_ENDIAN);
      //// header message
      raf.write(MAGIC_START.getBytes(CDM.utf8Charset));
      raf.writeInt(version);

      // build it
      BufrCdmIndexProto.BufrIndex.Builder indexBuilder = BufrCdmIndexProto.BufrIndex.newBuilder();
      indexBuilder.setFilename(bufrFilename);
      root = buildField(config.getRootConverter());
      indexBuilder.setRoot(root);
      indexBuilder.setStart(config.getStart());
      indexBuilder.setEnd(config.getEnd());
      indexBuilder.setNobs(config.getNobs());

      Map<String,BufrConfig.BufrStation> smaps = config.getStationMap();
      if (smaps != null) {
        List<BufrConfig.BufrStation> stations = new ArrayList<BufrConfig.BufrStation>(smaps.values());
        Collections.sort(stations);
        for (BufrConfig.BufrStation s : stations) {
          indexBuilder.addStations(buildStation(s));
        }
      }

      // write it
      BufrCdmIndexProto.BufrIndex index = indexBuilder.build();
      byte[] b = index.toByteArray();
      NcStream.writeVInt(raf, b.length); // message size
      raf.write(b);  // message  - all in one gulp

      log.debug("  file size =  %d bytes", raf.length());
      return true;
    }
  }
private boolean writeIndex2 ( String bufrFilename , BufrConfig config , File indexFile ) throws IOException { if ( indexFile . exists ( ) ) { if ( ! indexFile . delete ( ) ) log . warn ( " BufrCdmIndex cant delete index file {}" , indexFile . getPath ( ) ) ; } log . debug ( " createIndex for {}" , indexFile . getPath ( ) ) ; try ( RandomAccessFile raf = new RandomAccessFile ( indexFile . getPath ( ) , "rw" ) ) { raf . order ( RandomAccessFile . BIG_ENDIAN ) ; //// header message raf . write ( MAGIC_START . getBytes ( CDM . utf8Charset ) ) ; raf . writeInt ( version ) ; // build it BufrCdmIndexProto . BufrIndex . Builder indexBuilder = BufrCdmIndexProto . BufrIndex . newBuilder ( ) ; indexBuilder . setFilename ( bufrFilename ) ; root = buildField ( config . getRootConverter ( ) ) ; indexBuilder . setRoot ( root ) ; indexBuilder . setStart ( config . getStart ( ) ) ; indexBuilder . setEnd ( config . getEnd ( ) ) ; indexBuilder . setNobs ( config . getNobs ( ) ) ; Map < String , BufrConfig . BufrStation > smaps = config . getStationMap ( ) ; if ( smaps != null ) { List < BufrConfig . BufrStation > stations = new ArrayList < BufrConfig . BufrStation > ( smaps . values ( ) ) ; Collections . sort ( stations ) ; for ( BufrConfig . BufrStation s : stations ) { indexBuilder . addStations ( buildStation ( s ) ) ; } } // write it BufrCdmIndexProto . BufrIndex index = indexBuilder . build ( ) ; byte [ ] b = index . toByteArray ( ) ; NcStream . writeVInt ( raf , b . length ) ; // message size raf . write ( b ) ; // message  - all in one gulp log . debug ( "  file size =  %d bytes" , raf . length ( ) ) ; return true ; } }
/*
MAGIC_START
version
sizeIndex
BufrCdmIndexProto (sizeIndex bytes)
/ * MAGIC_START version sizeIndex BufrCdmIndexProto ( sizeIndex bytes )