PcapGlobalHeader { public void write(final OutputStream out) throws IOException { if (this.nsTimestamps) { if (this.byteOrder == ByteOrder.BIG_ENDIAN) { out.write(MAGIC_NSEC); } else { out.write(MAGIC_NSEC_SWAPPED); } } else { if (this.byteOrder == ByteOrder.BIG_ENDIAN) { out.write(MAGIC_BIG_ENDIAN); } else { out.write(MAGIC_LITTLE_ENDIAN); } } out.write(this.body); } PcapGlobalHeader(final ByteOrder byteOrder, final byte[] body);  PcapGlobalHeader(final ByteOrder byteOrder, final byte[] body, final boolean nsTimestamps); static PcapGlobalHeader createDefaultHeader(); static PcapGlobalHeader createDefaultHeader(Protocol protocol); ByteOrder getByteOrder(); boolean timestampsInNs(); int getMajorVersion(); int getMinorVersion(); int getTimeAccuracy(); long getTimeZoneCorrection(); long getSnapLength(); int getDataLinkType(); static final int getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder); static final long getUnsignedInt(final int offset, final byte[] buffer, final ByteOrder byteOrder); static final int getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder); static final PcapGlobalHeader parse(final Buffer in); void write(final OutputStream out); @Override String toString(); static long unsignedInt(final byte a, final byte b, final byte c, final byte d); static final int SIZE; static final byte[] MAGIC_BIG_ENDIAN; static final byte[] MAGIC_LITTLE_ENDIAN; static final byte[] MAGIC_NGPCAP; static final byte[] MAGIC_NSEC; static final byte[] MAGIC_NSEC_SWAPPED; static final byte[] MAGIC_MODIFIED; static final byte[] MAGIC_MODIFIED_SWAPPED; }
@Test public void littleEndianMicrosecondsHeader() throws IOException { final byte[] body = getDummyBody(); PcapGlobalHeader header = new PcapGlobalHeader(ByteOrder.LITTLE_ENDIAN, body, false); ByteArrayOutputStream os = new ByteArrayOutputStream(); header.write(os); assertArrayEquals(Arrays.copyOf(os.toByteArray(), 4), MAGIC_LITTLE_ENDIAN); }
@Test public void bigEndianMicrosecondsHeader() throws IOException { final byte[] body = getDummyBody(); PcapGlobalHeader header = new PcapGlobalHeader(ByteOrder.BIG_ENDIAN, body, false); ByteArrayOutputStream os = new ByteArrayOutputStream(); header.write(os); assertArrayEquals(Arrays.copyOf(os.toByteArray(), 4), MAGIC_BIG_ENDIAN); }
@Test public void littleEndianNanosecondsHeader() throws IOException { final byte[] body = getDummyBody(); PcapGlobalHeader header = new PcapGlobalHeader(ByteOrder.LITTLE_ENDIAN, body, true); ByteArrayOutputStream os = new ByteArrayOutputStream(); header.write(os); assertArrayEquals(Arrays.copyOf(os.toByteArray(), 4), MAGIC_NSEC_SWAPPED); }
@Test public void bigEndianNanosecondsHeader() throws IOException { final byte[] body = getDummyBody(); PcapGlobalHeader header = new PcapGlobalHeader(ByteOrder.BIG_ENDIAN, body, true); ByteArrayOutputStream os = new ByteArrayOutputStream(); header.write(os); assertArrayEquals(Arrays.copyOf(os.toByteArray(), 4), MAGIC_NSEC); }