Skip to content

Progress indicator - #67

Merged
simonoakesepimorphics merged 8 commits into
mainfrom
28-progress-indicator
Aug 13, 2026
Merged

Progress indicator#67
simonoakesepimorphics merged 8 commits into
mainfrom
28-progress-indicator

Conversation

@simonoakesepimorphics

Copy link
Copy Markdown
Contributor

Fixes #28

@kal kal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor niggles, but otherwise looks fine.

dc.getGlobalEnv().put(ConverterProcess.FILE_NAME, filename);
dc.getGlobalEnv().put(ConverterProcess.FILE_BASE_NAME, filebasename);
InputStream is = BOMInputStream.builder().setInputStream( new FileInputStream(dataFileF) ).get();
int rowCount = LineCount.file(dataFileF) - 1; // discount header row

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is safer to count the rows before opening the InputStream. I can see that you have two separate handles to the file here, but having the one for processing open while counting the rows just feels like asking for OS level malarky.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/main/java/com/epimorphics/dclib/framework/ConverterProcess.java Outdated
@kal

kal commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@simonoakesepimorphics - can you check why the build is stuck in in progress. I don't see it in the Actions tab at all so it might just be a GH issue.

@kal kal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the clarification about the row count property, I now have a concern that we are confusing row and line counts in calculating progress, which may cause problems in CSVs with muti-line rows.

process.setTemplate( template );
process.setMessageReporter( reporter );
process.setAllowNullRows( !args.isNullRowAborts() );
process.setRowCount(rowCount);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line sets the row count to the count of the number of lines in the file, not the number of rows and so contradicts what the documentation says. Given that you don't know how many multi-line rows you have without greater parsing up front, it feels like this should be setting a line count, not a row count?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I couldn't find an efficient way to deal with this so I rewrote the feature to use the formula (total bytes in file - bytes in header) / (bytes in rows processed).

@kal kal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The heuristic used for the bytes read is a bit suspect, and would definitely trip us up in non-European language content. A better solution would probably be to wrap the InputStream in a stream that can report position and expose that through the BindingEnv.

String[] headers = getHeaders();
totalBytes -= headers.length; // assume 1 byte for each column separator
for (String header: getHeaders()) {
totalBytes -= header.length();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a rough heuristic this is OK, but worth remembering that if a file is UTF-8 encoded, one character may encode to multiple bytes.

/**
* Set the total number of rows (not lines) to be processed for the purpose of computing progress percentage.
*/
public void setRowCount(int rowCount) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now redundant and can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

CsvBindingEnv row = new CsvBindingEnv();
for (int i = 0; i < rowLength; i++) {
String rowValue = rowValues[i];
sourceBytes += rowValue.length();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again this heuristic will be thrown out by multi-byte UTF-8 characters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a better solution would be to wrap the provided InputStream in an implementation that is capable of reporting the current position in the stream? There are a couple of options described in this SO answer - one using a custom decorator, the other suggesting the use of a Commons IO (though the latter references a deprecated class that has been deprecated in favour of BoundedInputStream)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea but the CSV parser is free to read ahead in the input stream on its own whim so that byte count won't be reliable. I've improved the accuracy of the original method by counting actual bytes instead of chars.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to specify the encoding of the file when counting the bytes of the string. At the moment the code is using the default encoding of the system which may or may not be the same as the encoding of the file...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a hardcoded assumption of UTF-8 elsewhere so I've made it more explicit.

@simonoakesepimorphics
simonoakesepimorphics merged commit eb27864 into main Aug 13, 2026
2 checks passed
@simonoakesepimorphics
simonoakesepimorphics deleted the 28-progress-indicator branch August 13, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve progress indicator

2 participants