The Format class serves as the interface between the calling program and the frames of the trace. The FormatProperties class enables you to set and retrieve properties that determine how the Format object behaves when it encounters information in the Frames of the trace.
Use the format class to read both the raw trace data and the trace data that you have already formatted by using the commtrace classes.
Use the Format class to parse and format the information in a trace, then send that formatted information to a file or a print device. Additionally, you might want to create a graphical front end that displays the information in a standalone application or within a browser. When you want to select only specific data, use the Format class to supply that information to your Java™ program. For example you could use the Format class to read IP addresses out of a trace and then use that data in your program.
The Format constructors accept arguments that represent unformatted data, such as an IFSFileInputStream object, a local file, or the binary trace file. To display a trace that you have already formatted, use the default Format constructor, then use Format.openIFSFile() or Format.openLclFile() to specify the formatted file that you want to display.
Example: Displaying a saved trace
Format fmt = new Format(); fmt.openLclFile("/path/to/file"); // Read the Prolog System.out.println(fmt.getRecFromFile()); // The total number of records in the trace TCP and non-TCP System.out.println("Total Records:" + fmt.getIntFromFile()); String rec; // Read in records until we reach the end. while((rec = fmt.getRecFromFile())!=null) { System.out.println(rec);
Example: Formatting a binary trace
// Create a FormatProperties. By default display everything. FormatProperties fmtprop = new FormatProperties(); Format fmt = new Format("/path/to/file"); // Sets the filtering properties for this format fmt.setFilterProperties(fmtprop); fmt.setOutFile("/path/to/output/file"); // Format the prolog fmt.formatProlog(); // Format the trace and send data to the specified file fmt.toLclBinFile();
You can also run the Format class as a standalone utility program. For more information, see the following topic:
Running Format as a standalone program
Use the FormatProperties class to specify and retrieve the properties for your Format object. In other words, when you use the Format class to send information to a file, use the FormatProperties class to filter the information that you want to send.
These properties specify how you want your Format object to handle the information that it encounters in the Frames of the communications trace. The default behavior is for the Format object to ignore properties for which you have not given a specific value.
The FormatProperties class provides constants that you use to set properties. Setting properties enables the Format object to verify which filters you want to use. For example, the following code sets a Format object to display a progess dialog and not display broadcast frames:
FormatProperties prop = new FormatProperties(); prop.setProgress(FormatProperties.TRUE); prop.setBroadcast(FormatProperties.NO);
Most of the properties are available to your Format object as filters that you set to explicitly include specific data. Once you set the filters, the Format object displays only data that matches those filters. For example, the following code set a filter to display frames that occurred between a particular start and end time:
FormatProperties prop = new FormatProperties(); // Set the filter to start and end times of 22 July, 2002, // 2:30 p.m. and 2:45 p.m. GMT. // The time is expressed as a Unix(TM) timestamp, which is // based on the standard epoch of 01/01/1970 at 00:00:00 GMT. prop.setStartTime("1027348200"); prop.setEndTime("1027349100");
The following example shows how you can use many of the commtrace classes, including the Format and FormatProperties classes, to display trace information to your monitor:
Example: Using the commtrace classes
For more information about the Format and FormatProperties classes, see the following Javadoc reference documentation: