org.jline.terminal.Terminal.encoding()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(204)

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

Terminal.encoding介绍

[英]Returns the Charset that should be used to encode characters for #input() and #output().
[中]返回应用于对#input()和#output()的字符进行编码的字符集。

代码示例

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.core

@Override
public Charset encoding() {
  return terminal.encoding();
}

代码示例来源:origin: apache/karaf

@Override
public Charset encoding() {
  return terminal.encoding();
}

代码示例来源:origin: apache/karaf

private Charset getEncoding(PrintStream ps) {
  if (ps.getClass() == ThreadPrintStream.class) {
    try {
      return ((Terminal) Job.Utils.current().session().get(".jline.terminal")).encoding();
    } catch (Throwable t) {
      // ignore
    }
    try {
      ps = (PrintStream) ps.getClass().getMethod("getCurrent").invoke(ps);
    } catch (Throwable t) {
      // ignore
    }
  }
  try {
    Field f = ps.getClass().getDeclaredField("charOut");
    f.setAccessible(true);
    OutputStreamWriter osw = (OutputStreamWriter) f.get(ps);
    return Charset.forName(osw.getEncoding());
  } catch (Throwable t) {
    // ignore
  }
  return null;
}

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.core

private Charset getEncoding(PrintStream ps) {
  if (ps.getClass() == ThreadPrintStream.class) {
    try {
      return ((Terminal) Job.Utils.current().session().get(".jline.terminal")).encoding();
    } catch (Throwable t) {
      // ignore
    }
    try {
      ps = (PrintStream) ps.getClass().getMethod("getCurrent").invoke(ps);
    } catch (Throwable t) {
      // ignore
    }
  }
  try {
    Field f = ps.getClass().getDeclaredField("charOut");
    f.setAccessible(true);
    OutputStreamWriter osw = (OutputStreamWriter) f.get(ps);
    return Charset.forName(osw.getEncoding());
  } catch (Throwable t) {
    // ignore
  }
  return null;
}

代码示例来源:origin: org.jline/jline

private static int readExt(Terminal terminal) {
  try {
    // The coordinates are encoded in UTF-8, so if that's not the input encoding,
    // we need to get around
    int c;
    if (terminal.encoding() != StandardCharsets.UTF_8) {
      c = new InputStreamReader(terminal.input(), StandardCharsets.UTF_8).read();
    } else {
      c = terminal.reader().read();
    }
    if (c < 0) {
      throw new EOFException();
    }
    return c;
  } catch (IOException e) {
    throw new IOError(e);
  }
}

相关文章