AppSchemaValidator { static String getEncoding(String xml) { Matcher m = XML_ENCODING_PATTERN.matcher(xml); if (m.matches()) { return m.group(1); } else { return null; } } private  AppSchemaValidator(); private  AppSchemaValidator(SchemaResolver resolver); private  AppSchemaValidator(SchemaCatalog catalog); List<String> getFailures(); boolean isFailOnWarning(); void setFailOnWarning(boolean failOnWarning); void parse(InputStream input); void checkForFailures(); static AppSchemaValidator buildValidator(); static AppSchemaValidator buildValidator(SchemaResolver resolver); static AppSchemaValidator buildValidator(SchemaCatalog catalog); static void validateResource(String name, SchemaCatalog catalog); static void validate(String xml, SchemaCatalog catalog); static void validate(InputStream input, SchemaCatalog catalog);  }
@Test public void getEncoding() { Assert.assertNull(AppSchemaValidator.getEncoding("")); Assert.assertNull(AppSchemaValidator.getEncoding("<?xml version=\"1.0\"?>")); Assert.assertNull(AppSchemaValidator.getEncoding("<?xml version=\"1.0\"? >")); Assert.assertNull(AppSchemaValidator.getEncoding("<?xml version=\"1.0\"?><root/>")); Assert.assertEquals("UTF-8", AppSchemaValidator.getEncoding("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); Assert.assertEquals("UTF-8", AppSchemaValidator.getEncoding("<?xml version='1.0' encoding='UTF-8'?>")); Assert.assertEquals("UTF-8", AppSchemaValidator.getEncoding("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); Assert.assertEquals("UTF-8", AppSchemaValidator .getEncoding("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>")); Assert.assertEquals("UTF-8", AppSchemaValidator.getEncoding("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root/>")); }