本文整理汇总了Java中java.nio.charset.Charset.isSupported方法的典型用法代码示例。如果您正苦于以下问题:Java Charset.isSupported方法的具体用法?Java Charset.isSupported怎么用?Java Charset.isSupported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.isSupported方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static String validateCharset(String cs)
{
if (!Charset.isSupported(cs))
{
println("Charset " + cs + " is not supported\n");
println("Available charsets:");
println("Default = " + Charset.defaultCharset());
Map<String,Charset> available = Charset.availableCharsets();
for (Entry<String, Charset> entry: available.entrySet())
{
println(entry.getKey() + " " + available.get(entry.getValue()).aliases());
}
println("");
usage("Charset " + cs + " is not supported");
}
return cs;
}
示例2: charsetForName
import java.nio.charset.Charset; //导入方法依赖的package包/类
protected static Charset charsetForName(final String charsetName)
throws UnsupportedEncodingException {
String csn = charsetName;
if (csn == null) {
csn = Charset.defaultCharset().name();
}
try {
if (Charset.isSupported(csn)) {
return Charset.forName(csn);
}
} catch (IllegalCharsetNameException x) {}
throw new UnsupportedEncodingException(csn);
}
示例3: WriterOutputStream
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Creates WriterOutputStream from given java.io.Writer object with a
* specified encoding.
*
* @param writer
* java.io.Writer object to be converted to.
*/
public WriterOutputStream(Writer writer, String encoding) {
this.writer = writer;
if (encoding == null && writer instanceof OutputStreamWriter) {
// this encoding might be null when writer has been closed
encoding = ((OutputStreamWriter) writer).getEncoding();
}
if (encoding == null) {
encoding = Charset.defaultCharset().name();
} else if (!Charset.isSupported(encoding)) {
throw new IllegalArgumentException(encoding + " is not supported");
}
decoder = Charset.forName(encoding).newDecoder();
decoder.onMalformedInput(CodingErrorAction.REPLACE);
decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
}
示例4: toString
import java.nio.charset.Charset; //导入方法依赖的package包/类
public static String toString(byte[] bytes, String encoding) {
String str;
if (encoding != null && Charset.isSupported(encoding)) {
try {
str = new String(bytes, encoding);
} catch (UnsupportedEncodingException e) {
// Uses same func as Charset.isSupported (cannot happen)
str = new String(bytes);
}
} else {
str = new String(bytes);
}
return str;
}
示例5: makePlatformString
import java.nio.charset.Charset; //导入方法依赖的package包/类
static String makePlatformString(boolean printToStderr, byte[] inArray) {
initOutput(printToStderr);
if (encoding == null) {
encoding = System.getProperty(encprop);
isCharsetSupported = Charset.isSupported(encoding);
}
try {
String out = isCharsetSupported
? new String(inArray, encoding)
: new String(inArray);
return out;
} catch (UnsupportedEncodingException uee) {
abort(uee, null);
}
return null; // keep the compiler happy
}
示例6: LocalizedMessage
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Constructs a new LocalizedMessage using <code>resource</code> as the base name for the
* RessourceBundle and <code>id</code> as the message bundle id the resource file.
* @param resource base name of the resource file
* @param id the id of the corresponding bundle in the resource file
* @param encoding the encoding of the resource file
* @param arguments an array containing the arguments for the message
* @throws NullPointerException if <code>resource</code> or <code>id</code> is <code>null</code>
* @throws UnsupportedEncodingException if the encoding is not supported
*/
public LocalizedMessage(String resource, String id, String encoding, Object[] arguments) throws NullPointerException, UnsupportedEncodingException
{
if (resource == null || id == null || arguments == null)
{
throw new NullPointerException();
}
this.id = id;
this.resource = resource;
this.arguments = new FilteredArguments(arguments);
if (!Charset.isSupported(encoding))
{
throw new UnsupportedEncodingException("The encoding \"" + encoding + "\" is not supported.");
}
this.encoding = encoding;
}
示例7: decode
import java.nio.charset.Charset; //导入方法依赖的package包/类
public void decode(InputStream in, String contentType, Packet packet, AttachmentSet att ) throws IOException {
List<String> expectedContentTypes = getExpectedContentTypes();
if (contentType != null && !isContentTypeSupported(contentType,expectedContentTypes)) {
throw new UnsupportedMediaException(contentType, expectedContentTypes);
}
com.oracle.webservices.internal.api.message.ContentType pct = packet.getInternalContentType();
ContentTypeImpl cti = (pct != null && pct instanceof ContentTypeImpl) ?
(ContentTypeImpl)pct : new ContentTypeImpl(contentType);
String charset = cti.getCharSet();
if (charset != null && !Charset.isSupported(charset)) {
throw new UnsupportedMediaException(charset);
}
if (charset != null) {
packet.invocationProperties.put(DECODED_MESSAGE_CHARSET, charset);
} else {
packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
}
packet.setMessage(streamDecoder.decode(in, charset, att, soapVersion));
}
示例8: charsetForName
import java.nio.charset.Charset; //导入方法依赖的package包/类
protected static Charset charsetForName(
final String charsetName) throws SQLException {
String csn = charsetName;
if (csn == null) {
csn = Charset.defaultCharset().name();
}
try {
if (Charset.isSupported(csn)) {
return Charset.forName(csn);
}
} catch (IllegalCharsetNameException x) {
}
throw JDBCUtil.sqlException(new UnsupportedEncodingException(csn));
}
示例9: testNegative
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static void testNegative(String csn) {
if (Charset.isSupported(csn))
fail(csn, "Supported");
if (available.containsKey(csn))
fail(csn, "Available");
try {
Charset.forName(csn);
} catch (UnsupportedCharsetException x) {
out.println(csn + " not supported, as expected");
return;
}
fail(csn, "Lookup succeeded");
}
示例10: setContentCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
@Override
public void setContentCharset(String contentCharset) {
if (contentCharset == null) {
throw new InvalidUserDataException("contentCharset must not be null");
}
if (!Charset.isSupported(contentCharset)) {
throw new InvalidUserDataException(String.format("Charset for contentCharset '%s' is not supported by your JVM", contentCharset));
}
this.contentCharset = contentCharset;
}
示例11: isEncodingSupported
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Determines whether this JRE can both encode and decode text in the
* specified encoding.
*/
private static boolean isEncodingSupported(String encoding) {
if (encoding == null) {
return false;
}
try {
return Charset.isSupported(encoding);
} catch (IllegalCharsetNameException icne) {
return false;
}
}
示例12: safeCharSet
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static Charset safeCharSet(String charsetName) {
if (Charset.isSupported(charsetName)) {
return Charset.forName(charsetName);
} else {
return Charset.defaultCharset();
}
}
示例13: decode
import java.nio.charset.Charset; //导入方法依赖的package包/类
@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
//TODO shouldn't we check for SOAP1.1/SOAP1.2 and throw
//TODO UnsupportedMediaException like StreamSOAPCodec
String charset = null;
String ct = mpp.getRootPart().getContentType();
if (ct != null) {
charset = new ContentTypeImpl(ct).getCharSet();
}
if (charset != null && !Charset.isSupported(charset)) {
throw new UnsupportedMediaException(charset);
}
if (charset != null) {
packet.invocationProperties.put(DECODED_MESSAGE_CHARSET, charset);
} else {
packet.invocationProperties.remove(DECODED_MESSAGE_CHARSET);
}
// we'd like to reuse those reader objects but unfortunately decoder may be reused
// before the decoded message is completely used.
XMLStreamReader mtomReader = new MtomXMLStreamReaderEx( mpp,
XMLStreamReaderFactory.create(null, mpp.getRootPart().asInputStream(), charset, true)
);
packet.setMessage(codec.decode(mtomReader, new MimeAttachmentSet(mpp)));
packet.setMtomFeature(mtomFeature);
packet.setContentType(mpp.getContentType());
}
示例14: lookupCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static Charset lookupCharset(String csName) {
if (Charset.isSupported(csName)) {
try {
return Charset.forName(csName);
} catch (UnsupportedCharsetException x) {
throw new Error(x);
}
}
return null;
}
示例15: isEncodingSupported
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Determines whether this JRE can both encode and decode text in the
* specified encoding.
*/
public static boolean isEncodingSupported(String encoding) {
if (encoding == null) {
return false;
}
try {
return Charset.isSupported(encoding);
} catch (IllegalCharsetNameException icne) {
return false;
}
}