本文整理了Java中php.runtime.env.Environment.getDefaultCharset()
方法的一些代码示例,展示了Environment.getDefaultCharset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.getDefaultCharset()
方法的具体详情如下:
包路径:php.runtime.env.Environment
类名称:Environment
方法名:getDefaultCharset
暂无
代码示例来源:origin: jphp-group/jphp
@Override
public ByteArrayInputStream convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
return new ByteArrayInputStream(arg.getBinaryBytes(env.getDefaultCharset()));
}
代码示例来源: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
public Memory getContents() throws UnsupportedEncodingException {
if (!binaryInBuffer){
return new StringMemory(buffer.toString(environment.getDefaultCharset().name()));
} else
return new BinaryMemory(buffer.toByteArray());
}
代码示例来源: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
protected Context getContext(String file) {
InputStream bootstrap = getResource(file);
if (bootstrap != null) {
return new Context(bootstrap, file, environment.getDefaultCharset());
} else
return null;
}
代码示例来源:origin: jphp-group/jphp
public Context fetchContext(Stream stream) throws Throwable {
if (stream instanceof FileStream) {
return new Context(
new BufferedInputStream(Stream.getInputStream(env, stream)), stream.getPath(), env.getDefaultCharset()
);
}
return new Context(
new BufferedInputStream(Stream.getInputStream(env, stream)), stream.getPath(), env.getDefaultCharset()
);
}
代码示例来源:origin: jphp-group/jphp
@Signature
public static String decode(Environment env, String text, Memory encoding) throws UnsupportedEncodingException {
return URLDecoder.decode(text, encoding.isNull() ? env.getDefaultCharset().name() : encoding.toString());
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public static String encode(Environment env, String text, Memory encoding) throws UnsupportedEncodingException {
return URLEncoder.encode(text, encoding.isNull() ? env.getDefaultCharset().name() : encoding.toString());
}
代码示例来源: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)
});
}
代码示例来源:origin: jphp-group/jphp
@Immutable
public static Memory strlen(Environment env, TraceInfo trace, Memory string) {
if (string.isArray()) {
env.warning(trace, "expects parameter 1 to be string, array given");
return Memory.NULL;
}
if (string instanceof BinaryMemory)
return LongMemory.valueOf(string.getBinaryBytes(env.getDefaultCharset()).length);
return LongMemory.valueOf(string.toString().length());
}
代码示例来源:origin: jphp-group/jphp
@Signature
public void addFromString(Environment env, PArchiveEntry entry, Memory contents) throws Throwable {
fetchOutput(env);
byte[] binaryBytes = contents.getBinaryBytes(env.getDefaultCharset());
env.assignProperty(entry, "size", LongMemory.valueOf(binaryBytes.length));
env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry));
outputStream.write(binaryBytes);
env.invokeMethod(output, "closeEntry");
}
代码示例来源:origin: jphp-group/jphp
public void write(Memory content) throws Throwable {
if (!isLock()){
content = content.toValue();
if (content instanceof BinaryMemory)
write(content.getBinaryBytes(environment.getDefaultCharset()));
else
write(content.toString());
}
}
内容来源于网络,如有侵权,请联系作者删除!