code: public static int getVersion(InputStream is, boolean littleEndianOk) throws IOException {
          if (! is.markSupported()) {
              throw new IllegalArgumentException("Input stream must support mark().");
              }
          is.mark(4);
          byte sig[] = new byte[4];
          int read = is.read(sig);
          is.reset();
  
          if (read != sig.length) {
              return 0;
          }
  
          if (sig[0]=='T' && sig[1]=='r' && sig[2]=='i' && sig[3]=='e') {
              return 1;
          }
          if (sig[0]=='T' && sig[1]=='r' && sig[2]=='i' && sig[3]=='2') {
              return 2;
          }
          if (littleEndianOk) {
              if (sig[0]=='e' && sig[1]=='i' && sig[2]=='r' && sig[3]=='T') {
                  return 1;
              }
              if (sig[0]=='2' && sig[1]=='i' && sig[2]=='r' && sig[3]=='T') {
                  return 2;
              }
          }
          return 0;
      }
docs: Get the UTrie version from an InputStream containing the serialized form
  of either a Trie (version 1) or a Trie2 (version 2).
  
  @param is   an InputStream containing the serialized form
  of a UTrie, version 1 or 2.  The stream must support mark() and reset().
  The position of the input stream will be left unchanged.
  @param littleEndianOk If FALSE, only big-endian (Java native) serialized forms are recognized.
  If TRUE, little-endian serialized forms are recognized as well.
  @return     the Trie version of the serialized form, or 0 if it is not
  recognized as a serialized UTrie
  @throws     IOException on errors in reading from the input stream.