本文整理匯總了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;
}
}