Updated codes to use the StringBuilder and IOUtils for error message
processing as suggested.