當前位置: 首頁>>代碼示例>>Java>>正文


Java Charset.isSupported方法代碼示例

本文整理匯總了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;
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:21,代碼來源:VDMJ.java

示例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);
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:18,代碼來源:JDBCClobFile.java

示例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);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:23,代碼來源:WriterOutputStream.java

示例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;
}
 
開發者ID:WhatAKitty,項目名稱:spark-project,代碼行數:17,代碼來源:StringUtils.java

示例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
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:LauncherHelper.java

示例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;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:LocalizedMessage.java

示例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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:StreamSOAPCodec.java

示例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));
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:19,代碼來源:JDBCClobClient.java

示例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");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:CharsetTest.java

示例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;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:11,代碼來源:DefaultManifest.java

示例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;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DataFlavorUtil.java

示例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();
  }
}
 
開發者ID:XDean,項目名稱:CSS-Editor-FX,代碼行數:8,代碼來源:Options.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:MtomCodec.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:Main.java

示例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;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:DataTransferer.java


注:本文中的java.nio.charset.Charset.isSupported方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。