JessRudder
@dblock trying to think what the next steps would be.... Would it make sense to write a method that opens the file provided in the JRHostsFile initialization method?
#4 · open · 3 comments
@dblock trying to think what the next steps would be.... Would it make sense to write a method that opens the file provided in the JRHostsFile initialization method?
Each line in hosts is a host entry. Next step should be an iterator that lazily let's you "see" every line in the file as such entry. That means a class that defines a host entry and a proper iterator that reads line by line, skips comments and returns instances of a host entry with such properties as a source and destination.
We never want to think about a hosts file as a file, that's an internal implementation detail or a way to store the data. What we want is a higher level interface that lets us implement logic around it. After we have an iterator we can also start adding methods that add an entry and methods that write the file back, potentially just incrementally. And we never need to keep the entire file in memory or ever read it at once.
Read up on enumerators, somewhere you'll learn how to enumerate with a block :)