-
Notifications
You must be signed in to change notification settings - Fork 25.2k
convert ConcatFilesTask.groovy to .java #34476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Create ConcatFilesTask.java
Thanks for the PR @mara2701. It looks like this is incomplete? The .groovy file still exists, and the java implementation doesn't have a TaskAction annotated method, nor input/outputs. |
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @mara2701 ! We appreciate your effort.
I think this is a good starting point, I added some comments.
I also added more details to #34459 as to what we expect with this transition,
sorry I should have added these to begin with.
public void concatFiles() { | ||
final StringBuilder output = new StringBuilder(); | ||
|
||
if (headerLine != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not necessary, Gradle doesn't allow for it unless the task is marked @Optional
|
||
final StringBuilder sb = new StringBuilder(); | ||
for (File f: files) { | ||
Scanner scanner = new Scanner(f, "UTF-8" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a try-with-resources syntax with this.
final StringBuilder sb = new StringBuilder(); | ||
for (File f: files) { | ||
Scanner scanner = new Scanner(f, "UTF-8" ); | ||
String text = scanner.useDelimiter("\\A").next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using nextLine
might be easier to read, and since we need all the lines in memory to perform the de-duplication anyhow, I would consider doing it in one step.
Using java streams and a set as the Groovy implementation did to take care of the de-duplication would make this concise and easy to understand:
files.getFiles().stream()
.flatMap(Files.readLines(null, StandardCharsets.UTF_8).stream())
.collect(Collectors.toSet())
.forEach( line -> {
// write each line to target
})
You will probably have to collect to a different set implementation to preserve order but this is the general idea. Writing a test will make that obvious.
@mara2701 Are you planning to work further on this? |
Picking this task due to long inactivity. |
This PR might be obsolete due to #37497. |
Closing since #37497 was merged. |
No description provided.