/** * Reads byte from the stream. */ @Override public int read() throws IOException { init(); return internalInputStream.read(); }
/** * Returns detected UTF encoding or <code>null</code> if no UTF encoding has been detected (i.e. no BOM). * If stream is not read yet, it will be {@link #init() initalized} first. */ public String getDetectedEncoding() { if (!initialized) { try { init(); } catch (IOException ioex) { throw new IllegalStateException(ioex); } } return encoding; }
/** * Reads byte from the stream. */ @Override public int read() throws IOException { init(); return internalInputStream.read(); }
/** * Returns detected UTF encoding or {@code null} if no UTF encoding has been detected (i.e. no BOM). * If stream is not read yet, it will be {@link #init() initalized} first. */ public String getDetectedEncoding() { if (!initialized) { try { init(); } catch (IOException ioex) { throw new IllegalStateException(ioex); } } return encoding; }
@Test void testUtf16BE() throws IOException { byte[] bytes = new byte[4]; Bits.putInt(bytes, 0, 0xFEFF6565); ByteArrayInputStream basis = new ByteArrayInputStream(bytes); UnicodeInputStream uis = new UnicodeInputStream(basis, null); uis.init(); assertEquals(2, uis.getBOMSize()); assertEquals("UTF-16BE", uis.getDetectedEncoding()); }
@Test void testUtf32LE() throws IOException { byte[] bytes = new byte[4]; Bits.putInt(bytes, 0, 0xFFFE0000); ByteArrayInputStream basis = new ByteArrayInputStream(bytes); UnicodeInputStream uis = new UnicodeInputStream(basis, null); uis.init(); assertEquals(4, uis.getBOMSize()); assertEquals("UTF-32LE", uis.getDetectedEncoding()); }
@Test void testUtf8() throws IOException { byte[] bytes = new byte[4]; Bits.putInt(bytes, 0, 0xEFBBBF65); ByteArrayInputStream basis = new ByteArrayInputStream(bytes); UnicodeInputStream uis = new UnicodeInputStream(basis, null); uis.init(); assertEquals(3, uis.getBOMSize()); assertEquals("UTF-8", uis.getDetectedEncoding()); }
@Test void testUtf16LE() throws IOException { byte[] bytes = new byte[4]; Bits.putInt(bytes, 0, 0xFFFE6565); ByteArrayInputStream basis = new ByteArrayInputStream(bytes); UnicodeInputStream uis = new UnicodeInputStream(basis, null); uis.init(); assertEquals(2, uis.getBOMSize()); assertEquals("UTF-16LE", uis.getDetectedEncoding()); }
@Test void testUtf32BE() throws IOException { byte[] bytes = new byte[4]; Bits.putInt(bytes, 0, 0x0000FEFF); ByteArrayInputStream basis = new ByteArrayInputStream(bytes); UnicodeInputStream uis = new UnicodeInputStream(basis, null); uis.init(); assertEquals(4, uis.getBOMSize()); assertEquals("UTF-32BE", uis.getDetectedEncoding()); }
@Test void testNoUtf() throws IOException { byte[] bytes = new byte[4]; Bits.putInt(bytes, 0, 0x11223344); ByteArrayInputStream basis = new ByteArrayInputStream(bytes); UnicodeInputStream uis = new UnicodeInputStream(basis, null); uis.init(); assertEquals(0, uis.getBOMSize()); assertNull(uis.getDetectedEncoding()); } }
/** * Reads byte from the stream. */ @Override public int read() throws IOException { init(); return internalInputStream.read(); }
/** * Returns detected UTF encoding or {@code null} if no UTF encoding has been detected (i.e. no BOM). * If stream is not read yet, it will be {@link #init() initalized} first. */ public String getDetectedEncoding() { if (!initialized) { try { init(); } catch (IOException ioex) { throw new IllegalStateException(ioex); } } return encoding; }