java.nio.charset.Charset.canEncode()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(97)

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

Charset.canEncode介绍

[英]Returns true if this charset supports encoding, false otherwise.
[中]

代码示例

代码示例来源:origin: commons-io/commons-io

private boolean isAvailabilityTestableForCharset(final String csName) {
  return Charset.forName(csName).canEncode()
      && !"COMPOUND_TEXT".equalsIgnoreCase(csName) && !"x-COMPOUND_TEXT".equalsIgnoreCase(csName)
      && !isOddBallLegacyCharsetThatDoesNotSupportFrenchCharacters(csName);
}

代码示例来源:origin: pholser/junit-quickcheck

private static CodePoints load(Charset c) {
  if (!c.canEncode())
    throw new IllegalArgumentException("Charset " + c.name() + " does not support encoding");
  return encodableCodePoints(c.newEncoder());
}

代码示例来源:origin: com.anrisoftware.globalpom/globalpomutils-core

/**
 * @see Charset#canEncode()
 * @since 2.6
 */
public boolean canEncode() {
  return charset.canEncode();
}

代码示例来源:origin: nu.validator.htmlparser/htmlparser

/**
 * @return
 * @see java.nio.charset.Charset#canEncode()
 */
public boolean canEncode() {
  return charset.canEncode();
}

代码示例来源:origin: nu.validator/htmlparser

/**
 * @return
 * @see java.nio.charset.Charset#canEncode()
 */
public boolean canEncode() {
  return charset.canEncode();
}

代码示例来源:origin: validator/htmlparser

/**
 * @return
 * @see java.nio.charset.Charset#canEncode()
 */
public boolean canEncode() {
  return charset.canEncode();
}

代码示例来源:origin: org.exbin.deltahex/deltahex-swing

public boolean isValidChar(char value) {
  return charset.canEncode();
}

代码示例来源:origin: mjanicek/rembulan

StringByteString(String s, Charset charset) {
  this.string = Objects.requireNonNull(s);
  this.charset = Objects.requireNonNull(charset);
  if (!charset.canEncode()) {
    throw new IllegalArgumentException("Charset cannot encode: " + charset.name());
  }
  this.byteHashCode = 0;
  this.byteLength = string.isEmpty() ? 0 : -1;
}

代码示例来源:origin: org.apache.ws.commons/ws-commons-util

public void startDocument() throws SAXException {
  Charset charSet = Charset.forName(getEncoding());
  if (charSet.canEncode()) {
    charsetEncoder = charSet.newEncoder();
  }
}

代码示例来源:origin: org.hudsonci.plugins/analysis-core

/**
   * Returns the encoding used to read a file. If the specified
   * encoding is empty or <code>null</code>, or if the encoding is not valid
   * then the default encoding of the platform is returned.
   *
   * @param encoding
   *            identifier of the character set
   * @return the default encoding for the specified encoding string
   */
  public static String getEncoding(@CheckForNull final String encoding) {
    if (StringUtils.isNotBlank(encoding) && Charset.forName(encoding).canEncode()) {
      return encoding;
    }
    return Charset.defaultCharset().name();
  }
}

代码示例来源:origin: uk.org.okapibarcode/okapibarcode

public static EciMode of(String data, String charsetName, int mode) {
  try {
    Charset charset = Charset.forName(charsetName);
    if (charset.canEncode() && charset.newEncoder().canEncode(data)) {
      return new EciMode(mode, charset);
    } else {
      return NONE;
    }
  } catch (UnsupportedCharsetException e) {
    return NONE;
  }
}

代码示例来源:origin: jenkinsci/analysis-core-plugin

/**
   * Returns the encoding used to read a file. If the specified
   * encoding is empty or <code>null</code>, or if the encoding is not valid
   * then the default encoding of the platform is returned.
   *
   * @param encoding
   *            identifier of the character set
   * @return the default encoding for the specified encoding string
   */
  public static String getEncoding(@CheckForNull final String encoding) {
    if (StringUtils.isNotBlank(encoding) && Charset.forName(encoding).canEncode()) {
      return encoding;
    }
    return Charset.defaultCharset().name();
  }
}

代码示例来源:origin: com.pholser/junit-quickcheck-generators

private static CodePoints load(Charset c) {
  if (!c.canEncode())
    throw new IllegalArgumentException("Charset " + c.name() + " does not support encoding");
  return encodableCodePoints(c.newEncoder());
}

代码示例来源:origin: io.github.splotycode.mosaik/Util

public static boolean isValidFileName(String name) {
  if (name.length() == 0 || name.equals(".") || name.equals("..")) {
    return false;
  }
  for (int i = 0; i < name.length(); i++) {
    if (!isValidFileNameChar(name.charAt(i))) {
      return false;
    }
  }
  if (name.length() >= 3 && name.length() <= 4 && WINDOWS_NAMES.contains(name.toUpperCase(Locale.US))) {
    return false;
  }
  Charset cs = Charsets.UTF16;
  return cs.canEncode() && cs.newEncoder().canEncode(name);
}

代码示例来源:origin: com.oracle.substratevm/svm

public static void addCharset(Charset charset) {
    Map<String, Charset> charsets = ImageSingletons.lookup(LocalizationSupport.class).charsets;
    charsets.put(charset.name().toLowerCase(), charset);
    for (String name : charset.aliases()) {
      charsets.put(name.toLowerCase(), charset);
    }

    /* Eagerly initialize all the tables necessary for decoding / encoding. */
    charset.newDecoder();
    if (charset.canEncode()) {
      charset.newEncoder();
    }
  }
}

代码示例来源:origin: org.apache.ws.commons.util/ws-commons-util

public void startDocument() throws SAXException {
  String enc = getEncoding();
  if (enc == null) {
    enc = "UTF-8";
  }
  Charset charSet = Charset.forName(enc);
  if (charSet.canEncode()) {
    charsetEncoder = charSet.newEncoder();
  }
  super.startDocument();
}

代码示例来源:origin: org.apache.jackrabbit.vault/org.apache.jackrabbit.vault

/**
 * Creates new {@code EncodingInfo} instance.
 */
public EncodingInfo(String ianaName, String javaName, int lastPrintable) {
  this.ianaName = ianaName;
  this.javaName = EncodingMap.getIANA2JavaMapping(ianaName);
  this.lastPrintable = lastPrintable;
  try {
    nioCharset = Charset.forName(this.javaName);
    if (nioCharset.canEncode())
      nioCharEncoder = nioCharset.newEncoder();
  } catch (IllegalCharsetNameException ie) {
    nioCharset = null;
    nioCharEncoder = null;
  } catch (UnsupportedCharsetException ue) {
    nioCharset = null;
    nioCharEncoder = null;
  }
}

代码示例来源:origin: org.apache.ws.jaxme/jaxme2

public void init(JMMarshallerImpl pController) throws JAXBException {
 super.init(pController);
 Charset charSet = Charset.forName(pController.getEncoding());
 if (charSet.canEncode()) {
  charsetEncoder = charSet.newEncoder();
 }
}

代码示例来源:origin: com.phloc/phloc-commons-jdk5

@Nonnull
 public static byte [] getAsBytes (@Nonnull final String sText, @Nonnull final Charset aCharset)
 {
  ValueEnforcer.notNull (sText, "Text");
  ValueEnforcer.notNull (aCharset, "Charset");
  if (!aCharset.canEncode ())
   throw new IllegalArgumentException ("Cannot encode to " + aCharset);

  // IFJDK5
   return getAsBytes (sText, aCharset.name ());
  // ELSE
//    return sText.getBytes (aCharset);
  // ENDIF
 }

代码示例来源:origin: usethesource/rascal

public IBool canEncode(IString charset) {
  return values.bool(Charset.forName(charset.getValue()).canEncode());
}

相关文章