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

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

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

Charset.displayName介绍

[英]Returns the name of this charset for the default locale.

The default implementation returns the canonical name of this charset. Subclasses may return a localized display name.
[中]返回默认区域设置的此字符集的名称。
默认实现返回此字符集的规范名称。子类可以返回本地化的显示名称。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the value of the {@linkplain #AUTHORIZATION Authorization} header to
 * Basic Authentication based on the given username and password.
 * @param username the username
 * @param password the password
 * @param charset the charset to use to convert the credentials into an octet
 * sequence. Defaults to {@linkplain StandardCharsets#ISO_8859_1 ISO-8859-1}.
 * @throws IllegalArgumentException if {@code username} or {@code password}
 * contains characters that cannot be encoded to the given charset
 * @since 5.1
 * @see <a href="https://tools.ietf.org/html/rfc7617">RFC 7617</a>
 */
public void setBasicAuth(String username, String password, @Nullable Charset charset) {
  Assert.notNull(username, "Username must not be null");
  Assert.notNull(password, "Password must not be null");
  if (charset == null) {
    charset = StandardCharsets.ISO_8859_1;
  }
  CharsetEncoder encoder = charset.newEncoder();
  if (!encoder.canEncode(username) || !encoder.canEncode(password)) {
    throw new IllegalArgumentException(
        "Username or password contains characters that cannot be encoded to " + charset.displayName());
  }
  String credentialsString = username + ":" + password;
  byte[] encodedBytes = Base64.getEncoder().encode(credentialsString.getBytes(charset));
  String encodedCredentials = new String(encodedBytes, charset);
  set(AUTHORIZATION, "Basic " + encodedCredentials);
}

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

private static Set<String> getStandardCharsetNames() {
  return STANDARD_CHARSETS.stream().map(c -> c.displayName()).collect(Collectors.toSet());
}

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

private static Set<String> getStandardCharsetNames() {
  return STANDARD_CHARSETS.stream().map(c -> c.displayName()).collect(Collectors.toSet());
}

代码示例来源:origin: pentaho/pentaho-kettle

private String[] getCharsets() {
 if ( charsets == null ) {
  Collection<Charset> charsetCol = Charset.availableCharsets().values();
  charsets = new String[charsetCol.size()];
  int i = 0;
  for ( Charset charset : charsetCol ) {
   charsets[i++] = charset.displayName();
  }
 }
 return charsets;
}

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

/**
 * Check whether UTF-8 is the default character encoding.
 * Differing character encodings across cluster may lead to erratic behavior.
 */
private void checkFileEncoding() {
  String encodingDisplayName = Charset.defaultCharset().displayName(Locale.ENGLISH);
  if (!"UTF-8".equals(encodingDisplayName)) {
    U.quietAndWarn(log, "Default character encoding is " + encodingDisplayName +
      ". Specify UTF-8 character encoding by setting -Dfile.encoding=UTF-8 JVM parameter. " +
      "Differing character encodings across cluster may lead to erratic behavior.");
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String guessEncodingName( File file ) throws FileNotFoundException, IOException {
 return guessEncoding( file, 4096 ).displayName();
}

代码示例来源:origin: org.springframework.boot/spring-boot

/**
 * Override Tomcat's default locale mappings to align with other servers. See
 * {@code org.apache.catalina.util.CharsetMapperDefault.properties}.
 * @param context the context to reset
 */
private void resetDefaultLocaleMapping(TomcatEmbeddedContext context) {
  context.addLocaleEncodingMappingParameter(Locale.ENGLISH.toString(),
      DEFAULT_CHARSET.displayName());
  context.addLocaleEncodingMappingParameter(Locale.FRENCH.toString(),
      DEFAULT_CHARSET.displayName());
}

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

/**
 * Returns an array of {@link AllowableValue} elements for each {@link Charset}. Only the charsets in {@link StandardCharsets} are returned to be consistent across JVM instances.
 *
 * @return an ordered {@code AllowableValue[]} containing the values
 */
public static AllowableValue[] buildCharacterSetAllowableValues() {
  final List<Charset> charsets = getSupportedCharsets();
  return charsets.stream().map(cs ->
       new AllowableValue(cs.name(),
           cs.displayName(),
           cs == StandardCharsets.UTF_16 ? UTF_16_DESCRIPTION : cs.displayName())
  ).toArray(AllowableValue[]::new);
}

代码示例来源:origin: wildfly/wildfly

private String extractCharset(HeaderMap headers) {
  String contentType = headers.getFirst(Headers.CONTENT_TYPE);
  if (contentType != null) {
    String value = Headers.extractQuotedValueFromHeader(contentType, "charset");
    if (value != null) {
      return value;
    }
    //if it is text we default to ISO_8859_1
    if(contentType.startsWith("text/")) {
      return StandardCharsets.ISO_8859_1.displayName();
    }
    return null;
  }
  return null;
}

代码示例来源:origin: SonarSource/sonarqube

private static DefaultInputModule createModule(ProjectDefinition def, int scannerComponentId) {
 LOG.debug("  Init module '{}'", def.getName());
 DefaultInputModule module = new DefaultInputModule(def, scannerComponentId);
 LOG.debug("    Base dir: {}", module.getBaseDir().toAbsolutePath().toString());
 LOG.debug("    Working dir: {}", module.getWorkDir().toAbsolutePath().toString());
 LOG.debug("    Module global encoding: {}, default locale: {}", module.getEncoding().displayName(), Locale.getDefault());
 return module;
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings() {
 // Encoding of the text file:
 if ( !gotEncodings ) {
  gotEncodings = true;
  wEncoding.removeAll();
  List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
  for ( int i = 0; i < values.size(); i++ ) {
   Charset charSet = values.get( i );
   wEncoding.add( charSet.displayName() );
  }
  // Now select the default!
  String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
  int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
  if ( idx >= 0 ) {
   wEncoding.select( idx );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings() {
 // Encoding of the text file:
 if ( !gotEncodings ) {
  gotEncodings = true;
  wEncoding.removeAll();
  List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
  for ( int i = 0; i < values.size(); i++ ) {
   Charset charSet = values.get( i );
   wEncoding.add( charSet.displayName() );
  }
  // Now select the default!
  String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
  int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
  if ( idx >= 0 ) {
   wEncoding.select( idx );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings( ComboVar var ) {
  // Encoding of the text file:
  String encoding = Const.NVL( var.getText(), Const.getEnvironmentVariable( "file.encoding", "UTF-8" ) );
  var.removeAll();
  ArrayList<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
  for ( int i = 0; i < values.size(); i++ ) {
   Charset charSet = values.get( i );
   var.add( charSet.displayName() );
  }

  // Now select the default!
  int idx = Const.indexOfString( encoding, var.getItems() );
  if ( idx >= 0 ) {
   var.select( idx );
  }
 }
}

代码示例来源:origin: hierynomus/sshj

public static String readFromFile(File f) throws IOException {
    FileInputStream fileInputStream = new FileInputStream(f);
    try {
      ByteArrayOutputStream byteArrayOutputStream = IOUtils.readFully(fileInputStream);
      return byteArrayOutputStream.toString(IOUtils.UTF8.displayName());
    } finally {
      IOUtils.closeQuietly(fileInputStream);
    }
  }
}

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

@Test
public void testMultiByteBreak() throws Exception {
  System.out.println("testMultiByteBreak() Default charset: "+Charset.defaultCharset().displayName());
  final long delay = 50;
  final File origin = new File(this.getClass().getResource("/test-file-utf8.bin").toURI());

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings() {
 // Encoding of the text file:
 if ( !gotEncodings ) {
  gotEncodings = true;
  wEncoding.removeAll();
  java.util.List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
  for ( Charset charSet : values ) {
   wEncoding.add( charSet.displayName() );
  }
  // Now select the default!
  String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
  int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
  if ( idx >= 0 ) {
   wEncoding.select( idx );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings() {
 // Encoding of the text file:
 if ( !gotEncodings ) {
  gotEncodings = true;
  wEncoding.removeAll();
  List<Charset> values = new ArrayList<>( Charset.availableCharsets().values() );
  for ( Charset charSet : values ) {
   wEncoding.add( charSet.displayName() );
  }
  // Now select the default!
  String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
  int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
  if ( idx >= 0 ) {
   wEncoding.select( idx );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings() {
  // Encoding of the text file:
  if ( !gotEncodings ) {
   gotEncodings = true;

   wEncoding.removeAll();
   java.util.List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
   for ( Charset charSet : values ) {
    wEncoding.add( charSet.displayName() );
   }

   // Now select the default!
   String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
   int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
   if ( idx >= 0 ) {
    wEncoding.select( idx );
   }
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void setEncodings() {
 // Encoding of the text file:
 if ( !gotEncodings ) {
  gotEncodings = true;
  wEncoding.removeAll();
  List<Charset> values = new ArrayList<Charset>( Charset.availableCharsets().values() );
  for ( Charset charSet : values ) {
   wEncoding.add( charSet.displayName() );
  }
  // Now select the default!
  String defEncoding = Const.getEnvironmentVariable( "file.encoding", "UTF-8" );
  int idx = Const.indexOfString( defEncoding, wEncoding.getItems() );
  if ( idx >= 0 ) {
   wEncoding.select( idx );
  }
 }
}

代码示例来源:origin: SonarSource/sonarqube

public DefaultInputProject provide(ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator,
                     ProjectReactor projectReactor, ScannerComponentIdGenerator scannerComponentIdGenerator) {
  if (project == null) {
   // 1 Apply project builders
   projectBuildersExecutor.execute(projectReactor);

   // 2 Validate final reactor
   validator.validate(projectReactor);

   // 3 Create project
   project = new DefaultInputProject(projectReactor.getRoot(), scannerComponentIdGenerator.getAsInt());

   LOG.info("Project key: {}", project.key());
   LOG.info("Base dir: {}", project.getBaseDir().toAbsolutePath().toString());
   LOG.info("Working dir: {}", project.getWorkDir().toAbsolutePath().toString());
   LOG.debug("Project global encoding: {}, default locale: {}", project.getEncoding().displayName(), Locale.getDefault());
  }
  return project;
 }
}

相关文章