Table of Contents

Search

  1. Preface
  2. Working with Transformations
  3. Aggregator Transformation
  4. Custom Transformation
  5. Custom Transformation Functions
  6. Data Masking Transformation
  7. Data Masking Examples
  8. Expression Transformation
  9. External Procedure Transformation
  10. Filter Transformation
  11. HTTP Transformation
  12. Identity Resolution Transformation
  13. Java Transformation
  14. Java Transformation API Reference
  15. Java Expressions
  16. Java Transformation Example
  17. Joiner Transformation
  18. Lookup Transformation
  19. Lookup Caches
  20. Dynamic Lookup Cache
  21. Normalizer Transformation
  22. Rank Transformation
  23. Router Transformation
  24. Sequence Generator Transformation
  25. Sorter Transformation
  26. Source Qualifier Transformation
  27. SQL Transformation
  28. Using the SQL Transformation in a Mapping
  29. Stored Procedure Transformation
  30. Transaction Control Transformation
  31. Union Transformation
  32. Unstructured Data Transformation
  33. Update Strategy Transformation
  34. XML Transformations

Transformation Guide

Transformation Guide

Using Java Code to Parse a Flat File

Using Java Code to Parse a Flat File

You can develop Java code to parse a flat file. Use Java code to extract specific columns of data from a flat file of varying schema or a JMS message.
For example, you want to read the first two columns of data from a delimited flat file. Create a mapping that reads data from a delimited flat file and passes data to one or more output ports.
The mapping contains the following components:
  • Source definition.
    The source is a delimited flat file. Configure the source to pass rows of a flat file as a string to the Java transformation. The source file has the following data:
    1a,2a,3a,4a,5a,6a,7a,8a,9a,10a 1b,2b,3b,4b,5b,6b,7b,8b,9b 1c,2c,3c,4c,5c,6c,7c 1d,2d,3d,4d,5d,6d,7d,8d,9d,10d
  • Java transformation.
    Define the Java transformation functionality on the Java Code tab.
    Use the Import Packages tab of the Java Code to import the java package. Enter the following code on the Import Packages tab:
    import java.util.StringTokenizer;
    Use the On Input Row tab of the Java Code tab to read each row of data from a string and pass the data to output ports. Enter the following code on the On Input Row tab to retrieve the first two columns of data:
    StringTokenizer st1 = new StringTokenizer(row,","); f1 = st1.nextToken(); f11= st1.nextToken();
  • Target definition
    . Configure the target to receive rows of data from the Java Transformation. After you run a workflow that contains the mapping, the target contains two columns of data. The target file has the following data:
    1a,2a 1b,2b 1c,2c 1d,2d

0 COMMENTS

We’d like to hear from you!