Home | History | Annotate | Download | only in check
      1 /*
      2  * Check
      3  *
      4  * Author: Lasse Collin <lasse.collin (at) tukaani.org>
      5  *
      6  * This file has been put into the public domain.
      7  * You can do whatever you want with this file.
      8  */
      9 
     10 package org.tukaani.xz.check;
     11 
     12 import org.tukaani.xz.XZ;
     13 import org.tukaani.xz.UnsupportedOptionsException;
     14 
     15 public abstract class Check {
     16     int size;
     17     String name;
     18 
     19     public abstract void update(byte[] buf, int off, int len);
     20     public abstract byte[] finish();
     21 
     22     public void update(byte[] buf) {
     23         update(buf, 0, buf.length);
     24     }
     25 
     26     public int getSize() {
     27         return size;
     28     }
     29 
     30     public String getName() {
     31         return name;
     32     }
     33 
     34     public static Check getInstance(int checkType)
     35             throws UnsupportedOptionsException {
     36         switch (checkType) {
     37             case XZ.CHECK_NONE:
     38                 return new None();
     39 
     40             case XZ.CHECK_CRC32:
     41                 return new CRC32();
     42 
     43             case XZ.CHECK_CRC64:
     44                 return new CRC64();
     45 
     46             case XZ.CHECK_SHA256:
     47                 try {
     48                     return new SHA256();
     49                 } catch (java.security.NoSuchAlgorithmException e) {}
     50 
     51                 break;
     52         }
     53 
     54         throw new UnsupportedOptionsException(
     55                 "Unsupported Check ID " + checkType);
     56     }
     57 }
     58