Source { @VisibleForTesting static Charset getCharSet(File file) { long bufferSize = file.length() < 9999 ? file.length() : 9999; byte[] buffer = new byte[(int) bufferSize]; try (InputStream initialStream = new FileInputStream(file)) { int bytesRead = initialStream.read(buffer); if (bytesRead < bufferSize) { throw new IOException("Was not able to read expected number of bytes"); } } catch (IOException e) { throw new IllegalStateException(e); } return getCharSet(buffer); } Source(File file);  Source(File file, Charset charset);  Source(Reader reader);  Source(InputStream inputStream);  Source(InputStream inputStream, Charset charset); static Source fromString(String s); static Source fromUrl(String url); File file(); Reader reader(); InputStream inputStream(); Reader createReader(byte[] cachedBytes);  }
@Test void getCharSet() { assertEquals( "ISO-8859-1", Source.getCharSet(Paths.get("../data", "urb_cpop1_1_Data.csv").toFile()).name()); }