Examples of EBinary


Examples of erjang.EBinary

      repo.store(cv.getInternalClassName(), byteArray);
    }
  }

  public void compile(File file, BeamLoader beam_parser) throws IOException {
    EBinary eb = EUtil.readFile(file);
    BeamFileData bfd = beam_parser.load(eb.getByteArray());
    compile(bfd, this.classRepo);
  }
View Full Code Here

Examples of erjang.EBinary

  }
 
  @BIF
  public static EObject sha(EObject data)
  {
    EBinary bin = data.testBinary();
    if (bin == null)
      throw ERT.badarg(data);
   
    MessageDigest sha;
    try {
      sha = MessageDigest.getInstance("SHA");
    } catch (NoSuchAlgorithmException e) {
      throw ERT.badarg(data);
    }

    sha.digest(bin.getByteArray());
   
    byte[] res = sha.digest();
   
    return EBinary.make(res);
  }
View Full Code Here

Examples of erjang.EBinary

  }
 
  @BIF
  public static EObject md5(EObject data)
  {
    EBinary bin = data.testBinary();
    if (bin == null)
      throw ERT.badarg(data);
   
    MessageDigest md5;
    try {
      md5 = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      throw ERT.badarg(data);
    }

    md5.digest(bin.getByteArray());
   
    byte[] res = md5.digest();
   
    return EBinary.make(res);
  }
View Full Code Here

Examples of erjang.EBinary

  }
 
  @BIF
  public static EObject rand_uniform_nif(EObject from, EObject to)
  {
    EBinary fb = from.testBinary();
    EBinary tb = to.testBinary();
   
    if (fb == null || tb == null) {
      throw ERT.badarg(from, to);
    }
   
    BigInteger fi = mp2big(fb);
    BigInteger ti = mp2big(tb);
   
    if (log.isLoggable(Level.FINE)) log.fine("rand_uniform ("+fb+", "+tb+")");
   
    BigInteger interval = ti.subtract(fi).subtract(BigInteger.ONE);
   
    BigInteger base_value = new BigInteger(interval.bitLength(), rand);
   
    BigInteger result;
    while (interval.compareTo(base_value) == 1) {
      base_value = new BigInteger(interval.bitLength(), rand);
    }

    result = fi.add(base_value);
   
    if (log.isLoggable(Level.FINE)) log.fine("rand_uniform ("+fi+", "+ti+") -> "+result);

    EBinary res = big2mp(result);
    return res;
  }
View Full Code Here

Examples of erjang.EBinary

          return null;
        }
        pattern = out.toString();
      } else {
       
        EBinary bin;
        if ((bin = io_or_char_list.testBinary()) != null) {
          return EString.make(bin).stringValue();
        }
       
        EString str;
View Full Code Here

Examples of erjang.EBinary

    ByteBuffer out = ByteBuffer.allocate(4 + bytes.length);
    out.putInt(bytes.length);
    out.put(bytes);
    out.position(0);
   
    EBinary res = EBinary.make(out);
    return res;
  }
View Full Code Here

Examples of erjang.EBinary

public class Native extends ENative {

  @BIF
  public static EBinary compress(EObject bin) {
   
    EBinary b = bin.testBinary();
    if (b == null) {
      throw ERT.badarg(bin);
    }
   
    Deflater defl = new Deflater();
    BARR bos = new BARR();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos, defl);
   
    try {
      b.writeTo(dos);
      dos.close();
    } catch (IOException e) {
      throw new InternalError("should not happen");
    }
   
View Full Code Here

Examples of erjang.EBinary

    return bos.asBinary();   
  }
 
  static private class BARR extends ByteArrayOutputStream {
    EBinary asBinary() {
      return new EBinary(super.buf, 0, super.count);
    }
View Full Code Here

Examples of erjang.EBinary

            Insn.F insn = (Insn.F) insn_;
            ExtFun efun = insn.anon_fun.asExtFun();
            int numfree = insn.anon_fun.free_vars;
            int index = insn.anon_fun.index;
            int old_index = insn.anon_fun.old_index;
            EBinary uniq = insn.anon_fun.mod_md5;
            int old_uniq = insn.anon_fun.old_uniq;
           
            Arg[] free = new Arg[numfree];
            for (int i = 0; i < numfree; i++) {
              free[i] = new Arg(Arg.Kind.X, i, map[insn_idx]
View Full Code Here

Examples of erjang.EBinary

public class Native extends ENative
{
  @BIF
  public static EObject is_translatable(EObject arg) {
    EBinary bin = arg.testBinary();
    if (bin == null) throw ERT.badarg(arg);
   
    try {
      new String(bin.getByteArray(), IO.UTF8);
      return ERT.TRUE;
    } catch (RuntimeException e) {
      return ERT.FALSE;
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.