Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify encodings? #5

Open
albertdev opened this issue Sep 5, 2018 · 0 comments
Open

How to specify encodings? #5

albertdev opened this issue Sep 5, 2018 · 0 comments

Comments

@albertdev
Copy link

While I'm afraid I might not immediately use this library, I spotted the following example in the README:

PrintWriter writer = IoStream.file("yesss.txt").printWriter();

Where is the encoding set? Because if this is just syntactic sugar for new PrintWriter(new OutputStreamWriter(new FileOutputStream("yesss.txt"))) then you are leaving the encoding up to chance - silently a default will be used. This default depends on system settings, JVM versions and platform, and it can vary from an ASCII-only encoding on Windows (which will ruin all kinds of UTF-8 files!) to UTF-16 on some exotic platforms. It is therefore recommended to use an explicit encoding.

To do so, the OutputStreamWriter (and its cousin InputStreamReader) constructors are overloaded to accept either an additional Charset, CharsetDecoder or a string identifying the encoding. Making the encoding required in your builders would thus be a serious step forward to make it plain obvious that you can't do without.

Building a library which makes it easier to do things right than do things wrong is always strongly recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant