code: public static Charset getCharset(final InputStream inputStream) throws IOException
      {
          final Charset resultCharset;
          final byte[] buffer = new byte[192];
          final int reading = ByteStreams.read(inputStream, buffer, 0, 192);
          if (4 > reading)
          {
              resultCharset = Charset.forName(EncodingUtils.DEFAULT_ENCODING);
          }
          else
          {
              final long computed = (0xFF000000 & (buffer[0] << 24)) |
                      (0x00FF0000 & (buffer[1] << 16)) |
                      (0x0000FF00 & (buffer[2] << 8)) |
                      (0x000000FF & buffer[3]);
              if (0x0000FEFFL == computed || 0xFFFE0000L == computed)
              {
                  resultCharset = Charset.forName("UCS-4");
              }
              else if (0x0000003CL == computed)
              {
                  resultCharset = Charset.forName("UCS-4BE");
              }
              else if (0x3C000000L == computed)
              {
                  resultCharset = Charset.forName("UCS-4LE");
              }
              else if (0x003C003FL == computed)
              {
                  resultCharset = Charset.forName("UTF-16BE");
              }
              else if (0x3C003F00L == computed)
              {
                  resultCharset = Charset.forName("UTF-16LE");
              }
              else if (0x3C3F786DL == computed || 0x4C6FA794L == computed)
              {
                  resultCharset = EncodingUtils.getXmlCharsetEncoding(buffer);
              }
              else if (0xFEFF0000L == (computed & 0xFFFF0000L))
              {
                  resultCharset = Charset.forName("UTF-16");
              }
              else if (0xFFFE0000L == (computed & 0xFFFF0000L))
              {
                  resultCharset = Charset.forName("UTF-16");
              }
              else
              {
                  resultCharset = Charset.forName(EncodingUtils.DEFAULT_ENCODING);
              }
          }
          return resultCharset;
      }
docs: Gets charset of an inputstream.
  
  @param inputStream the input stream to analyse
  @return the charset identify
  @throws IOException if inputstream is unreadable