org.jruby.Ruby.getDefaultExternalEncoding()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(114)

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

Ruby.getDefaultExternalEncoding介绍

暂无

代码示例

代码示例来源:origin: org.jruby/jruby-core

public static Encoding defaultExternalEncoding(Ruby runtime) {
  if (runtime.getDefaultExternalEncoding() != null) return runtime.getDefaultExternalEncoding();
  return runtime.getEncodingService().getLocaleEncoding();
}

代码示例来源:origin: org.jruby/jruby-complete

public Encoding toEncoding(Ruby runtime) {
    switch (this) {
    case LOCALE: return runtime.getEncodingService().getLocaleEncoding();
    case EXTERNAL: return runtime.getDefaultExternalEncoding();
    case INTERNAL: return runtime.getDefaultInternalEncoding();
    case FILESYSTEM: return runtime.getDefaultFilesystemEncoding();
    default:
      throw new AssertionError("invalid SpecialEncoding: " + this);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-core

public Encoding toEncoding(Ruby runtime) {
    switch (this) {
    case LOCALE: return runtime.getEncodingService().getLocaleEncoding();
    case EXTERNAL: return runtime.getDefaultExternalEncoding();
    case INTERNAL: return runtime.getDefaultInternalEncoding();
    case FILESYSTEM: return runtime.getDefaultFilesystemEncoding();
    default:
      throw new AssertionError("invalid SpecialEncoding: " + this);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(module = true)
public static synchronized IRubyObject systmpdir(ThreadContext context, IRubyObject recv) {
  Ruby runtime = context.getRuntime();
  ByteList tmp = ByteList.create(System.getProperty("java.io.tmpdir")); // default for all platforms except Windows
  if (Platform.IS_WINDOWS) {
    String commonAppData = System.getenv("CSIDL_COMMON_APPDATA");
    if (commonAppData != null) tmp = ByteList.create(commonAppData);
  }
  RubyString ret = RubyString.newString(runtime, tmp, runtime.getDefaultExternalEncoding());
  ret.untaint(context);
  return ret;
}

代码示例来源:origin: org.jruby/jruby-complete

public static final Encoding frobnicateEncoding(IRubyObject io) {
  // Non-ripper IO will not have encoding so we will just use default external
  if (!io.respondsTo("encoding")) return io.getRuntime().getDefaultExternalEncoding();
  
  IRubyObject encodingObject = io.callMethod(io.getRuntime().getCurrentContext(), "encoding");
  return encodingObject instanceof RubyEncoding ? 
      ((RubyEncoding) encodingObject).getEncoding() : io.getRuntime().getDefaultExternalEncoding();
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(module = true)
public static synchronized IRubyObject systmpdir(ThreadContext context, IRubyObject recv) {
  Ruby runtime = context.getRuntime();
  ByteList tmp = ByteList.create(System.getProperty("java.io.tmpdir")); // default for all platforms except Windows
  if (Platform.IS_WINDOWS) {
    String commonAppData = System.getenv("CSIDL_COMMON_APPDATA");
    if (commonAppData != null) tmp = ByteList.create(commonAppData);
  }
  RubyString ret = RubyString.newString(runtime, tmp, runtime.getDefaultExternalEncoding());
  ret.untaint(context);
  return ret;
}

代码示例来源:origin: org.jruby/jruby-core

public static final Encoding frobnicateEncoding(IRubyObject io) {
  // Non-ripper IO will not have encoding so we will just use default external
  if (!io.respondsTo("encoding")) return io.getRuntime().getDefaultExternalEncoding();
  
  IRubyObject encodingObject = io.callMethod(io.getRuntime().getCurrentContext(), "encoding");
  return encodingObject instanceof RubyEncoding ? 
      ((RubyEncoding) encodingObject).getEncoding() : io.getRuntime().getDefaultExternalEncoding();
}

代码示例来源:origin: org.jruby/jruby-complete

public static void rbEncSetDefaultExternal(ThreadContext context, IRubyObject encoding) {
  if (encoding.isNil()) {
    throw context.runtime.newArgumentError("default external can not be nil");
  }
  Encoding[] enc_p = {context.runtime.getDefaultExternalEncoding()};
  encSetDefaultEncoding(context, enc_p, encoding, "external");
  context.runtime.setDefaultExternalEncoding(enc_p[0]);
}

代码示例来源:origin: org.jruby/jruby-core

public static void rbEncSetDefaultExternal(ThreadContext context, IRubyObject encoding) {
  if (encoding.isNil()) {
    throw context.runtime.newArgumentError("default external can not be nil");
  }
  Encoding[] enc_p = {context.runtime.getDefaultExternalEncoding()};
  encSetDefaultEncoding(context, enc_p, encoding, "external");
  context.runtime.setDefaultExternalEncoding(enc_p[0]);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static void rbEncSetDefaultExternal(ThreadContext context, IRubyObject encoding) {
  if (encoding.isNil()) {
    throw context.runtime.newArgumentError("default external can not be nil");
  }
  
  Encoding[] enc_p = {context.runtime.getDefaultExternalEncoding()};
  encSetDefaultEncoding(context, enc_p, encoding, "external");
  context.runtime.setDefaultExternalEncoding(enc_p[0]);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static void rbEncSetDefaultExternal(ThreadContext context, IRubyObject encoding) {
  if (encoding.isNil()) {
    throw context.runtime.newArgumentError("default external can not be nil");
  }
  
  Encoding[] enc_p = {context.runtime.getDefaultExternalEncoding()};
  encSetDefaultEncoding(context, enc_p, encoding, "external");
  context.runtime.setDefaultExternalEncoding(enc_p[0]);
}

代码示例来源:origin: org.jruby/jruby-core

public IRubyObject getDefaultExternal() {
  Encoding defaultEncoding = runtime.getDefaultExternalEncoding();
  if (defaultEncoding == null) {
    // TODO: MRI seems to default blindly to US-ASCII and we were using Charset default from Java...which is right?
    ByteList encodingName = ByteList.create("US-ASCII");
    defaultEncoding = runtime.getEncodingService().loadEncoding(encodingName);
    runtime.setDefaultExternalEncoding(defaultEncoding);
  }
  return getEncoding(defaultEncoding);
}

代码示例来源:origin: org.jruby/jruby-complete

public IRubyObject getDefaultExternal() {
  Encoding defaultEncoding = runtime.getDefaultExternalEncoding();
  if (defaultEncoding == null) {
    // TODO: MRI seems to default blindly to US-ASCII and we were using Charset default from Java...which is right?
    ByteList encodingName = ByteList.create("US-ASCII");
    defaultEncoding = runtime.getEncodingService().loadEncoding(encodingName);
    runtime.setDefaultExternalEncoding(defaultEncoding);
  }
  return getEncoding(defaultEncoding);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(module = true)
public static synchronized IRubyObject sysconfdir(ThreadContext context, IRubyObject recv) {
  Ruby runtime = context.getRuntime();
  ByteList tmp = ByteList.create(RbConfigLibrary.getSysConfDir(runtime)); // default for all platforms except Windows
  
  if (Platform.IS_WINDOWS) {
    String localAppData = System.getenv("CSIDL_LOCAL_APPDATA");
    // TODO: need fallback mechanism
    if (localAppData != null) tmp = ByteList.create(localAppData);
  }
  RubyString ret = RubyString.newString(runtime, tmp, runtime.getDefaultExternalEncoding());
  ret.untaint(context);
  return ret;
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(module = true)
public static synchronized IRubyObject sysconfdir(ThreadContext context, IRubyObject recv) {
  Ruby runtime = context.getRuntime();
  ByteList tmp = ByteList.create(RbConfigLibrary.getSysConfDir(runtime)); // default for all platforms except Windows
  
  if (Platform.IS_WINDOWS) {
    String localAppData = System.getenv("CSIDL_LOCAL_APPDATA");
    // TODO: need fallback mechanism
    if (localAppData != null) tmp = ByteList.create(localAppData);
  }
  RubyString ret = RubyString.newString(runtime, tmp, runtime.getDefaultExternalEncoding());
  ret.untaint(context);
  return ret;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public IRubyObject getDefaultExternal() {
  IRubyObject defaultExternal = convertEncodingToRubyEncoding(runtime.getDefaultExternalEncoding());
  if (defaultExternal.isNil()) {
    // TODO: MRI seems to default blindly to US-ASCII and we were using Charset default from Java...which is right?
    ByteList encodingName = ByteList.create("US-ASCII");
    Encoding encoding = runtime.getEncodingService().loadEncoding(encodingName);
    runtime.setDefaultExternalEncoding(encoding);
    defaultExternal = convertEncodingToRubyEncoding(encoding);
  }
  return defaultExternal;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public IRubyObject getDefaultExternal() {
  IRubyObject defaultExternal = convertEncodingToRubyEncoding(runtime.getDefaultExternalEncoding());
  if (defaultExternal.isNil()) {
    // TODO: MRI seems to default blindly to US-ASCII and we were using Charset default from Java...which is right?
    ByteList encodingName = ByteList.create("US-ASCII");
    Encoding encoding = runtime.getEncodingService().loadEncoding(encodingName);
    runtime.setDefaultExternalEncoding(encoding);
    defaultExternal = convertEncodingToRubyEncoding(encoding);
  }
  return defaultExternal;
}

代码示例来源:origin: org.jruby/jruby-complete

protected final String validateConstant(String name, IRubyObject errorName) {
  if (IdUtil.isValidConstantName(name)) return name;
  Ruby runtime = getRuntime();
  Encoding resultEncoding = runtime.getDefaultInternalEncoding();
  if (resultEncoding == null) resultEncoding = runtime.getDefaultExternalEncoding();
  // MRI is more complicated than this and distinguishes between ID and non-ID.
  RubyString nameString = errorName.asString();
  // MRI does strlen to check for \0 vs Ruby string length.
  if ((nameString.getEncoding() != resultEncoding && !nameString.isAsciiOnly()) ||
      nameString.toString().indexOf('\0') > -1 ) {
    nameString = (RubyString) nameString.inspect();
  }
  throw getRuntime().newNameError("wrong constant name " + nameString, name);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private static ByteList regexpDescription19(Ruby runtime, byte[] s, int start, int len, RegexpOptions options, Encoding enc) {
  ByteList description = new ByteList();
  description.setEncoding(enc);
  description.append((byte)'/');
  Encoding resultEnc = runtime.getDefaultInternalEncoding();
  if (resultEnc == null) resultEnc = runtime.getDefaultExternalEncoding();
  
  appendRegexpString19(runtime, description, s, start, len, enc, resultEnc);
  description.append((byte)'/');
  appendOptions(description, options);
  if (options.isEncodingNone()) description.append((byte) 'n');
  return description; 
}

代码示例来源:origin: org.jruby/jruby-complete

private static ByteList regexpDescription19(Ruby runtime, byte[] s, int start, int len, RegexpOptions options, Encoding enc) {
  ByteList description = new ByteList();
  description.setEncoding(enc);
  description.append((byte)'/');
  Encoding resultEnc = runtime.getDefaultInternalEncoding();
  if (resultEnc == null) resultEnc = runtime.getDefaultExternalEncoding();
  appendRegexpString19(runtime, description, s, start, len, enc, resultEnc);
  description.append((byte)'/');
  appendOptions(description, options);
  if (options.isEncodingNone()) description.append((byte) 'n');
  return description;
}

相关文章

Ruby类方法