本文整理了Java中java.nio.charset.UnsupportedCharsetException
类的一些代码示例,展示了UnsupportedCharsetException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UnsupportedCharsetException
类的具体详情如下:
包路径:java.nio.charset.UnsupportedCharsetException
类名称:UnsupportedCharsetException
[英]An UnsupportedCharsetException is thrown when an unsupported charset name is encountered.
[中]遇到不受支持的字符集名称时,会引发UnsupportedCharsetException。
代码示例来源:origin: docker-java/docker-java
/**
* @see io.netty.handler.codec.http.QueryStringEncoder
*/
private static String encodeComponent(String s, Charset charset) {
// TODO: Optimize me.
try {
return URLEncoder.encode(s, charset.name()).replace("+", "%20");
} catch (UnsupportedEncodingException ignored) {
throw new UnsupportedCharsetException(charset.name());
}
}
代码示例来源:origin: wildfly/wildfly
static Charset getCharset(final String charsetName) throws UnsupportedEncodingException {
try {
return Charset.forName(charsetName);
} catch (UnsupportedCharsetException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
}
}
代码示例来源:origin: spring-projects/spring-framework
throw new InvalidMimeTypeException(mimeType, "unsupported charset '" + ex.getCharsetName() + "'");
代码示例来源:origin: wildfly/wildfly
private static void appendComponent(String s, String charset, StringBuilder sb) {
try {
s = URLEncoder.encode(s, charset);
} catch (UnsupportedEncodingException ignored) {
throw new UnsupportedCharsetException(charset);
}
// replace all '+' with "%20"
int idx = s.indexOf('+');
if (idx == -1) {
sb.append(s);
return;
}
sb.append(s, 0, idx).append("%20");
int size = s.length();
idx++;
for (; idx < size; idx++) {
char c = s.charAt(idx);
if (c != '+') {
sb.append(c);
} else {
sb.append("%20");
}
}
}
}
代码示例来源:origin: apache/ignite
/**
* Creates bulk load CSV parser.
*
* @param format Format options (parsed from COPY command).
*/
public BulkLoadCsvParser(BulkLoadCsvFormat format) {
try {
Charset charset = format.inputCharsetName() == null ? BulkLoadFormat.DEFAULT_INPUT_CHARSET :
Charset.forName(format.inputCharsetName());
inputBlock = new CharsetDecoderBlock(charset);
}
catch (IllegalCharsetNameException e) {
throw new IgniteSQLException("Unknown charset name: '" + format.inputCharsetName() + "': " +
e.getMessage());
}
catch (UnsupportedCharsetException e) {
throw new IgniteSQLException("Charset is not supported: '" + format.inputCharsetName() + "': " +
e.getMessage());
}
collectorBlock = new StrListAppenderBlock();
// Handling of the other options is to be implemented in IGNITE-7537.
inputBlock.append(new LineSplitterBlock(format.lineSeparator()))
.append(new CsvLineProcessorBlock(format.fieldSeparator(), format.quoteChars()))
.append(collectorBlock);
}
代码示例来源:origin: org.n52.security/52n-security-core
public StringInputStream(String pContent, String pCharset) throws UnsupportedEncodingException {
if (pCharset == null) {
pCharset = Charset.defaultCharset().name();
}
Charset charset;
try {
charset = Charset.forName(pCharset);
} catch (UnsupportedCharsetException e) {
throw new UnsupportedEncodingException(e.getCharsetName());
}
m_content = pContent;
initEncoder(charset);
initBuffers();
}
代码示例来源:origin: ldp4j/ldp4j
public static CharacterEncoding fromString(final String name) {
requireNonNull(name,"Character encoding name cannot be null");
try {
if(WILDCARD.equals(name)) {
return wildcard();
} else {
return of(Charset.forName(name));
}
} catch (final UnsupportedCharsetException ex) {
throw new IllegalArgumentException("Unsupported character encoding '"+ex.getCharsetName()+"'",ex);
} catch (final IllegalCharsetNameException ex) {
throw new IllegalArgumentException("Invalid character encoding name '"+ex.getCharsetName()+"'",ex);
}
}
代码示例来源:origin: com.caucho/resin
OutputStreamEncodingWriter(String javaEncoding)
throws UnsupportedEncodingException
{
try {
_encoding = javaEncoding;
if (Charset.isSupported(javaEncoding))
_charset = Charset.forName(javaEncoding);
else {
// server/054i
throw new UnsupportedEncodingException(javaEncoding);
}
} catch (java.nio.charset.UnsupportedCharsetException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
}
代码示例来源:origin: net.vvakame/jsonpullparser-core
/**
* Creates a new parser, using the given InputStream as its {@code JSON} feed.
*
* <p>
* Please call one of the {@code setSource(...)}'s before calling other methods.
* </p>
*
* @param is
* An InputStream serves as {@code JSON} feed. Cannot be null.
* @param charsetName
* The character set should be assumed in which in the stream are encoded. {@link #DEFAULT_CHARSET_NAME} is assumed if null is passed.
* @return {@link JsonPullParser}
* @throws UnsupportedEncodingException
* An unknown character set is specified.
* @throws IllegalArgumentException
* {@code null} has been passed in where not applicable.
*/
public static JsonPullParser newParser(InputStream is, String charsetName)
throws UnsupportedEncodingException {
if (is == null) {
throw new IllegalArgumentException("'is' must not be null.");
}
try {
final Charset charset = (charsetName == null) ? null : Charset.forName(charsetName);
return newParser(is, charset);
} catch (UnsupportedCharsetException e) {
throw new UnsupportedEncodingException(e.getCharsetName());
}
}
代码示例来源:origin: webx/citrus
/** 判断charset是否被支持。 */
public LocaleInfo assertCharsetSupported() throws UnsupportedCharsetException {
if (charset instanceof UnknownCharset) {
throw new UnsupportedCharsetException(charset.name());
}
return this;
}
代码示例来源:origin: com.google.code.echo-maven-plugin/echo-output
/**
* Saves text output
*
* @param message The text to save
*/
public void saveToFile(final String message) {
File saveFile = new File(defaultOutputPath, toFile);
String absolutePath = saveFile.getAbsolutePath();
mavenLogger.info("Saving output to " + absolutePath);
try {
checkForNonWritableFile(saveFile);
makeFileWritable(saveFile);
FileUtils.write(saveFile, message, encoding, appendToFile);
} catch (UnsupportedEncodingException ex) {
throw new FailureException(UNSUPPORTED_ENCODING + ex.getMessage(), ex);
} catch (UnsupportedCharsetException ex) {
throw new FailureException(UNSUPPORTED_ENCODING + ex.getMessage(), ex);
} catch (IOException ex) {
mavenLogger.debug(ex);
throw new FailureException("Could not save file: " + absolutePath, ex);
}
}
代码示例来源:origin: apache/flink
public void setCharsetName(String charsetName) throws IllegalCharsetNameException, UnsupportedCharsetException {
if (charsetName == null) {
throw new NullPointerException();
}
if (!Charset.isSupported(charsetName)) {
throw new UnsupportedCharsetException("The charset " + charsetName + " is not supported.");
}
this.charsetName = charsetName;
}
代码示例来源:origin: com.caucho/resin
/**
* Sets the character encoding of a post.
*/
public void setCharacterEncoding(String encoding)
throws UnsupportedEncodingException
{
// server/122k (tck)
if (_hasReadStream)
return;
_readEncoding = encoding;
try {
// server/122d (tck)
//if (_hasReadStream)
_readStream.setEncoding(_readEncoding);
} catch (UnsupportedEncodingException e) {
throw e;
} catch (java.nio.charset.UnsupportedCharsetException e) {
throw new UnsupportedEncodingException(e.getMessage());
}
}
代码示例来源:origin: apache/flume
+ "JSON handler supports UTF-8, "
+ "UTF-16 and UTF-32 only.", charset);
throw new UnsupportedCharsetException("JSON handler supports UTF-8, "
+ "UTF-16 and UTF-32 only.");
代码示例来源:origin: robovm/robovm
checkCharsetName(charsetName);
cs = NativeConverter.charsetForName(charsetName);
if (cs != null) {
return cacheCharset(charsetName, cs);
cs = charsetProvider.charsetForName(charsetName);
if (cs != null) {
return cacheCharset(charsetName, cs);
throw new UnsupportedCharsetException(charsetName);
代码示例来源:origin: spring-projects/spring-framework
@SuppressWarnings("deprecation")
private String decodeInternal(HttpServletRequest request, String source) {
String enc = determineEncoding(request);
try {
return UriUtils.decode(source, enc);
}
catch (UnsupportedCharsetException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Could not decode request string [" + source + "] with encoding '" + enc +
"': falling back to platform default encoding; exception message: " + ex.getMessage());
}
return URLDecoder.decode(source);
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
private InputStream createXMPStream(final String pXMP, final String pCharsetName) {
try {
return new SequenceInputStream(
Collections.enumeration(
Arrays.asList(
createRandomStream(79),
new ByteArrayInputStream(pXMP.getBytes(pCharsetName)),
createRandomStream(31)
)
)
);
}
catch (UnsupportedEncodingException e) {
UnsupportedCharsetException uce = new UnsupportedCharsetException(pCharsetName);
uce.initCause(e);
throw uce;
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
@Override
public T fromString(String str) throws IOException {
try {
byte[] bytes = Base64.decodeBase64(str.getBytes("UTF-8"));
inBuf.reset(bytes, bytes.length);
T restored = deserializer.deserialize(null);
return restored;
} catch (UnsupportedCharsetException ex) {
throw new IOException(ex.toString());
}
}
代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9
private String urlEncode(String value)
{
String encoding = "UTF-8";
try
{
return URLEncoder.encode(value, encoding);
}
catch (UnsupportedEncodingException e)
{
throw new UnsupportedCharsetException(encoding);
}
}
代码示例来源:origin: net.java.dev.jna/jna
/**
* Gets the charset belonging to the given {@code encoding}.
* @param encoding The encoding - if {@code null} then the default platform
* encoding is used.
* @return The charset belonging to the given {@code encoding} or the platform default.
* Never {@code null}.
*/
private static Charset getCharset(String encoding) {
Charset charset = null;
if (encoding != null) {
try {
charset = Charset.forName(encoding);
}
catch(IllegalCharsetNameException e) {
LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})",
new Object[]{encoding, e.getMessage()});
}
catch(UnsupportedCharsetException e) {
LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})",
new Object[]{encoding, e.getMessage()});
}
}
if (charset == null) {
LOG.log(Level.WARNING, "JNA Warning: Using fallback encoding {0}", Native.DEFAULT_CHARSET);
charset = Native.DEFAULT_CHARSET;
}
return charset;
}
内容来源于网络,如有侵权,请联系作者删除!