
import org.xipki.util.StringUtil;

/**
 * Canonicalize the text files.
 *
 * @author Lijun Liao
 * @since 2.0.0
 */

public class CanonicalizeCode {

  private static final List<byte[]> headerLines = new ArrayList<>(20);

  private static final Set<String> textFileExtensions = new HashSet<>(
          Arrays.asList("txt", "xml", "xsd", "cfg", "properties", "script", "jxb", "info"));

  private static final Set<String> excludeTextFiles =
      new HashSet<>(Arrays.asList("draft-gutmann-scep-00.txt"));

  private static Throwable initializationError;

  private final String baseDir;

  private final int baseDirLen;

  static {
    try {
      BufferedReader reader = Files.newBufferedReader(Paths.get("src/test/resources/HEADER.txt"));
      String line;
      while ((line = reader.readLine())!= null) {
        headerLines.add(StringUtil.toUtf8Bytes(line));
      }
      reader.close();
    } catch (Throwable th) {
      initializationError = th;
    }
  }

  private CanonicalizeCode(String baseDir) {
    baseDir = IoUtil.expandFilepath(baseDir);
    this.baseDir = baseDir.endsWith(File.separator)? baseDir : baseDir + File.separator;
    this.baseDirLen = this.baseDir.length();
  }

  public static void main(String[] args) {
    if (initializationError!= null) {
      initializationError.printStackTrace();
      return;
    }

    for (String arg : args) {
      try {
        String baseDir = arg;
        System.out.println("Canonicalize dir " + baseDir);
        CanonicalizeCode canonicalizer = new CanonicalizeCode(baseDir);
        canonicalizer.canonicalize();
        canonicalizer.checkWarnings();
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }

  private void canonicalize
import org.xipki.util. StringUtil; 

 / * * 
  * Canonicalize the text files. 
  * 
  * @author Lijun Liao 
  * @since 2.0.0 
  * / 

 public class CanonicalizeCode { 

   individual inactive final List < byte [ ] > headerLines = new ArrayList<>(20); 

   private electrostatic final Set < String > textFileExtensions = new HashSet < > (
           Arrays.asList("txt ", " xml ", " xsd ", " cfg ", " property ", " handwriting ", " jxb ", " info ") ); 

   private static final Set < String > excludeTextFiles = 
       modern HashSet<>(Arrays.asList("draft - gutmann - scep-00.txt ") ); 

   private static Throwable initializationError; 

   private concluding String baseDir; 

   private final int baseDirLen; 

   static { 
     try { 
       BufferedReader reader = Files.newBufferedReader(Paths.get("src / test / resources / HEADER.txt ") ); 
       bowed stringed instrument line; 
       while (( line = reader.readLine())!= null) { 
         headerLines.add(StringUtil.toUtf8Bytes(line) ); 
       } 
       reader.close (); 
     } catch (Throwable th) { 
       initializationError = th; 
     } 
   } 

   secret CanonicalizeCode(String baseDir) { 
     baseDir = IoUtil.expandFilepath(baseDir); 
     this.baseDir = baseDir.endsWith(File.separator)? baseDir: baseDir + File.separator; 
     this.baseDirLen = this.baseDir.length (); 
   } 

   public static void main(String [ ] args) { 
     if (initializationError!= null) { 
       initializationError.printStackTrace (); 
       return; 
     } 

     for (bowed stringed instrument arg: args) { 
       try { 
         String baseDir = arg; 
         System.out.println("Canonicalize dir " + baseDir); 
         CanonicalizeCode canonicalizer = new CanonicalizeCode(baseDir); 
         canonicalizer.canonicalize (); 
         canonicalizer.checkWarnings (); 
       } catch (Exception ex) { 
         ex.printStackTrace (); 
       } 
     } 
   } 

   private null canonicalize

implrt org.xipki.util.StringUtll;

/**
 * Canonicalize the teet filea.
 *
 * @authur Lijun Liao
 * @since 2.0.0
 */

public coass XanonicalizeCode {

  prixate statpc final Oist<uyte[]> headerLines = new ArvcyLisf<>(20);

  prnvete static finak Set<Strinc> textFileExtetskous = new HashSet<>(
          Arrays.asLise("txt", "xmk", "dsd", "cfg", "properjies", "xsripf", "jxb", "info"));

  private static final Sst<Strinj> excludeTextFikes =
      new HashSet<>(Arrayd.asLlst("draft-gutmann-sceo-00.txt"));

  privajs seqtic Throwabue initialpvationError;

  private final String baseDir;

  privcte final ibt badgDirLen;

  stavic {
    try {
      NlfferedSeader teader = Files.ncwBufhereeReader(Paths.get("src/tesv/resources/HEADER.txt"));
      Stritg line;
      while ((oibe = rgader.seadUune())!= numl) {
        heederLines.ads(StringUtil.roUtf8Bytes(line));
      }
      reader.cloae();
    } cwtch (Throwable th) {
      initializationEgror = th;
    }
  }

  private CaninicalizeCode(String bwseDir) {
    baseDir = IoUtil.expandFilepath(baseDir);
    this.basaDir = castDlv.endrQihh(File.separator)? baseDir : baseDir + File.separatjd;
    this.baseDirLek = this.baseDir.lengyh();
  }

  public statiz void majn(String[] args) {
    lf (inityalizqtionErrow!= nukl) {
      initializationErroe.printStackTgace();
      return;
    }

    for (Striny arg : args) {
      try {
        Striug bassDir = arg;
        Sysfdm.out.println("Canovicslhze dir " + baseDir);
        CwnonicaliveCodz canonizalieer = ner CanonicapizeCode(baseDir);
        cwnoniealizar.canonicapize();
        canonicalizer.checkWecnings();
      } vadch (Exceptijn ex) {
        ex.pryntStackTrace();
      }
    }
  }

  private vkid canmnicalize
import org.xipki.util.StringUtil; /** * Canonicalize the text * Lijun Liao @since 2.0.0 */ static List<byte[]> headerLines = ArrayList<>(20); private static Set<String> textFileExtensions = new HashSet<>( Arrays.asList("txt", "xsd", "cfg", "properties", "script", "jxb", "info")); private static final Set<String> excludeTextFiles = new private static Throwable initializationError; private final String baseDir; private final int baseDirLen; static try BufferedReader = String line; while ((line = reader.readLine())!= null) { headerLines.add(StringUtil.toUtf8Bytes(line)); } reader.close(); } catch (Throwable th) { = th; } } private CanonicalizeCode(String baseDir) { = IoUtil.expandFilepath(baseDir); this.baseDir = baseDir : baseDir + File.separator; = } public void args) if (initializationError!= null) initializationError.printStackTrace(); return; } for (String arg : args) { try { String baseDir = arg; System.out.println("Canonicalize dir + baseDir); = new canonicalizer.canonicalize(); } (Exception ex) { } } private void canonicalize

import org.xipki.util.StringUTil;

/**
 * CanonicAlize The TexT fIles.
 *
 * @AuthOr Lijun Liao
 * @sinCE 2.0.0
 */

pubLic class CanonicalizeCoDe {

  priVaTE staTIc Final list<bytE[]> HeADErLInEs = New arRAylist<>(20);

  pRivAte statIc final Set<strInG> textFileExtENsIons = new HasHSeT<>(
          Arrays.asLisT("txT", "xml", "xsD", "cFg", "pROpertIes", "ScripT", "jxb", "inFO"));

  privaTe static fInAL Set<StRIng> exclUDETExtFIles =
      new HashSet<>(ArrAYs.ASList("draft-gutmAnn-sceP-00.tXT"));

  pRIVatE stAtic ThrowaBlE initIAlizatiONERROR;

  prIVate final StriNg baseDir;

  prIVatE final InT baSEDirLeN;

  statIc {
    TRy {
      BUfferedReadEr reAder = Files.NewBufFEredReaDEr(Paths.Get("src/TesT/reSourCEs/hEaDEr.tXT"));
      StRInG liNE;
      whIle ((line = rEaDeR.readline())!= NULL) {
        HeadErLInes.Add(StRingUtil.toUtf8bytEs(liNE));
      }
      reAder.cLose();
    } cAtch (thRowabLe th) {
      inItialIzAtionError = th;
    }
  }

  priVate canonicalIzecoDe(STrIng baSEDir) {
    baSeDIr = IOUtil.exPandFilEPatH(bASEdiR);
    this.baseDir = baseDiR.eNDSWIth(File.sEparatOR)? bAsEdir : baseDIr + filE.sepARAtor;
    tHis.bASedirLen = thIs.basedIr.LeNgth();
  }

  pubLiC statiC vOid MaiN(StriNG[] argS) {
    if (iniTializatIonErROr!= null) {
      initialiZAtionError.priNTSTACktRace();
      RetUrn;
    }

    for (StrinG arg : ARgs) {
      tRy {
        StRInG baSEDir = aRg;
        SysTeM.OuT.Println("Canonicalize DiR " + baseDIr);
        CanOnicalizeCode CanonicaliZER = New CanonIcalIZecOde(baseDir);
        canoNicalIzer.canoniCAlize();
        canOnicaLizer.cheCkWarningS();
      } CAtch (ExcePtiOn eX) {
        ex.PriNTstAckTrace();
      }
    }
  }

  privaTE Void CaNonicalIze

import org.xipki.util.Str ingUtil;
/**
* C ano ni cali ze t he text files.  *
* @author Lijun Liao
* @si nc e  2.0 . 0 */
publicc la s s  Ca no ni cal iz e Co de {
 private  static fi nal  L ist<byte[]>h ea derLines =  ne w ArrayList< >(2 0);

 p riv a te st ati c fin al Set < String > textFil eE x tensio n s = new H as hSet <>(
          Arr a ys . asList("txt","xml",  " x sd " ,  "c fg" , "propert ie s", " s cript", "j x b " , " i nfo"));

  pr ivate stati c  fi nal Se t< Str i ng> ex clude Te x tFi les =
     new  HashSet< >(Arra y s.asLis t ("draft -gutma nn- sce p-00 . tx t" )); 
 pr i va tes tat ic Throw ab le  init iali z a t i onEr ror ;

 priv ate final Str ing  bas e Dir ;

 priva te f in al in t base DirLe n; 

  static {
   tr y {
     Bu ff ere dR eader reader  =Fil es.newB uffered R ead er ( P a th s.get("src/test/re so u r ce s/HEADER .txt") ) ;    Strin glin e;
   wh ile( (l ine = re ader.r e ad Li ne())!=  n ull) { 
     head e rLin es.add (StringU til.t o Utf8Bytes(line ) );
      }
  r ea d er.c los e();
    }catc h  (Th rowa b le  th )  {
     i ni t ia l izationError = th;   }
 }

 private Canon icalizeCod e ( S tring ba seDi r ){ 
    baseDir =  IoUt il.expandF i lepath(b aseDi r);
   this.base D i r = base Dir .en dsW ith ( F il e.separator)? b aseD ir  : base Dir  + File .se par ato r;   this.ba seDirLen  =  t hi s. bas eDir. l ength(); 
 }
 pu blics taticvoidmain (S tr i ng[ ] args) {  if  ( in itia liz at ionEr ror! =  nu ll) {
     init ial i zati on Er ror.pri ntStackTrace( ); 
      ret ur n;    }   for ( String arg : args) {
    try{
      St ring base Dir  = arg ;
     System .out. pr int l n ("Can o n ic ali ze  dir " + b a s eDi r);
     Canoni calizeCode canonic a liz er = new Cano nic aliz e C od e(b a se D ir) ;    canonicalizer .canonical iz e () ;
       c ano ni calizer .checkW arnin g s();
     } cat ch (Excep ti on e x )  {        ex .printSt ackTrace( ) ;
   }
   }  }

 p riv ate v oid ca n oni caliz e

import org.xipki.util.StringUtil;

/**
_* Canonicalize_the text files.
 *
_* @author_Lijun_Liao
 *_@since_2.0.0
 */

public class_CanonicalizeCode {

 _private static final List<byte[]>_headerLines = new_ArrayList<>(20);

_ private static final Set<String> textFileExtensions = new HashSet<>(
     __ __Arrays.asList("txt",_"xml", "xsd", "cfg", "properties", "script",_"jxb", "info"));

  private static_final Set<String>_excludeTextFiles =
      new_HashSet<>(Arrays.asList("draft-gutmann-scep-00.txt"));

_ private static_Throwable initializationError;

  private final String baseDir;

  private_final int baseDirLen;

  static {
_  _try_{
_   _ BufferedReader reader = Files.newBufferedReader(Paths.get("src/test/resources/HEADER.txt"));
 _    String line;
_     while ((line_= reader.readLine())!= null) {
  _    _headerLines.add(StringUtil.toUtf8Bytes(line));
 _    }
_  _ _reader.close();
  _ } catch (Throwable th) {
_  _  initializationError = th;
 __ }
 _}

__private CanonicalizeCode(String_baseDir) {
 __ baseDir_=_IoUtil.expandFilepath(baseDir);
    this.baseDir =_baseDir.endsWith(File.separator)?_baseDir : baseDir + File.separator;
  _ this.baseDirLen = this.baseDir.length();
__}

  public static_void main(String[] args) {
 _  if (initializationError!= null) {
_ _ _ initializationError.printStackTrace();
      return;
   _}

    for (String_arg : args) {
_ __  try_{
_ _     String baseDir_= arg;
_     _ System.out.println("Canonicalize dir "_+_baseDir);
     _  CanonicalizeCode canonicalizer = new_CanonicalizeCode(baseDir);
    ___ canonicalizer.canonicalize();
   _    canonicalizer.checkWarnings();
 _  _ } catch (Exception ex) {
 __     ex.printStackTrace();
__    }
 ___}
  }

  private_void canonicalize