@Test public void getDetectedEncoding_A$File() throws Exception { FileReaderCommonsIOImpl target = new FileReaderCommonsIOImpl(); File file = new File("src/test/resources/UTF-8.txt"); String actual = target.getDetectedEncoding(file); String expected = "UTF-8"; assertEquals(expected, actual); }
@Override public String getDetectedEncoding(File file) { InputStream is = null; String encoding = null; try { is = new FileInputStream(file); UniversalDetector detector = new UniversalDetector(null); byte[] buf = new byte[4096]; int nread; while ((nread = is.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } detector.dataEnd(); encoding = detector.getDetectedCharset(); } catch (IOException e) { } finally { IOUtils.closeQuietly(is); if (encoding == null) { return Charset.defaultCharset().name(); } } return encoding; }
FileReaderCommonsIOImpl implements FileReader { @Override public String getDetectedEncoding(File file) { InputStream is = null; String encoding = null; try { is = new FileInputStream(file); UniversalDetector detector = new UniversalDetector(null); byte[] buf = new byte[4096]; int nread; while ((nread = is.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } detector.dataEnd(); encoding = detector.getDetectedCharset(); } catch (IOException e) { } finally { IOUtils.closeQuietly(is); if (encoding == null) { return Charset.defaultCharset().name(); } } return encoding; } }
FileReaderCommonsIOImpl implements FileReader { @Override public String getDetectedEncoding(File file) { InputStream is = null; String encoding = null; try { is = new FileInputStream(file); UniversalDetector detector = new UniversalDetector(null); byte[] buf = new byte[4096]; int nread; while ((nread = is.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } detector.dataEnd(); encoding = detector.getDetectedCharset(); } catch (IOException e) { } finally { IOUtils.closeQuietly(is); if (encoding == null) { return Charset.defaultCharset().name(); } } return encoding; }  }
FileReaderCommonsIOImpl implements FileReader { @Override public String getDetectedEncoding(File file) { InputStream is = null; String encoding = null; try { is = new FileInputStream(file); UniversalDetector detector = new UniversalDetector(null); byte[] buf = new byte[4096]; int nread; while ((nread = is.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } detector.dataEnd(); encoding = detector.getDetectedCharset(); } catch (IOException e) { } finally { IOUtils.closeQuietly(is); if (encoding == null) { return Charset.defaultCharset().name(); } } return encoding; }  @Override InputStream getResourceAsStream(String name); @Override String readAsString(File file); @Override String getDetectedEncoding(File file); }
FileReaderCommonsIOImpl implements FileReader { @Override public String getDetectedEncoding(File file) { InputStream is = null; String encoding = null; try { is = new FileInputStream(file); UniversalDetector detector = new UniversalDetector(null); byte[] buf = new byte[4096]; int nread; while ((nread = is.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } detector.dataEnd(); encoding = detector.getDetectedCharset(); } catch (IOException e) { } finally { IOUtils.closeQuietly(is); if (encoding == null) { return Charset.defaultCharset().name(); } } return encoding; }  @Override InputStream getResourceAsStream(String name); @Override String readAsString(File file); @Override String getDetectedEncoding(File file);  }