Refactor with FindBugs: do not rely on default encoding
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d634031..02f8d13 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -7,7 +7,10 @@
     </properties>
     <body>
         <release version="1.10-SNAPSHOT" date="in Mercurial" description="Development">
-             <action dev="maslovalex" type="update">
+             <action dev="py4fun" type="update">
+                Refactor with FindBugs: do not rely on default encoding (2012-01-28)
+             </action>
+             <action dev="py4fun" type="update">
                 Refactor: apply FindBugs recommendations (2012-01-28)
              </action>
              <action dev="maslovalex" type="fix">
diff --git a/src/main/java/org/yaml/snakeyaml/reader/UnicodeReader.java b/src/main/java/org/yaml/snakeyaml/reader/UnicodeReader.java
index 1f5762c..0931023 100644
--- a/src/main/java/org/yaml/snakeyaml/reader/UnicodeReader.java
+++ b/src/main/java/org/yaml/snakeyaml/reader/UnicodeReader.java
@@ -42,12 +42,17 @@
 import java.io.InputStreamReader;
 import java.io.PushbackInputStream;
 import java.io.Reader;
+import java.nio.charset.Charset;
 
 /**
  * Generic unicode textreader, which will use BOM mark to identify the encoding
  * to be used. If BOM is not found then use a given default or system encoding.
  */
 public class UnicodeReader extends Reader {
+    public static final Charset UTF8 = Charset.forName("UTF-8");
+    public static final Charset UTF16BE = Charset.forName("UTF-16BE");
+    public static final Charset UTF16LE = Charset.forName("UTF-16LE");
+
     PushbackInputStream internalIn;
     InputStreamReader internalIn2 = null;
 
@@ -77,23 +82,23 @@
         if (internalIn2 != null)
             return;
 
-        String encoding;
+        Charset encoding;
         byte bom[] = new byte[BOM_SIZE];
         int n, unread;
         n = internalIn.read(bom, 0, bom.length);
 
         if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
-            encoding = "UTF-8";
+            encoding = UTF8;
             unread = n - 3;
         } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
-            encoding = "UTF-16BE";
+            encoding = UTF16BE;
             unread = n - 2;
         } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
-            encoding = "UTF-16LE";
+            encoding = UTF16LE;
             unread = n - 2;
         } else {
             // Unicode BOM mark not found, unread all bytes
-            encoding = "UTF-8";
+            encoding = UTF8;
             unread = n;
         }
 
diff --git a/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java b/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
index 96cf35f..3db8aa4 100644
--- a/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
+++ b/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java
@@ -31,6 +31,7 @@
 import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
 import org.yaml.snakeyaml.nodes.Node;
 import org.yaml.snakeyaml.nodes.Tag;
+import org.yaml.snakeyaml.reader.UnicodeReader;
 
 /**
  * Represent standard Java classes
@@ -114,7 +115,7 @@
             if (BINARY_PATTERN.matcher(value).find()) {
                 tag = Tag.BINARY;
                 char[] binary;
-                binary = Base64Coder.encode(value.getBytes());
+                binary = Base64Coder.encode(value.getBytes(UnicodeReader.UTF8));
                 value = String.valueOf(binary);
                 style = '|';
             }
diff --git a/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java b/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
index dc937dc..9d16b74 100644
--- a/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
+++ b/src/test/java/biz/source_code/base64Coder/Base64CoderTest.java
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 
 import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
+import org.yaml.snakeyaml.reader.UnicodeReader;
 
 public class Base64CoderTest extends TestCase {
 
@@ -63,7 +64,7 @@
     }
 
     private void check(String text, String encoded) throws UnsupportedEncodingException {
-        char[] s1 = Base64Coder.encode(text.getBytes("UTF-8"));
+        char[] s1 = Base64Coder.encode(text.getBytes(UnicodeReader.UTF8));
         String t1 = new String(s1);
         assertEquals(encoded, t1);
         byte[] s2 = Base64Coder.decode(encoded.toCharArray());
diff --git a/src/test/java/examples/LoadExampleTest.java b/src/test/java/examples/LoadExampleTest.java
index e7fca44..3df5a0e 100644
--- a/src/test/java/examples/LoadExampleTest.java
+++ b/src/test/java/examples/LoadExampleTest.java
@@ -26,6 +26,7 @@
 import junit.framework.TestCase;
 
 import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.reader.UnicodeReader;
 
 public class LoadExampleTest extends TestCase {
     @SuppressWarnings("unchecked")
@@ -51,7 +52,7 @@
         Object data = yaml.load(input);
         assertEquals("test", data);
         //
-        data = yaml.load(new ByteArrayInputStream("test2".getBytes()));
+        data = yaml.load(new ByteArrayInputStream("test2".getBytes(UnicodeReader.UTF8)));
         assertEquals("test2", data);
         input.close();
     }
diff --git a/src/test/java/org/yaml/snakeyaml/JavaBeanLoaderTest.java b/src/test/java/org/yaml/snakeyaml/JavaBeanLoaderTest.java
index cb0e5d2..cb0b13f 100644
--- a/src/test/java/org/yaml/snakeyaml/JavaBeanLoaderTest.java
+++ b/src/test/java/org/yaml/snakeyaml/JavaBeanLoaderTest.java
@@ -26,6 +26,7 @@
 
 import org.yaml.snakeyaml.constructor.Constructor;
 import org.yaml.snakeyaml.introspector.BeanAccess;
+import org.yaml.snakeyaml.reader.UnicodeReader;
 
 public class JavaBeanLoaderTest extends TestCase {
 
@@ -50,7 +51,7 @@
 
     public void testLoadInputStream() {
         String yaml = "!!org.yaml.snakeyaml.JavaBeanParserTest$Bean {id: 3, name: Test me.}\n";
-        InputStream input = new ByteArrayInputStream(yaml.getBytes());
+        InputStream input = new ByteArrayInputStream(yaml.getBytes(UnicodeReader.UTF8));
         Yaml loader = new Yaml();
         Bean parsed = loader.loadAs(input, Bean.class);
         assertEquals(3, parsed.getId());