Description
The RandomAccessFixedFileReceiver is used to randomly access locations within a fixed file, to modify its data at any given site. To randomly access a specific location within a fixed file, the RandomAccessFixedFileReceiver has a few requirements, defined below.
In This Article
- In This Article
- Requirements
- Special Notes
- How It Works
- Receiver Parameters
- Receiver Attribute PropertyKeys
- Example Stories
- Story 1 - Modify a Fixed File With Delimiters and End Of Line characters
- Story 2 - Modify a Fixed File With Delimiters and No End of Line Characters
- Story 3 - Modify a Fixed File With No Delimiters and No End Of Line Characters
- Story 4 - Modify a Fixed File With Delimiters, and an End Of Line Character And Quantity is Excluded
- Story 5 - Modify a Fixed File With Delimiters, an End Of Line Character and use ignoreValue as a Toggle
- Modification to the value Attribute Generators
Requirements
- Fixed length Columns - The file must contain two or more fixed-length columns that are consistent across all rows within the fixed file.
- Key Columns - One or more columns within the fixed file can be used to define a key that uniquely identifies a row within the fixed file.
- Memory Allocation - Make sure the Java Virtual Machine (JVM) has enough memory allocated to it, so that all keys and their index may be mapped in memory.
Special Notes
- The Receiver will not modify the values of key columns.
- The Receiver will throw a GenRocket Exception if a duplicate key column is found within the given fixed file document.
- All rows within a fixed file document must have the exact same number of bytes.
How It Works
Before GenRocket starts generating data, it calls the Receiver during an initialization event. During the initialization event, the Receiver executes the following setup steps:
- Opens the given fixed file.
- Builds a list of column objects defined by its property keys (see Property Keys below).
- Determines which columns define the key for each row.
- Determines the block size of each row by calculating the length of all columns.
- Traverses each row, one block at a time, seeks the data within each row to define its key, and stores the key and row's index into memory.
Receiver Parameters
The RandomAccessFixedFileReceiver requires that the following parameters are defined. Items with an asterisk (*) are required.
- path* - Defines the base directory path where the file to access is located.
- subDir - Defines an optional subdirectory under the path base directory where the file to access is located.
- fileName - Defines the name of the file to access.
- delimiterSize* - If the fixed file being accessed has a delimiter between each fixed column, then the size of the delimiter must be defined. For instance, if the delimiting character happens to be a colon ':,' then the size would be 1. The default is 0.
- endOfLineSize* - If the fixed file being accessed has an end of line character(s) between each fixed row, then the size of the end of line character(s) must be defined. For instance, if the end of line character happens to be a \n, then the size would be 1. If the end of line characters happens to be a \r\n, then the size would be 2. The default is 0.
- ignoreValue - When there are instances where a value for a given fixed column should not be modified, then the ignoreValue's value should be used as the generated value. When the Receiver sees the ignoredValue, it will not perform an update to the given column for the given iteration.
Receiver Attribute PropertyKeys
- length - Defines the fixed length of the given column.
- key - If set to true, the column will be used to define a key to map each row and its row index into memory.
- include - Determines if the given column within the fixed file may be updated.
Example Stories
The example stories below show different use cases where the RandomAccessFixedFileReceiver is used to modify fixed files with slightly different internal formats. Sometimes, the parameters or property key values determine the Receiver's behavior and how data within a given fixed file are updated. All of the example stories below share the same configuration for the length Attribute property key values and the productId Attribute's key property key value.
Receivers Attributes Property Keys
The fixed lengths are set for each column, and the productId's key attribute property key value is set to true.
Story 1 - Modify a Fixed File With Delimiters and End Of Line characters
The fixed file below contains a colon (:) delimiter between each column and a linefeed (\n) at the end of each row. Thus, the value of the delimiterSize parameter and endOfLineSize parameter needs to be set to 1.
Receivers Parameters
Before File Modification
This is the form of the fixed file before modifications.
After File Modification
After GenRocket has generated the test data and RandomAccessFixedFileReceiver has updated the fixed file.
Story 2 - Modify a Fixed File With Delimiters and No End of Line Characters
The fixed file below contains a colon (:) delimiter between each column and no end of line characters. Thus, the value of the delimiterSize parameter needs to be set to the value of 1, and the endOfLineSize parameter needs to remain with its default value of 0.
Receivers Parameters
Before File Modification
This is the form of the fixed file before modifications.
After File Modification
After GenRocket has generated the test data and RandomAccessFixedFileReceiver has updated the fixed file.
Story 3 - Modify a Fixed File With No Delimiters and No End Of Line Characters
The fixed file below contains no delimiter between each column and no end of line characters. It's just a pure block of continuous block of data. Thus, the value of the delimiterSize parameter and endOfLineSize parameter both need to remain with their default values of 0.
Receivers Parameters
Before File Modification
This is the form of the fixed file before modifications.
After File Modification
After GenRocket has generated the test data and RandomAccessFixedFileReceiver has updated the fixed file.
Story 4 - Modify a Fixed File With Delimiters, an End Of Line Character, and Quantity is Excluded
The fixed file below contains a colon (:) delimiter between each column and a linefeed (\n) at the end of each row. Also, we do not want the quantity column to be updated. Thus, the quantity Attribute's include property key value, is set to false to exclude it from being updated.
Receivers Attributes Property Keys
The quantity Attribute's include property key value, is set to false.
Before File Modification
This is the form of the fixed file before modifications.
After File Modification
After GenRocket has generated the test data and RandomAccessFixedFileReceiver has updated the fixed file.
Story 5 - Modify a Fixed File With Delimiters, an End Of Line Character and use ignoreValue as a Toggle
The fixed file below contains a colon (:) delimiter between each column and a linefeed (\n) at the end of each row. Also, we want to update the value column only when the generated value is not equal to the value defined in the ignoreValue parameter, which is set to the value of IGNORE.
Receivers Parameters
Preview of the Value Column Having Toggled Data
Modification to the value Attribute Generators
The value Attribute uses three Generators to generate the toggling effect:
- CalcGen - computes the price * quantity
- PadGen - pads the value computed by the CalcGen
- EvalCaseGen - uses the modulus functions to toggle between the padded value and the constant, IGNORE.
CalcGen Generator
PadGen Generator
EvalCaseGen Generator
Before File Modification
This is the form of the fixed file before modifications.
After File Modification
After GenRocket has generated the test data and RandomAccessFixedFileReceiver has updated the fixed file.