Examples of EBinary


Examples of erjang.EBinary

  private static final EAtom am_minor_version = EAtom.intern("minor_version");
  private static final EAtom am_safe = EAtom.intern("safe");

  @BIF
  public static EObject binary_to_term(EObject arg) {
    EBinary bin;
    if ((bin=arg.testBinary()) == null) throw ERT.badarg(arg);
    EInputStream in = bin.getInputStream();
    try {
      EObject val = in.read_any();
      //System.out.println("DECODED:"+val);
      return val;
    } catch (IOException e) {
View Full Code Here

Examples of erjang.EBinary

    }
  }

  @BIF
  public static EObject binary_to_term(EObject arg, EObject opts) {
    EBinary bin; ESeq options;
    if ((bin=arg.testBinary()) == null || (options = opts.testSeq()) == null) throw ERT.badarg(arg);
    EInputStream in = bin.getInputStream();
    if (!options.isNil()) {
      if (options.head() == am_safe) {
        in.setSafe(true);
      }
    }
View Full Code Here

Examples of erjang.EBinary

    }
  }

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

Examples of erjang.EBinary

    }

    if (resource == null) {
      return null;
    } else {
      EBinary bin = null;
      try {
        bin = IO.istream2binary(resource);
        return bin;
      } catch (IOException e) {
        return null;
View Full Code Here

Examples of erjang.EBinary

    return eos.getBinaryContent();   
  }
 
  @BIF
  public static ESmall external_size(EObject obj) {
    EBinary bin = term_to_binary(obj);
    return ERT.box(bin.byteSize());
  }
View Full Code Here

Examples of erjang.EBinary

   
  }

  @BIF
  public static EInteger binary_to_integer(EObject obj) {
    EBinary bin;
    if ((bin = obj.testBinary()) == null)
      throw ERT.badarg(obj);

    // remove leading +
    int off = 0;
    if (bin.byteSize() > 0) {
      if (bin.byteAt(0) == '+') {
        off += 1;
      }
    }
   
    try {
      byte[] bytes = bin.getByteArray();
      String sval = new String(bytes, off, bytes.length-off, IO.ISO_LATIN_1);
      return ERT.box_parse(sval);
     
    } catch (NumberFormatException e) {
      throw ERT.badarg(obj);
View Full Code Here

Examples of erjang.EBinary

   
  }

  @BIF
  public static EInteger binary_to_integer(EObject obj, EObject radix) {
    EBinary bin;
    ESmall rdx;
    if ((bin = obj.testBinary()) == null || (rdx = radix.testSmall()) == null)
      throw ERT.badarg(obj, radix);

    // remove leading +
    int off = 0;
    if (bin.byteSize() > 0) {
      if (bin.byteAt(0) == '+') {
        off += 1;
      }
    }
   
    try {
      byte[] bytes = bin.getByteArray();
      String sval = new String(bytes, off, bytes.length-off, IO.ISO_LATIN_1);
      return ERT.box(new BigInteger(sval, rdx.value));
     
    } catch (NumberFormatException e) {
      throw ERT.badarg(obj);
View Full Code Here

Examples of erjang.EBinary

    return ETuple.make(seq.toArray());
  }

  @BIF
  public static EString binary_to_list(EObject obj) {
    EBinary bin = obj.testBinary();
    if (bin == null)
      throw ERT.badarg(obj);
    return EString.make(bin);
  }
View Full Code Here

Examples of erjang.EBinary

    return bin.toList();
  }

  @BIF
  public static EString binary_to_list(EObject obj, EObject start, EObject stop) {
    EBinary bin = obj.testBinary();
    ESmall s = start.testSmall();
    ESmall e = stop.testSmall();
    if (bin == null || s==null || e==null)
      throw ERT.badarg(obj,start,stop);

    int idx0start = s.value-1;
    int len = e.value-s.value+1;

    if (idx0start < 0 || len < 0 || (idx0start + len) > bin.byteSize())
      throw ERT.badarg(obj, start, stop);

    return EString.make(bin, idx0start, len);
  }
View Full Code Here

Examples of erjang.EBinary

    ECons cons;
    for (tail=iol; (cons = tail.testNonEmptyList()) != null; tail = cons.tail()) {
      EObject hd = cons.head();

      ESmall sm;
      EBinary bi;
      ECons co;
      if ((sm = hd.testSmall()) != null) {
        if (sm.value < 0 || sm.value > 255)
          throw ERT.badarg(list);
        barr.write(sm.value);
      } else if ((bi = hd.testBinary()) != null) {
        bi.writeTo(barr);
      } else if ((co = hd.testNonEmptyList()) != null) {
        collectList(list, co, barr);
      } else if (hd.isNil()) {
      } else {
        throw ERT.badarg(list);
      }
    }

    // Process tail:
    EBinary bi;
    if ((bi = tail.testBinary()) != null) {
      try {
        bi.writeTo(barr);
      } catch (IOException e) {
        throw new InternalError("should not happen");
      }
    } else if (! tail.isNil()) {
      throw ERT.badarg(list);
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.