public static void convert(File pcapngInFile,File pcapOutFile) throws IOException {
  byte[] inputBytes=Files.readAllBytes(pcapngInFile.toPath());
  if (inputBytes[0] != 0x0A || inputBytes[1] != 0x0D || inputBytes[2] != 0x0D || inputBytes[3] != 0x0A) {
    throw new IOException("Pcapng file missing expected header");
  }
  PcapDecoder pcapNgDecoder=new PcapDecoder(inputBytes);
  int status=pcapNgDecoder.decode();
  if (status == DecoderStatus.SUCCESS_STATUS) {
    FileOutputStream fos=new FileOutputStream(pcapOutFile);
    try {
      fos.write(MAGIC_NUMBER);
      fos.write(VERSION);
      fos.write(TIMEZONE_OFFSET);
      fos.write(TIMING_ACCURACY);
      convert(pcapNgDecoder,fos);
    }
  finally {
      fos.close();
    }
  }
 else {
    throw new IOException("Unable to parse pcapng file");
  }
}

public static void convert ( File pcapngInFile , File pcapOutFile ) throws IOException { byte [ ] inputBytes = Files . readAllBytes ( pcapngInFile . toPath ( ) ) ; if ( inputBytes [ 0 ] != 0x0A || inputBytes [ 1 ] != 0x0D || inputBytes [ 2 ] != 0x0D || inputBytes [ 3 ] != 0x0A ) { throw new IOException ( "Pcapng file missing expected header" ) ; } PcapDecoder pcapNgDecoder = new PcapDecoder ( inputBytes ) ; int status = pcapNgDecoder . decode ( ) ; if ( status == DecoderStatus . SUCCESS_STATUS ) { FileOutputStream fos = new FileOutputStream ( pcapOutFile ) ; try { fos . write ( MAGIC_NUMBER ) ; fos . write ( VERSION ) ; fos . write ( TIMEZONE_OFFSET ) ; fos . write ( TIMING_ACCURACY ) ; convert ( pcapNgDecoder , fos ) ; } finally { fos . close ( ) ; } } else { throw new IOException ( "Unable to parse pcapng file" ) ; } }
converts the given pcapng formatted file into the older pcap format out writes the result to the given file .
