Implemented try-with-resources, as in JLS SE 7 | 14.20.3.

Added missing copyright headers.