Skip to content
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

File fixture get first line #106

Merged
merged 8 commits into from
Dec 22, 2016
Merged

File fixture get first line #106

merged 8 commits into from
Dec 22, 2016

Conversation

tcnh
Copy link
Contributor

@tcnh tcnh commented Dec 21, 2016

Added takeFirstLineFrom file method. Allows for using a file based list of non-reusable data (i.e. card numbers in a test environment) to use in your tests. May be useful for others as well

@tcnh
Copy link
Contributor Author

tcnh commented Dec 21, 2016

I don't understand where the old (july) commits come from.. they seem not to have affected any files?
Only affected files should be FileFixture.java and the example/test wiki page.

@fhoeben
Copy link
Owner

fhoeben commented Dec 21, 2016

In the files changed I only see the changes to the 2 files you mention, so the rest is probably some Git branch magic affecting you.

throw new IOException(fullName + " is an empty file.");
}

//Overwrite file, minus the first line.
Copy link
Owner

Choose a reason for hiding this comment

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

Any chance you are willing to rewrite this to a (streaming) write to another file (e.g. .new) and at the end remove old file and rename new file to old name?
That way the entire file does not need to be loaded in memory and there is no chance of corrupting the existing file.

Maybe a bit overkill for the purpose at hand, but that just feels safer...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See commit below. Added a utility method to do an incremental write from the scanner using a printwriter.
This method is used to create a temporary file. Temp file gets copied over the original file and gets deleted afterwards

Is that what you meant?

@@ -175,6 +175,28 @@ public static File writeFile(String filename, String content) {
return new File(filename);
}

public static File writeStreamFromScanner(String filename, Scanner sc){
Copy link
Owner

Choose a reason for hiding this comment

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

Looks good (exceptie for some spacing issues preceding '(')
Maybe rename method to writeFromScanner, as there is no 'stream' involved?

@fhoeben fhoeben merged commit bd8996b into fhoeben:master Dec 22, 2016
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.

2 participants