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

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

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

Charset.toString介绍

[英]Gets a string representation of this charset. Usually this contains the canonical name of the charset.
[中]获取此字符集的字符串表示形式。通常它包含字符集的规范名称。

代码示例

代码示例来源:origin: eclipse-vertx/vert.x

@Override
public String charset() {
 return charset.toString();
}

代码示例来源:origin: looly/hutool

/**
 * 获取编码
 * 
 * @return 编码
 * @since 4.1.11
 */
public String getCharsetStr() {
  return charset.toString();
}

代码示例来源:origin: stackoverflow.com

System.out.println(
 URLEncoder.encode(
  "urlParameterString",
  java.nio.charset.StandardCharsets.UTF_8.toString()
 )
);

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the charset for this charset.
 *
 * @param charset The charset to use
 * @return An instance of MultiPartSpecBuilder
 */
public MultiPartSpecBuilder charset(Charset charset) {
  Validate.notNull(charset, "Charset cannot be null");
  this.charset = charset.toString();
  return this;
}

代码示例来源:origin: looly/hutool

/**
 * 获取请求的Content-Type,附加编码信息
 * @return 请求的Content-Type
 */
private String getXmlContentType() {
  return TEXT_XML_CONTENT_TYPE.concat(this.charset.toString());
}
//------------------------------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: looly/hutool

/**
 * 获取请求的Content-Type,附加编码信息
 * @return 请求的Content-Type
 */
private String getXmlContentType() {
  return TEXT_XML_CONTENT_TYPE.concat(this.charset.toString());
}
//------------------------------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: JessYanCoding/MVPArms

public static String convertCharset(Charset charset) {
    String s = charset.toString();
    int i = s.indexOf("[");
    if (i == -1)
      return s;
    return s.substring(i + 1, s.length() - 1);
  }
}

代码示例来源:origin: rest-assured/rest-assured

public static String encode(final String content, final String encoding) {
  try {
    String encoded = URLEncoder.encode(content, encoding != null ? encoding : Charset.defaultCharset().toString());
    // We replace spaces encoded as "+" to %20 because some server (such as Scalatra) doesn't decode "+" correctly.
    encoded = StringUtils.replace(encoded, PLUS, PERCENTAGE_20);
    return encoded;
  } catch (UnsupportedEncodingException problem) {
    throw new IllegalArgumentException(problem);
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * The a "value" from an XML file using XPath.
 * <p>
 * Uses the system encoding for reading the file.
 *
 * @param xpath The XPath expression to select the value.
 * @param file The file to read.
 * @return The data value. An empty {@link String} is returned when the expression does not evaluate
 * to anything in the document.
 * @throws IOException Error reading from the file.
 * @throws SAXException Error parsing the XML file data e.g. badly formed XML.
 * @throws XPathExpressionException Invalid XPath expression.
 * @since 2.0
 */
public static @Nonnull String getValue(@Nonnull String xpath, @Nonnull File file) throws IOException, SAXException, XPathExpressionException {
  return getValue(xpath, file, Charset.defaultCharset().toString());
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Configure the decoder config to use the default charset as specified by {@link java.nio.charset.Charset#defaultCharset()} for content decoding.
 */
public DecoderConfig() {
  this(Charset.defaultCharset().toString(), DEFAULT_NO_WRAP_FOR_INFLATE_ENCODED_STREAMS, false, DEFAULT_CHARSET_FOR_CONTENT_TYPE, defaultContentEncoders());
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify a charset for this content-type
 *
 * @param charset The charset
 * @return The content-type with the given charset.
 */
public String withCharset(Charset charset) {
  if (charset == null) {
    throw new IllegalArgumentException("charset cannot be null");
  }
  return withCharset(charset.toString());
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset to use for the specific content-type if it's not specified in the content-type header explicitly
 *
 * @param charset     The charset to use as default (unless specified explicitly)
 * @param contentType The content-type
 * @return A new instance of {@link EncoderConfig}
 */
public EncoderConfig defaultCharsetForContentType(Charset charset, ContentType contentType) {
  notNull(charset, "Charset");
  return defaultCharsetForContentType(charset.toString(), contentType);
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset to use for the specific content-type if it's not specified in the content-type header explicitly
 *
 * @param charset     The charset to use as default (unless specified explicitly)
 * @param contentType The content-type
 * @return A new instance of {@link EncoderConfig}
 */
public EncoderConfig defaultCharsetForContentType(Charset charset, String contentType) {
  notNull(charset, "Charset");
  return defaultCharsetForContentType(charset.toString(), contentType);
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset of the content in the response that's assumed if no charset is explicitly specified in the response.
 *
 * @param charset The expected charset
 * @return A new instance of the DecoderConfig.
 */
@SuppressWarnings("UnusedDeclaration")
public DecoderConfig defaultContentCharset(Charset charset) {
  String charsetAsString = notNull(charset, Charset.class).toString();
  return new DecoderConfig(charsetAsString, useNoWrapForInflateDecoding, true, contentDecoders, contentTypeToDefaultCharset);
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset for the body/content in the request specification
 *
 * @param charset The charset to use.
 * @return A new instance of {@link EncoderConfig}
 */
public EncoderConfig defaultContentCharset(Charset charset) {
  String charsetAsString = notNull(charset, Charset.class).toString();
  return new EncoderConfig(charsetAsString, defaultQueryParameterCharset, shouldAppendDefaultContentCharsetToContentTypeIfUndefined, contentEncoders, contentTypeToDefaultCharset, true);
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset to use for the specific content-type if it's not specified in the content-type header explicitly
 *
 * @param charset     The charset to use as default (unless specified explicitly)
 * @param contentType The content-type
 * @return A new instance of {@link DecoderConfig}
 */
public DecoderConfig defaultCharsetForContentType(Charset charset, ContentType contentType) {
  notNull(charset, "Charset");
  return defaultCharsetForContentType(charset.toString(), contentType);
}

代码示例来源:origin: rest-assured/rest-assured

public static void logFileRequestBody(RequestSpecificationImpl reqSpec, Object requestBody, String contentType) {
  String charset = null;
  if (StringUtils.isNotBlank(contentType)) {
    charset = CharsetExtractor.getCharsetFromContentType(contentType);
  }
  if (charset == null) {
    charset = Charset.defaultCharset().toString();
  }
  String string = fileToString((File) requestBody, charset);
  reqSpec.body(string);
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset to use for the specific content-type if it's not specified in the content-type header explicitly
 *
 * @param charset     The charset to use as default (unless specified explicitly)
 * @param contentType The content-type
 * @return A new instance of {@link DecoderConfig}
 */
public DecoderConfig defaultCharsetForContentType(Charset charset, String contentType) {
  notNull(charset, "Charset");
  return defaultCharsetForContentType(charset.toString(), contentType);
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Specify the default charset for query parameters
 *
 * @param charset The charset to use.
 * @return A new instance of {@link EncoderConfig}
 */
@SuppressWarnings("UnusedDeclaration")
public EncoderConfig defaultQueryParameterCharset(Charset charset) {
  String charsetAsString = notNull(charset, Charset.class).toString();
  return new EncoderConfig(defaultContentCharset, charsetAsString, shouldAppendDefaultContentCharsetToContentTypeIfUndefined, contentEncoders, contentTypeToDefaultCharset, true);
}

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

private static HttpHeaders initHeaders(HttpHeaders headers, HttpServletRequest request) {
  MediaType contentType = headers.getContentType();
  if (contentType == null) {
    String requestContentType = request.getContentType();
    if (StringUtils.hasLength(requestContentType)) {
      contentType = MediaType.parseMediaType(requestContentType);
      headers.setContentType(contentType);
    }
  }
  if (contentType != null && contentType.getCharset() == null) {
    String encoding = request.getCharacterEncoding();
    if (StringUtils.hasLength(encoding)) {
      Charset charset = Charset.forName(encoding);
      Map<String, String> params = new LinkedCaseInsensitiveMap<>();
      params.putAll(contentType.getParameters());
      params.put("charset", charset.toString());
      headers.setContentType(
          new MediaType(contentType.getType(), contentType.getSubtype(),
              params));
    }
  }
  if (headers.getContentLength() == -1) {
    int contentLength = request.getContentLength();
    if (contentLength != -1) {
      headers.setContentLength(contentLength);
    }
  }
  return headers;
}

相关文章