Use Apache Commons IO to copy streams instead of custom code.