Index: ../../incubator-johnzon/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../../incubator-johnzon/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java	(revision 0fdbca31d1f4964a11e73cc6756f6d59bd945723)
+++ ../../incubator-johnzon/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java	(revision )
@@ -833,8 +833,28 @@
   
         Json.createReader(new CharArrayReader(new char[]{})).read();
     }
-    
+
     @Test
+    public void testIOException() {
+        final InputStream bin = new InputStream() {
+            @Override
+            public int read() throws IOException {
+                throw new IOException("Expected");
+            }
+        };
+        JsonParser parser = null;
+        try {
+            parser = Json.createParser(bin);
+        } catch (JsonException e) {
+            assertEquals("We were expecting another cause", "Expected", e.getCause().getMessage());
+        } finally {
+            if (parser != null) {
+                parser.close();
+            }
+        }
+    }
+
+    @Test
     public void testUTF32LEStream() {
         ByteArrayInputStream bin = new ByteArrayInputStream("[\"UTF32LE\"]".getBytes(UTF_32LE));
         JsonParser parser = Json.createParser(bin);
Index: ../../incubator-johnzon/johnzon-core/src/main/java/org/apache/johnzon/core/RFC4627AwareInputStreamReader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../../incubator-johnzon/johnzon-core/src/main/java/org/apache/johnzon/core/RFC4627AwareInputStreamReader.java	(revision 0fdbca31d1f4964a11e73cc6756f6d59bd945723)
+++ ../../incubator-johnzon/johnzon-core/src/main/java/org/apache/johnzon/core/RFC4627AwareInputStreamReader.java	(revision )
@@ -57,73 +57,37 @@
 
         */
 
-    private static Charset getCharset(final PushbackInputStream inputStream) {
+    public static Charset getCharset(final PushbackInputStream inputStream) {
         Charset charset = Charset.forName("UTF-8");
         final byte[] utfBytes = new byte[4];
-        int bomLength=0;
         try {
             final int read = inputStream.read(utfBytes);
             if (read < 2) {
                 throw new JsonException("Invalid Json. Valid Json has at least 2 bytes");
             } else {
-
                 int first = (utfBytes[0] & 0xFF);
                 int second = (utfBytes[1] & 0xFF);
-                
-                if (first == 0x00) {
-                    charset = (second == 0x00) ? Charset.forName("UTF-32BE") : Charset.forName("UTF-16BE");
-                } else if (read > 2 && second == 0x00) {
-                    int third = (utfBytes[2] & 0xFF);
-                    charset = (third  == 0x00) ? Charset.forName("UTF-32LE") : Charset.forName("UTF-16LE");
-                } else {
-                  
-                    /*check BOM
-
+                /*
+                    BOM
                     Encoding       hex byte order mark
                     UTF-8          EF BB BF
                     UTF-16 (BE)    FE FF
                     UTF-16 (LE)    FF FE
                     UTF-32 (BE)    00 00 FE FF
                     UTF-32 (LE)    FF FE 00 00
-                    */
+                */
-                                        
-                    
-                    
-                    
-                    if(first == 0xFE && second == 0xFF) {
-                        charset = Charset.forName("UTF-16BE");
-                        bomLength=2;
-                    } else if(read > 3 && first == 0x00 && second == 0x00 && (utfBytes[2]&0xff) == 0xFE && (utfBytes[3]&0xff) == 0xFF){
-                        charset = Charset.forName("UTF-32BE");
-                        bomLength=4;
-                    } else if(first == 0xFF && second == 0xFE) {
-                        
-                        if(read > 3 && (utfBytes[2]&0xff) == 0x00 && (utfBytes[3]&0xff) == 0x00) {
-                            charset = Charset.forName("UTF-32LE");
-                            bomLength=4;
-                        }else {
-                            charset = Charset.forName("UTF-16LE");
-                            bomLength=2;
+                if (first == 0x00) {
+                    charset = (second == 0x00) ? Charset.forName("UTF-32BE") : Charset.forName("UTF-16BE");
+                } else if (read > 2 && second == 0x00) {
+                    int third = (utfBytes[2] & 0xFF);
+                    charset = (third == 0x00) ? Charset.forName("UTF-32LE") : Charset.forName("UTF-16LE");
-                        }
+                }
-                        
-                    } 
-                    
-                    //assume UTF8
+                //assume UTF8
-                    
-                }
+            }
-
-            }
-            
-            if(bomLength < 4) {
-                inputStream.unread(utfBytes,bomLength==2?2:0,read-bomLength);
-            }
-            
-            
-
+            inputStream.unread(utfBytes, 0, read);
         } catch (final IOException e) {
-            throw new JsonException("Unable to detect charset due to "+e.getMessage(), e);
+            throw new JsonException("Unable to detect charset due to " + e.getMessage(), e);
         }
-
         return charset;
     }
 
