Regular Expression File Reader Input Adapter


The TIBCO StreamBase® Regular Expression File Reader input adapter allows StreamBase applications to read custom-formatted text input files, parsed with regular expressions.

The application specifies an input file, the regular expression used to parse lines of the input file, options for how to time and repeat tuples, how to deal with malformed records, and the target output schema. The input file must be a text file with newlines delimiting records. The adapter parses each line of the file using the provided Java regular expression. Each capture group of the regular expression must correspond to a field of the output schema (the first capture group corresponds to the first schema field and so forth). The fields extracted from the file are coerced to the correct data types according to the schema and tuples are emitted.

Because the input source of this adapter is finite and has no natural timing, this adapter allows the input file to be repeated and the inter-tuple timing to be specified.

The Regular Expression File Reader can read files compressed in the zip or gzip formats, automatically extracting the file to be read from the zip or gzip archive file. For this to work, the adapter requires the target file to have the extension .zip or .gz, and expects to find exactly one text file inside each compressed file. This feature allows the adapter to read market data files provided by a market data vendor in compressed format, without needing to uncompress the files in advance.

Regular Expression File Reader Properties

This section describes the properties you can set for this adapter, using the various tabs of the Properties view in StreamBase Studio.

General Tab

Name: Use this field to specify or change the component's name, which must be unique in the application. The name must contain only alphabetic characters, numbers, and underscores, and no hyphens or other special characters. The first character must be alphabetic or an underscore.

Adapter: A read-only field that shows the formal name of the adapter.

Class: A field that shows the fully qualified class name that implements the functionality of this adapter. Use this class name when loading the adapter in StreamSQL programs with the APPLY JAVA statement. You can right-click this field and select Copy from the context menu to place the full class name in the system clipboard.

Start with application: If this field is set to Yes or to a module parameter that evaluates to true, an instance of this adapter starts as part of the containing StreamBase Server. If this field is set to No or to a module parameter that evaluates to false, the adapter is loaded with the server, but does not start until you send an sbadmin resume command, or until you start the component with StreamBase Manager. With this option set to No or false, the adapter does not start even if the application as a whole is suspended and later resumed. The recommended setting is selected by default.

Enable Error Output Port: Select this check box to add an Error Port to this component. In the EventFlow canvas, the Error Port shows as a red output port, always the last port for the component. See Using Error Ports and Error Streams to learn about Error Ports.

Description: Optionally enter text to briefly describe the component's purpose and function. In the EventFlow canvas, you can see the description by pressing Ctrl while the component's tooltip is displayed.

Adapter Properties Tab

Property StreamSQL Property Default Description
File Name FileName none This control is a drop-down list showing eligible files in the current project. Use the drop-down selector to select the file to read and parse. This file is read one line at a time. Each line is parsed using the Format property and emits one tuple.
Use Default Charset UseDefaultCharset Selected If selected, specifies whether the Java platform default character set is to be used. If cleared, a valid character set name must be specified for the Character Set property.
Character Set Charset None The name of the character set encoding that the adapter is to use to read input or write output.
Format Format none The regular expression used to parse the input file. This must be a Java regular expression as expected by the java.util.regex.Pattern class. For example, ([^,]*),([^,]*) could be used to parse a simple, two-field CSV file.
Period Period 0 An integer specifying the rate, in milliseconds, at which to read lines from the specified file and emit tuples. Specify 0 or omit this property to emit tuples as quickly as possible.
Repeat Repeat 1 An integer specifying the number of times to repeat the input file. If omitted or 1, this reads the input file once and then stops emitting tuples. If set to 0, this repeats the input file indefinitely.
Drop Mismatches DropMismatches selected (true) If selected, records that do not match the regular expression in the Format field are ignored and the next record is immediately examined. Otherwise, a tuple with all fields set to null is emitted when a non-matching input line is encountered.
Timestamp Format TimestampFormat MM/dd/yyyy hh:mm:ss aa Specifies the format used to parse timestamp fields extracted from the input file. Specify a string in the form expected by the java.text.SimpleDateFormat class described in the Sun Java Platform SE reference documentation.
Start Control Port StartControlPort Cleared

Select this check box to give this adapter instance an input port that you can use to control which files to read, and in which order. The input schema for the Start Control Port must have a single field of type string. The schema is typechecked as you define it.

If the File Name property is empty, the adapter begins reading when it receives a control tuple on this port. The path to the file to be read is specified in the only field of the tuple. The path can be absolute, or relative to the working directory of the StreamBase Server process.

If the File Name property specifies a file name, there are two cases:

  1. If a control tuple received on this port has an empty or null string, the file specified in the File Name property is read or re-read.

  2. If a control tuple contains the path to a file, then that specified file is read, as above, ignoring the File Name field.

Start Event Port StartEventPort Cleared

Select this check box to create an output port that emits an informational tuple each time a file is opened or closed. The informational tuple schema has five fields:

  • Type, string

  • Object, string

  • Action, string

  • Status, int

  • Info, string

For a file open event, the event port tuple's Type field is set to "Open", while the Object field is set to the path name of the file being opened.

For a file close event, Type is set to "Close", Object is set to the path name of the file being closed, and Status is set to the number of rows that were read from the file. The Close event tuple is sent after the adapter processes the entire file and emits data tuples for each record in the file.

If you enable the Map Control Port to Event Port option below, the event port tuple also includes a sixth field named ControlInfo of type tuple.

When running in Studio, remember that tuples from more than one output port may appear in the Application Output view in a different order than they are emitted from the adapter. Thus, you may see the Close event appear on the output of this event port while data tuples are still displaying.

Map Control Port to Event Port MapControlPort Cleared

Select this check box to pass all information received on the control input port to the event output port. When enabled, this property adds a field of type tuple named ControlInfo to the tuple passed to the event output stream. The ControlInfo field contains the entire tuple of the input stream sent to the Control Port.

Log Level drop-down list INFO Controls the level of verbosity the adapter uses to send notifications to the console. This setting can be higher than the containing application's log level. If set lower, the system log level will be used. Available values, in increasing order of verbosity, are: OFF, ERROR, WARN, INFO, DEBUG, TRACE, and ALL.

Edit Schema Tab

Use the Edit Schema tab to specify the schema of the output tuple for this adapter. For general instructions on using the Edit Schema tab, see the Properties: Edit Schema Tab section of the Defining Input Streams page.

Concurrency Tab

Use the Concurrency tab to specify parallel regions for this instance of this component, or multiplicity options, or both. The Concurrency tab settings are described in Concurrency Options, and dispatch styles are described in Dispatch Styles.


Concurrency settings are not suitable for every application, and using these settings requires a thorough analysis of your application. For details, see Execution Order and Concurrency, which includes important guidelines for using the concurrency options.

Typechecking and Error Handling

Typechecking fails if the Format property contains an invalid regular expression, if the number of fields in the output schema does not match the number of capture subexpressions in the Format property, or if the Timestamp Format is malformed.

Malformed records (lines that do no match the Format regular expression) will cause the adapter to either ignore the input line or to emit a tuple with all fields set to null, depending on the value of the Drop Mismatches property.

If a field extracted from the file cannot be coerced into the type specified for that field in the schema (for example, if "abc" is extracted where a int field is expected), that field is set to null in the output tuple. Likewise, if a capture group in the Format expression fails to match, but the overall regular expression does match, the corresponding field in the output tuple is set to null.

Suspend and Resume Behavior

When suspended, the input file will remain open and the adapter will retain its position in the file. Upon resume, the adapter will continue consuming lines from the input file and outputting tuples.