quiz
quiz copied to clipboard
fix and improvement
- use try-with-resources to close Streams finally
- it is better to use ReadWriteLock in accessors because to multithreading read property
- use StringBuilder (mutable) instead String (immutable) to reduce creating String-objects and improve code performance.
- Use try-with-resources to autoclose Streams finally
- Write lock is needed in set() and saveContent() methods. Read lock is needed in get(), getContent() and getContentWithoutUnicode() methods. This will increase performance in multithreaded code reading mode and prevent from reading the field by another thread while writing (preventing from ConcurrentModificationException)
- Use StringBuilder (mutable) instead String (immutable) to reduce creating String-objects and improve code performance.
- Avoid duplicate code. We can to create one private method getStringContent(boolean withUnicode) and use it in getContent() and getContentWithoutUnicode() methods.
- If we can to change the API, we can to use one static method getContent() instead of two non static, because it will eliminate the need to lock the file for reading. Or it is better to move static getContent() method to another FileUtils class. In this case it will be better to rename class Parser to FileHolder.
- Minor fixes (unicode symbol constant)