@Override public String charset() { return charset.toString(); }
/** * 获取编码 * * @return 编码 * @since 4.1.11 */ public String getCharsetStr() { return charset.toString(); }
System.out.println( URLEncoder.encode( "urlParameterString", java.nio.charset.StandardCharsets.UTF_8.toString() ) );
/** * 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; }
/** * 获取请求的Content-Type,附加编码信息 * @return 请求的Content-Type */ private String getXmlContentType() { return TEXT_XML_CONTENT_TYPE.concat(this.charset.toString()); } //------------------------------------------------------------------------------------------------------------------------- Private method end
/** * 获取请求的Content-Type,附加编码信息 * @return 请求的Content-Type */ private String getXmlContentType() { return TEXT_XML_CONTENT_TYPE.concat(this.charset.toString()); } //------------------------------------------------------------------------------------------------------------------------- Private method end
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); } }
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); } }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
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); }
/** * 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); }
/** * 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); }
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; }