php.runtime.env.Environment.getDefaultCharset()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(134)

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

Environment.getDefaultCharset介绍

暂无

代码示例

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

  1. @Override
  2. public ByteArrayInputStream convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
  3. return new ByteArrayInputStream(arg.getBinaryBytes(env.getDefaultCharset()));
  4. }

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

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

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

  1. public Memory getContents() throws UnsupportedEncodingException {
  2. if (!binaryInBuffer){
  3. return new StringMemory(buffer.toString(environment.getDefaultCharset().name()));
  4. } else
  5. return new BinaryMemory(buffer.toByteArray());
  6. }

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

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

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

  1. public static Memory md5(Environment env, Memory value, boolean rawOutput) {
  2. MessageDigest md = md5Digest.get();
  3. md.reset();
  4. md.update(value.getBinaryBytes(env.getDefaultCharset()));
  5. if (rawOutput)
  6. return new BinaryMemory(md.digest());
  7. else
  8. return new StringMemory(DigestUtils.bytesToHex(md.digest()));
  9. }

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

  1. public static Memory sha1(Environment env, Memory value, boolean rawOutput) {
  2. MessageDigest md = sha1Digest.get();
  3. md.reset();
  4. md.update(value.getBinaryBytes(env.getDefaultCharset()));
  5. if (rawOutput) {
  6. return new BinaryMemory(md.digest());
  7. } else {
  8. return new StringMemory(DigestUtils.bytesToHex(md.digest()));
  9. }
  10. }

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

  1. protected Context getContext(String file) {
  2. InputStream bootstrap = getResource(file);
  3. if (bootstrap != null) {
  4. return new Context(bootstrap, file, environment.getDefaultCharset());
  5. } else
  6. return null;
  7. }

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

  1. public Context fetchContext(Stream stream) throws Throwable {
  2. if (stream instanceof FileStream) {
  3. return new Context(
  4. new BufferedInputStream(Stream.getInputStream(env, stream)), stream.getPath(), env.getDefaultCharset()
  5. );
  6. }
  7. return new Context(
  8. new BufferedInputStream(Stream.getInputStream(env, stream)), stream.getPath(), env.getDefaultCharset()
  9. );
  10. }

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

  1. @Signature
  2. public static String decode(Environment env, String text, Memory encoding) throws UnsupportedEncodingException {
  3. return URLDecoder.decode(text, encoding.isNull() ? env.getDefaultCharset().name() : encoding.toString());
  4. }
  5. }

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

  1. @Signature
  2. public static String encode(Environment env, String text, Memory encoding) throws UnsupportedEncodingException {
  3. return URLEncoder.encode(text, encoding.isNull() ? env.getDefaultCharset().name() : encoding.toString());
  4. }

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

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

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

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

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

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

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

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

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

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

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

  1. @Signature
  2. public void writeEntryHeader(Environment env, Memory outbuf) {
  3. getWrappedObject().writeEntryHeader(outbuf.getBinaryBytes(env.getDefaultCharset()));
  4. }
  5. }

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

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

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

  1. @Immutable
  2. public static Memory strlen(Environment env, TraceInfo trace, Memory string) {
  3. if (string.isArray()) {
  4. env.warning(trace, "expects parameter 1 to be string, array given");
  5. return Memory.NULL;
  6. }
  7. if (string instanceof BinaryMemory)
  8. return LongMemory.valueOf(string.getBinaryBytes(env.getDefaultCharset()).length);
  9. return LongMemory.valueOf(string.toString().length());
  10. }

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

  1. @Signature
  2. public void addFromString(Environment env, PArchiveEntry entry, Memory contents) throws Throwable {
  3. fetchOutput(env);
  4. byte[] binaryBytes = contents.getBinaryBytes(env.getDefaultCharset());
  5. env.assignProperty(entry, "size", LongMemory.valueOf(binaryBytes.length));
  6. env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry));
  7. outputStream.write(binaryBytes);
  8. env.invokeMethod(output, "closeEntry");
  9. }

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

  1. public void write(Memory content) throws Throwable {
  2. if (!isLock()){
  3. content = content.toValue();
  4. if (content instanceof BinaryMemory)
  5. write(content.getBinaryBytes(environment.getDefaultCharset()));
  6. else
  7. write(content.toString());
  8. }
  9. }

相关文章