php.runtime.Memory.getBinaryBytes()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中php.runtime.Memory.getBinaryBytes()方法的一些代码示例,展示了Memory.getBinaryBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Memory.getBinaryBytes()方法的具体详情如下:
包路径:php.runtime.Memory
类名称:Memory
方法名:getBinaryBytes

Memory.getBinaryBytes介绍

暂无

代码示例

代码示例来源:origin: jphp-group/jphp

public static Memory binaryShr(Memory o1, Memory o2){
  byte[] bytes1 = o1.getBinaryBytes();
  byte[] bytes2 = o2.getBinaryBytes();
  byte[] result = bytes1.length <= bytes2.length
      ? Arrays.copyOf(bytes1, bytes1.length)
      : Arrays.copyOf(bytes2, bytes2.length);
  for(int i = 0; i < result.length; i++){
    result[i] = (byte)(bytes1[i] >> bytes2[i]);
  }
  return new BinaryMemory(result);
}

代码示例来源:origin: jphp-group/jphp

public static Memory binaryShl(Memory o1, Memory o2){
  byte[] bytes1 = o1.getBinaryBytes();
  byte[] bytes2 = o2.getBinaryBytes();
  byte[] result = bytes1.length <= bytes2.length
      ? Arrays.copyOf(bytes1, bytes1.length)
      : Arrays.copyOf(bytes2, bytes2.length);
  for(int i = 0; i < result.length; i++){
    result[i] = (byte)(bytes1[i] << bytes2[i]);
  }
  return new BinaryMemory(result);
}

代码示例来源:origin: jphp-group/jphp

public static Memory binaryXor(Memory o1, Memory o2){
  byte[] bytes1 = o1.getBinaryBytes();
  byte[] bytes2 = o2.getBinaryBytes();
  byte[] result = bytes1.length <= bytes2.length
      ? Arrays.copyOf(bytes1, bytes1.length)
      : Arrays.copyOf(bytes2, bytes2.length);
  for(int i = 0; i < result.length; i++){
    result[i] = (byte)(bytes1[i] ^ bytes2[i]);
  }
  return new BinaryMemory(result);
}

代码示例来源:origin: jphp-group/jphp

public static Memory binaryAnd(Memory o1, Memory o2){
  byte[] bytes1 = o1.getBinaryBytes();
  byte[] bytes2 = o2.getBinaryBytes();
  byte[] result = bytes1.length <= bytes2.length
      ? Arrays.copyOf(bytes1, bytes1.length)
      : Arrays.copyOf(bytes2, bytes2.length);
  for(int i = 0; i < result.length; i++){
    result[i] = (byte)(bytes1[i] & bytes2[i]);
  }
  return new BinaryMemory(result);
}

代码示例来源:origin: jphp-group/jphp

public static Memory binaryOr(Memory o1, Memory o2){
  byte[] bytes1 = o1.getBinaryBytes();
  byte[] bytes2 = o2.getBinaryBytes();
  int min = Math.min(bytes1.length, bytes2.length);
  byte[] result = bytes1.length > bytes2.length
      ? Arrays.copyOf(bytes1, bytes1.length)
      : Arrays.copyOf(bytes2, bytes2.length);
  for(int i = 0; i < min; i++){
    result[i] = (byte)(bytes1[i] | bytes2[i]);
  }
  return new BinaryMemory(result);
}

代码示例来源:origin: jphp-group/jphp

@Signature
public PHttpServerResponse write(Memory value, String charset) throws IOException {
  response.getOutputStream().write(value.getBinaryBytes(Charset.forName(charset)));
  return this;
}

代码示例来源:origin: jphp-group/jphp

public static Memory binaryNot(Memory o1){
  byte[] bytes = o1.getBinaryBytes();
  bytes = Arrays.copyOf(bytes, bytes.length);
  for(int i = 0; i < bytes.length; i++){
    bytes[i] = (byte)~bytes[i];
  }
  return new BinaryMemory(bytes);
}

代码示例来源:origin: jphp-group/jphp

@Immutable
public static int crc32(Environment env, Memory value) {
  CRC32 crc = new CRC32();
  crc.update(value.getBinaryBytes(env.getDefaultCharset()));
  return (int) crc.getValue();
}

代码示例来源:origin: jphp-group/jphp

@Signature
public void __construct(Environment env, Memory data, String algorithm) {
  __wrappedObject = new SecretKeySpec(
      data.getBinaryBytes(env.getDefaultCharset()), algorithm
  );
}

代码示例来源:origin: jphp-group/jphp

public static Memory md5(Environment env, Memory value, boolean rawOutput) {
  MessageDigest md = md5Digest.get();
  md.reset();
  md.update(value.getBinaryBytes(env.getDefaultCharset()));
  if (rawOutput)
    return new BinaryMemory(md.digest());
  else
    return new StringMemory(DigestUtils.bytesToHex(md.digest()));
}

代码示例来源:origin: jphp-group/jphp

public static Memory sha1(Environment env, Memory value, boolean rawOutput) {
  MessageDigest md = sha1Digest.get();
  md.reset();
  md.update(value.getBinaryBytes(env.getDefaultCharset()));
  if (rawOutput) {
    return new BinaryMemory(md.digest());
  } else {
    return new StringMemory(DigestUtils.bytesToHex(md.digest()));
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
  public Memory decode(Environment env, Memory data, Key key) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
    getWrappedObject().init(Cipher.DECRYPT_MODE, key);
    byte[] result = getWrappedObject().doFinal(data.getBinaryBytes(charset));
    return StringMemory.valueOf(new String(result, charset));
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory encode(Environment env, Memory data, Key key) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
  getWrappedObject().init(Cipher.ENCRYPT_MODE, key);
  byte[] result = getWrappedObject().doFinal(data.getBinaryBytes(charset));
  return new BinaryMemory(result);
}

代码示例来源:origin: jphp-group/jphp

@Signature({
    @Arg("value"),
    @Arg(value = "algorithm", optional = @Optional("SHA-1"))
})
public static Memory hash(Environment env, Memory... args) throws NoSuchAlgorithmException {
  MessageDigest messageDigest = MessageDigest.getInstance(args[1].toString());
  messageDigest.update(args[0].getBinaryBytes(env.getDefaultCharset()));
  return StringMemory.valueOf(DigestUtils.bytesToHex(messageDigest.digest()));
}

代码示例来源:origin: jphp-group/jphp

@Override
public Memory write(Environment env, Memory... args) throws IOException {
  int len      = args[1].toInteger();
  byte[] bytes = args[0].getBinaryBytes(env.getDefaultCharset());
  len          = len == 0 || len > bytes.length ? bytes.length : len;
  getOutputStream().write(bytes, 0, len);
  return LongMemory.valueOf(len);
}

代码示例来源:origin: jphp-group/jphp

@Signature({@Arg("value"), @Arg(value = "length", optional = @Optional("NULL"))})
public Memory write(Environment env, Memory... args){
  int len = args[1].toInteger();
  byte[] bytes = args[0].getBinaryBytes(env.getDefaultCharset());
  try {
    accessFile.write(bytes, 0, len == 0 ? bytes.length : len);
    return LongMemory.valueOf(len == 0 ? bytes.length : len);
  } catch (IOException e) {
    env.exception(WrapIOException.class, e.getMessage());
  }
  return Memory.FALSE;
}

代码示例来源:origin: jphp-group/jphp

@Override
public int read(byte[] b, int off, int len) throws IOException {
  Memory result = stream.read(env, LongMemory.valueOf(len));
  if (!result.isString())
    return -1;
  byte[] copy = result.getBinaryBytes(env.getDefaultCharset());
  System.arraycopy(copy, 0, b, off, copy.length);
  return copy.length;
}

代码示例来源:origin: jphp-group/jphp

@Override
public int read() throws IOException {
  Memory result = stream.read(env, Memory.CONST_INT_1);
  return result.isString() ? result.getBinaryBytes(env.getDefaultCharset())[0] & 0xFF : -1;
}

代码示例来源:origin: jphp-group/jphp

@Signature
  public void writeEntryHeader(Environment env, Memory outbuf) {
    getWrappedObject().writeEntryHeader(outbuf.getBinaryBytes(env.getDefaultCharset()));
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public void addFromString(Environment env, String path, Memory string, int compressLevel) {
  ZipUtil.addOrReplaceEntries(zipFile, new ZipEntrySource[] {
    new ByteSource(path, string.getBinaryBytes(env.getDefaultCharset()), compressLevel)
  });
}

相关文章