Okay --
So, I have some Java code which creates a file, then runs one of several external binaries upon that file using exec. The external binary reads the provided file, does its processing, then dumps its output into a file which the Java portion reads, parses and presses on with processing.
The output from the various binaries has a fixed, common part and an optional binary-specific part.
The problem is that the way that these things are described are 'hard-coded' in String.substring() calls. For example, if there are fields named 'date' and 'record_id' it would look something like:
This repeats for every field in the input format.
I would like to be able to describe the format, field names, etc., in a better way than using these hard-coded values.
I've been going down the line of two format Strings -- one for the fixed, common part and one for the variable part -- and two String arrays for the common and variable field names.
(Note: Very simplified example, but I'm looking at up to a couple dozen of these fields.)
Then work through the format ... somehow ... using the Scanner class.
But now that I'm working on it, this gets tedious really quick.
I'm wondering if there's a better way ...
Thanks in advance,
So, I have some Java code which creates a file, then runs one of several external binaries upon that file using exec. The external binary reads the provided file, does its processing, then dumps its output into a file which the Java portion reads, parses and presses on with processing.
The output from the various binaries has a fixed, common part and an optional binary-specific part.
The problem is that the way that these things are described are 'hard-coded' in String.substring() calls. For example, if there are fields named 'date' and 'record_id' it would look something like:
Code:
date = inputLine.substring(0, 6);
record_id = inputLine.substring(6, 15);
I would like to be able to describe the format, field names, etc., in a better way than using these hard-coded values.
I've been going down the line of two format Strings -- one for the fixed, common part and one for the variable part -- and two String arrays for the common and variable field names.
Code:
static final String COMMON_FORMAT = "%6s%9s";
static final String[] COMMON_FIELDS = { "DATE", "RECORD_ID" };
(Note: Very simplified example, but I'm looking at up to a couple dozen of these fields.)
Then work through the format ... somehow ... using the Scanner class.
But now that I'm working on it, this gets tedious really quick.
I'm wondering if there's a better way ...
Thanks in advance,