Remove reliance on default encoding

These are not all cases because there are a few String.getBytes() that I didn't want to mess with because .getBytes(String charsetName) throws an Exception.

In some cases I also made sure the streams were closed properly.