### Question:
XMLCharsetDeterminator { @Nullable public static Charset determineXMLCharset (@Nonnull final byte [] aBytes) { ValueEnforcer.notNull (aBytes, "Bytes"); Charset aParseCharset = null; int nSearchOfs = 0; if (aBytes.length > 0) { try (NonBlockingByteArrayInputStream aIS = new NonBlockingByteArrayInputStream (aBytes, 0, Math.min (EUnicodeBOM.getMaximumByteCount (), aBytes.length))) { final InputStreamAndCharset aISC = CharsetHelper.getInputStreamAndCharsetFromBOM (aIS); if (aISC.hasBOM ()) { nSearchOfs = aISC.getBOM ().getByteCount (); } if (aISC.hasCharset ()) { aParseCharset = aISC.getCharset (); } } } if (aParseCharset == null && aBytes.length - nSearchOfs >= 4) if (_match (aBytes, nSearchOfs, CS_UTF32_BE)) aParseCharset = CHARSET_UTF_32BE; else if (_match (aBytes, nSearchOfs, CS_UTF32_LE)) aParseCharset = CHARSET_UTF_32LE; else if (_match (aBytes, nSearchOfs, CS_UTF16_BE)) aParseCharset = StandardCharsets.UTF_16BE; else if (_match (aBytes, nSearchOfs, CS_UTF16_LE)) aParseCharset = StandardCharsets.UTF_16LE; else if (_match (aBytes, nSearchOfs, CS_UTF8)) aParseCharset = StandardCharsets.UTF_8; else if (_match (aBytes, nSearchOfs, CS_EBCDIC)) aParseCharset = CHARSET_EBCDIC; else if (_match (aBytes, nSearchOfs, CS_IBM290)) aParseCharset = CHARSET_IBM290; if (aParseCharset == null) { aParseCharset = FALLBACK_CHARSET; } return _parseXMLEncoding (aBytes, nSearchOfs, aParseCharset); } private  XMLCharsetDeterminator(); @Nonnull @ReturnsMutableCopy static ICommonsSet <Charset> getAllSupportedCharsets(); @Nullable static Charset determineXMLCharset(@Nonnull final byte [] aBytes); static final Charset FALLBACK_CHARSET; }### Answer:
@Test public void testAllBOMCharsets () { for (final EUnicodeBOM eBOM : EUnicodeBOM.values ()) if (eBOM.hasCharset ()) { final Charset c = eBOM.getCharset (); final ICommonsList <String> aNames = new CommonsArrayList <> (c.name ()); aNames.addAll (c.aliases ()); for (final String sAlias : aNames) { final String sXML = "<?xml version=\"1.0\" encoding=\"" + sAlias + "\"?><!-- " + c.name () + " --><root />"; if (false) LOGGER.info (sXML); final byte [] aBytes = sXML.getBytes (c); assertFalse ("Charset " + sAlias + " already contains BOM " + eBOM, eBOM.isPresent (aBytes)); final Charset aDetermined = XMLCharsetDeterminator.determineXMLCharset (ArrayHelper.getConcatenated (eBOM.getAllBytes (), aBytes)); assertEquals (c, aDetermined); } } }