Andrey Somov  committed 82edf00

Remove StreamReader.getEncoding() because it works only with UnicodeReader

Comments (0)

Files changed (3)

File src/main/java/org/yaml/snakeyaml/reader/StreamReader.java Modified

View file
  • Ignore whitespace
  • Hide word diff
         return column;
     }
 
-    public Charset getEncoding() {
-        return Charset.forName(((UnicodeReader) this.stream).getEncoding());
-    }
-
     /**
      * @return current position as number (in characters) from the beginning of the stream
      */

File src/test/java/org/pyyaml/PyReaderTest.java Modified

View file
  • Ignore whitespace
  • Hide word diff
         File[] inputs = getStreamsByExtension(".stream-error");
         for (int i = 0; i < inputs.length; i++) {
             InputStream input = new FileInputStream(inputs[i]);
-            StreamReader stream = new StreamReader(new UnicodeReader(input));
+            UnicodeReader unicodeReader = new UnicodeReader(input);
+            StreamReader stream = new StreamReader(unicodeReader);
             try {
                 while (stream.peek() != '\u0000') {
                     stream.forward();
                 }
                 fail("Invalid stream must not be accepted: " + inputs[i].getAbsolutePath()
-                        + "; encoding=" + stream.getEncoding());
+                        + "; encoding=" + unicodeReader.getEncoding());
             } catch (ReaderException e) {
                 assertTrue(e.toString(),
                         e.toString().contains(" special characters are not allowed"));

File src/test/java/org/yaml/snakeyaml/reader/ReaderBomTest.java Modified

View file
  • Ignore whitespace
  • Hide word diff
     public void testNoBom() throws IOException {
         byte[] data = "test".getBytes("UTF-8");
         ByteArrayInputStream input = new ByteArrayInputStream(data);
-        Reader r = new UnicodeReader(input);
+        UnicodeReader r = new UnicodeReader(input);
         StreamReader reader = new StreamReader(r);
         assertEquals('t', reader.peek());
-        assertEquals(Charset.forName("UTF-8"), reader.getEncoding());
+        assertEquals(Charset.forName("UTF-8"), Charset.forName(r.getEncoding()));
         reader.forward(1);
         assertEquals('e', reader.peek());
         reader.forward(1);
         File file = new File("src/test/resources/reader/utf-8.txt");
         assertTrue("Test file not found: " + file.getAbsolutePath(), file.exists());
         InputStream input = new FileInputStream(file);
-        StreamReader reader = new StreamReader(new UnicodeReader(input));
+        UnicodeReader unicodeReader = new UnicodeReader(input);
+        StreamReader reader = new StreamReader(unicodeReader);
         assertEquals('t', reader.peek());
         reader.forward(1);
         assertEquals('e', reader.peek());
         assertEquals('t', reader.peek());
         reader.forward(1);
         assertEquals('\u0000', reader.peek());
-        assertEquals(Charset.forName("UTF-8"), reader.getEncoding());
+        assertEquals(Charset.forName("UTF-8"), Charset.forName(unicodeReader.getEncoding()));
         input.close();
     }
 
         File file = new File("src/test/resources/reader/unicode-16le.txt");
         assertTrue("Test file not found: " + file.getAbsolutePath(), file.exists());
         InputStream input = new FileInputStream(file);
-        StreamReader reader = new StreamReader(new UnicodeReader(input));
+        UnicodeReader unicodeReader = new UnicodeReader(input);
+        StreamReader reader = new StreamReader(unicodeReader);
         assertEquals('t', reader.peek());
         reader.forward(1);
         assertEquals('e', reader.peek());
         assertEquals('t', reader.peek());
         reader.forward(1);
         assertEquals('\u0000', reader.peek());
-        assertEquals(Charset.forName("UTF-16LE"), reader.getEncoding());
+        assertEquals(Charset.forName("UTF-16LE"), Charset.forName(unicodeReader.getEncoding()));
         input.close();
     }
 
         File file = new File("src/test/resources/reader/unicode-16be.txt");
         assertTrue("Test file not found: " + file.getAbsolutePath(), file.exists());
         InputStream input = new FileInputStream(file);
-        StreamReader reader = new StreamReader(new UnicodeReader(input));
+        UnicodeReader unicodeReader = new UnicodeReader(input);
+        StreamReader reader = new StreamReader(unicodeReader);
         assertEquals('t', reader.peek());
         reader.forward(1);
         assertEquals('e', reader.peek());
         assertEquals('t', reader.peek());
         reader.forward(1);
         assertEquals('\u0000', reader.peek());
-        assertEquals(Charset.forName("UTF-16BE"), reader.getEncoding());
+        assertEquals(Charset.forName("UTF-16BE"), Charset.forName(unicodeReader.getEncoding()));
         input.close();
     }
 }