In the previous part we saw how to read files and print them. This isn't terribly interesting. Typically, you are going to read files and then do some processing on the contents of the file and possibly save the results. Let's do that in a set of examples.
Clojure is a functional language and you'll realize that as you learn the language and start writing functions. There is actually more to it than that but for now remember that you are building your program by creating and composing functions. In a purely functional language each function would not have a side effect. In other words the function would accept parameters and return a result without any change to the environment around it. As soon as we started talking about writing a function to process a file and do something with the contents we introduced the idea of a side effect. In our simple example previously we printed the lines. Next we'll process the lines and write the results to another file.
There are a few ways to read files in Clojure.
If you want to simply read a small file into a string then you can use slurp. This function works with local files as well as URLs.
To make it easier for others to work on I've moved my most popular open source project to GitHub.
Already, I've had one pull request with some fixes to allow s3cp to run under Windows more easily.
See the project at https://github.com/bradlucas/s3cp
Recently found an issue with some code running against Amazon’s S3 service. All of a sudden the application, s3cp, was not working as part of our downloader service. The app has been working flawlessly for over a year and suddenly stopped working.
As I tried to debug it I found that the system worked fine locally but not on the server. It was giving an error message around not being able to find one of my accounts buckets. That was odd. First I tried updating the jets3t library used underneath to communicate with S3. The I noticed the server’s Java as bit old but still 1.6. After upgrading both of these still no go.
After taking a break from this I turned on debugging and saw that the authorization interaction with Amazon was returning a 403 error.
To make a long day’s session short for others here is the punch line. Turned out the server’s date was off and Amazon will reject the call if it is too far from the correct time. After setting the servers date and time to the proper value my issue went away.
Just fixed. Was getting
Tree connect failed (NTSTATUSBADNETWORKNAME)
when printing from my Mac to a printer hanging off a Ubuntu machine.
Having recently upgraded Ubuntu that was probably the culprit.