当前位置: 首页>>代码示例>>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;未经允许,请勿转载。