Java 类java.nio.charset.IllegalCharsetNameException 实例源码

项目:OpenDiabetes    文件:JDBCClobFile.java   
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);
}
项目:OpenDiabetes    文件:JDBCClobClient.java   
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));
}
项目:the-vigilantes    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            Charset oldCs = charsetsByAlias.putIfAbsent(alias, cs);
            if (oldCs != null) {
                // if the previous value was recently set by another thread we return it instead of value we found here
                cs = oldCs;
            }
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:OpenVertretung    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            Charset oldCs = charsetsByAlias.putIfAbsent(alias, cs);
            if (oldCs != null) {
                // if the previous value was recently set by another thread we return it instead of value we found here
                cs = oldCs;
            }
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:lams    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            charsetsByAlias.putIfAbsent(alias, cs);
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:ProyectoPacientes    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            Charset oldCs = charsetsByAlias.putIfAbsent(alias, cs);
            if (oldCs != null) {
                // if the previous value was recently set by another thread we return it instead of value we found here
                cs = oldCs;
            }
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:dev-courses    文件:JDBCClobFile.java   
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);
}
项目:dev-courses    文件:JDBCClobClient.java   
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));
}
项目:OpenJSharp    文件:CodeSetConversion.java   
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
                        int alignmentForEncoding) {

    try {
        ctb = cache.getCharToByteConverter(codeset.getName());
        if (ctb == null) {
            Charset tmpCharset = Charset.forName(codeset.getName());
            ctb = tmpCharset.newEncoder();
            cache.setConverter(codeset.getName(), ctb);
        }
    } catch(IllegalCharsetNameException icne) {

        // This can only happen if one of our Entries has
        // an invalid name.
        throw wrapper.invalidCtbConverterName(icne,codeset.getName());
    } catch(UnsupportedCharsetException ucne) {

        // This can only happen if one of our Entries has
        // an unsupported name.
        throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
    }

    this.codeset = codeset;
    alignment = alignmentForEncoding;
}
项目:OpenJSharp    文件:CodeSetConversion.java   
/**
 * Utility method to find a CharsetDecoder in the
 * cache or create a new one if necessary.  Throws an
 * INTERNAL if the code set is unknown.
 */
protected CharsetDecoder getConverter(String javaCodeSetName) {

    CharsetDecoder result = null;
    try {
        result = cache.getByteToCharConverter(javaCodeSetName);

        if (result == null) {
            Charset tmpCharset = Charset.forName(javaCodeSetName);
            result = tmpCharset.newDecoder();
            cache.setConverter(javaCodeSetName, result);
        }

    } catch(IllegalCharsetNameException icne) {
        // This can only happen if one of our charset entries has
        // an illegal name.
        throw wrapper.invalidBtcConverterName( icne, javaCodeSetName ) ;
    }

    return result;
}
项目:OpenJSharp    文件:StringCoding.java   
static char[] decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                sd = new StringDecoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:OpenJSharp    文件:StringCoding.java   
static byte[] encode(String charsetName, char[] ca, int off, int len)
    throws UnsupportedEncodingException
{
    StringEncoder se = deref(encoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((se == null) || !(csn.equals(se.requestedCharsetName())
                          || csn.equals(se.charsetName()))) {
        se = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                se = new StringEncoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (se == null)
            throw new UnsupportedEncodingException (csn);
        set(encoder, se);
    }
    return se.encode(ca, off, len);
}
项目:BibliotecaPS    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            Charset oldCs = charsetsByAlias.putIfAbsent(alias, cs);
            if (oldCs != null) {
                // if the previous value was recently set by another thread we return it instead of value we found here
                cs = oldCs;
            }
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:jdk8u-jdk    文件:StringCoding.java   
static char[] decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                sd = new StringDecoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:jdk8u-jdk    文件:StringCoding.java   
static byte[] encode(String charsetName, char[] ca, int off, int len)
    throws UnsupportedEncodingException
{
    StringEncoder se = deref(encoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((se == null) || !(csn.equals(se.requestedCharsetName())
                          || csn.equals(se.charsetName()))) {
        se = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                se = new StringEncoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (se == null)
            throw new UnsupportedEncodingException (csn);
        set(encoder, se);
    }
    return se.encode(ca, off, len);
}
项目:openjdk-jdk10    文件:CodeSetConversion.java   
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
                        int alignmentForEncoding) {

    try {
        ctb = cache.getCharToByteConverter(codeset.getName());
        if (ctb == null) {
            Charset tmpCharset = Charset.forName(codeset.getName());
            ctb = tmpCharset.newEncoder();
            cache.setConverter(codeset.getName(), ctb);
        }
    } catch(IllegalCharsetNameException icne) {

        // This can only happen if one of our Entries has
        // an invalid name.
        throw wrapper.invalidCtbConverterName(icne,codeset.getName());
    } catch(UnsupportedCharsetException ucne) {

        // This can only happen if one of our Entries has
        // an unsupported name.
        throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
    }

    this.codeset = codeset;
    alignment = alignmentForEncoding;
}
项目:openjdk-jdk10    文件:CodeSetConversion.java   
/**
 * Utility method to find a CharsetDecoder in the
 * cache or create a new one if necessary.  Throws an
 * INTERNAL if the code set is unknown.
 */
protected CharsetDecoder getConverter(String javaCodeSetName) {

    CharsetDecoder result = null;
    try {
        result = cache.getByteToCharConverter(javaCodeSetName);

        if (result == null) {
            Charset tmpCharset = Charset.forName(javaCodeSetName);
            result = tmpCharset.newDecoder();
            cache.setConverter(javaCodeSetName, result);
        }

    } catch(IllegalCharsetNameException icne) {
        // This can only happen if one of our charset entries has
        // an illegal name.
        throw wrapper.invalidBtcConverterName( icne, javaCodeSetName ) ;
    }

    return result;
}
项目:openjdk-jdk10    文件:StringCoding.java   
static Result decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null) {
                if (cs == UTF_8) {
                    sd = new StringDecoderUTF8(cs, csn);
                } else if (cs == ISO_8859_1) {
                    sd = new StringDecoder8859_1(cs, csn);
                } else {
                    sd = new StringDecoder(cs, csn);
                }
            }
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:chipKIT-importer    文件:ProjectSetupPanel.java   
public EncodingModel(String originalEncoding) {
    Charset defEnc = null;
    for (Charset c : Charset.availableCharsets().values()) {
        if (c.name().equals(originalEncoding)) {
            defEnc = c;
        }
        addElement(c);
    }
    if (defEnc == null) {
        //Create artificial Charset to keep the original value
        //May happen when the project was set up on the platform
        //which supports more encodings
        try {
            defEnc = new UnknownCharset(originalEncoding);
            addElement(defEnc);
        } catch (IllegalCharsetNameException e) {
            //The source.encoding property is completely broken
            Logger.getLogger(this.getClass().getName()).log(Level.INFO, "IllegalCharsetName: {0}", originalEncoding);
        }
    }
    if (defEnc == null) {
        defEnc = Charset.defaultCharset();
    }
    setSelectedItem(defEnc);
}
项目:openjdk9    文件:CodeSetConversion.java   
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
                        int alignmentForEncoding) {

    try {
        ctb = cache.getCharToByteConverter(codeset.getName());
        if (ctb == null) {
            Charset tmpCharset = Charset.forName(codeset.getName());
            ctb = tmpCharset.newEncoder();
            cache.setConverter(codeset.getName(), ctb);
        }
    } catch(IllegalCharsetNameException icne) {

        // This can only happen if one of our Entries has
        // an invalid name.
        throw wrapper.invalidCtbConverterName(icne,codeset.getName());
    } catch(UnsupportedCharsetException ucne) {

        // This can only happen if one of our Entries has
        // an unsupported name.
        throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
    }

    this.codeset = codeset;
    alignment = alignmentForEncoding;
}
项目:openjdk9    文件:CodeSetConversion.java   
/**
 * Utility method to find a CharsetDecoder in the
 * cache or create a new one if necessary.  Throws an
 * INTERNAL if the code set is unknown.
 */
protected CharsetDecoder getConverter(String javaCodeSetName) {

    CharsetDecoder result = null;
    try {
        result = cache.getByteToCharConverter(javaCodeSetName);

        if (result == null) {
            Charset tmpCharset = Charset.forName(javaCodeSetName);
            result = tmpCharset.newDecoder();
            cache.setConverter(javaCodeSetName, result);
        }

    } catch(IllegalCharsetNameException icne) {
        // This can only happen if one of our charset entries has
        // an illegal name.
        throw wrapper.invalidBtcConverterName( icne, javaCodeSetName ) ;
    }

    return result;
}
项目:openjdk9    文件:StringCoding.java   
static Result decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null) {
                if (cs == UTF_8) {
                    sd = new StringDecoderUTF8(cs, csn);
                } else if (cs == ISO_8859_1) {
                    sd = new StringDecoder8859_1(cs, csn);
                } else {
                    sd = new StringDecoder(cs, csn);
                }
            }
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:Java8CN    文件:StringCoding.java   
static char[] decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                sd = new StringDecoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:Java8CN    文件:StringCoding.java   
static byte[] encode(String charsetName, char[] ca, int off, int len)
    throws UnsupportedEncodingException
{
    StringEncoder se = deref(encoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((se == null) || !(csn.equals(se.requestedCharsetName())
                          || csn.equals(se.charsetName()))) {
        se = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                se = new StringEncoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (se == null)
            throw new UnsupportedEncodingException (csn);
        set(encoder, se);
    }
    return se.encode(ca, off, len);
}
项目:DigitalMediaServer    文件:FileUtil.java   
/**
 * Detects charset/encoding for given file. Not 100% accurate for
 * non-Unicode files.
 *
 * @param file the file for which to detect charset/encoding.
 * @return The detected {@link Charset} or {@code null} if not detected.
 * @throws IOException If an IO error occurs during the operation.
 */
@Nullable
public static Charset getFileCharset(@Nullable File file) throws IOException {
    if (file == null) {
        return null;
    }
    CharsetMatch match = getFileCharsetMatch(file);
    try {
        if (Charset.isSupported(match.getName())) {
            LOGGER.debug("Detected charset \"{}\" in file \"{}\"", match.getName(), file.getAbsolutePath());
            return Charset.forName(match.getName());
        }
        LOGGER.debug(
            "Detected charset \"{}\" in file \"{}\", but cannot use it because it's not supported by the Java Virual Machine",
            match.getName(),
            file.getAbsolutePath()
        );
        return null;
    } catch (IllegalCharsetNameException e) {
        LOGGER.debug("Illegal charset \"{}\" deteceted in file \"{}\"", match.getName(), file.getAbsolutePath());
    }
    LOGGER.debug("Found no matching charset for file \"{}\"", file.getAbsolutePath());
    return null;
}
项目:DigitalMediaServer    文件:FileUtil.java   
/**
 * Detects charset/encoding for given file. Not 100% accurate for
 * non-Unicode files.
 *
 * @param file the file for which to detect charset/encoding.
 * @return The name of the detected charset or {@code null} if not detected.
 * @throws IOException If an IO error occurs during the operation.
 */
@Nullable
public static String getFileCharsetName(@Nullable File file) throws IOException {
    if (file == null) {
        return null;
    }
    CharsetMatch match = getFileCharsetMatch(file);
    try {
        if (Charset.isSupported(match.getName())) {
            LOGGER.debug("Detected charset \"{}\" in file \"{}\"", match.getName(), file.getAbsolutePath());
            return match.getName().toUpperCase(Locale.ROOT);
        }
        LOGGER.debug(
            "Detected charset \"{}\" in file \"{}\", but cannot use it because it's not supported by the Java Virual Machine",
            match.getName(),
            file.getAbsolutePath()
        );
        return null;
    } catch (IllegalCharsetNameException e) {
        LOGGER.debug("Illegal charset \"{}\" deteceted in file \"{}\"", match.getName(), file.getAbsolutePath());
    }
    LOGGER.debug("Found no matching charset for file \"{}\"", file.getAbsolutePath());
    return null;
}
项目:jdk8u_jdk    文件:StringCoding.java   
static char[] decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                sd = new StringDecoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:jdk8u_jdk    文件:StringCoding.java   
static byte[] encode(String charsetName, char[] ca, int off, int len)
    throws UnsupportedEncodingException
{
    StringEncoder se = deref(encoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((se == null) || !(csn.equals(se.requestedCharsetName())
                          || csn.equals(se.charsetName()))) {
        se = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                se = new StringEncoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (se == null)
            throw new UnsupportedEncodingException (csn);
        set(encoder, se);
    }
    return se.encode(ca, off, len);
}
项目:lookaside_java-1.8.0-openjdk    文件:CodeSetConversion.java   
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
                        int alignmentForEncoding) {

    try {
        ctb = cache.getCharToByteConverter(codeset.getName());
        if (ctb == null) {
            Charset tmpCharset = Charset.forName(codeset.getName());
            ctb = tmpCharset.newEncoder();
            cache.setConverter(codeset.getName(), ctb);
        }
    } catch(IllegalCharsetNameException icne) {

        // This can only happen if one of our Entries has
        // an invalid name.
        throw wrapper.invalidCtbConverterName(icne,codeset.getName());
    } catch(UnsupportedCharsetException ucne) {

        // This can only happen if one of our Entries has
        // an unsupported name.
        throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
    }

    this.codeset = codeset;
    alignment = alignmentForEncoding;
}
项目:lookaside_java-1.8.0-openjdk    文件:CodeSetConversion.java   
/**
 * Utility method to find a CharsetDecoder in the
 * cache or create a new one if necessary.  Throws an
 * INTERNAL if the code set is unknown.
 */
protected CharsetDecoder getConverter(String javaCodeSetName) {

    CharsetDecoder result = null;
    try {
        result = cache.getByteToCharConverter(javaCodeSetName);

        if (result == null) {
            Charset tmpCharset = Charset.forName(javaCodeSetName);
            result = tmpCharset.newDecoder();
            cache.setConverter(javaCodeSetName, result);
        }

    } catch(IllegalCharsetNameException icne) {
        // This can only happen if one of our charset entries has
        // an illegal name.
        throw wrapper.invalidBtcConverterName( icne, javaCodeSetName ) ;
    }

    return result;
}
项目:lookaside_java-1.8.0-openjdk    文件:StringCoding.java   
static char[] decode(String charsetName, byte[] ba, int off, int len)
    throws UnsupportedEncodingException
{
    StringDecoder sd = deref(decoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
                          || csn.equals(sd.charsetName()))) {
        sd = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                sd = new StringDecoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (sd == null)
            throw new UnsupportedEncodingException(csn);
        set(decoder, sd);
    }
    return sd.decode(ba, off, len);
}
项目:lookaside_java-1.8.0-openjdk    文件:StringCoding.java   
static byte[] encode(String charsetName, char[] ca, int off, int len)
    throws UnsupportedEncodingException
{
    StringEncoder se = deref(encoder);
    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
    if ((se == null) || !(csn.equals(se.requestedCharsetName())
                          || csn.equals(se.charsetName()))) {
        se = null;
        try {
            Charset cs = lookupCharset(csn);
            if (cs != null)
                se = new StringEncoder(cs, csn);
        } catch (IllegalCharsetNameException x) {}
        if (se == null)
            throw new UnsupportedEncodingException (csn);
        set(encoder, se);
    }
    return se.encode(ca, off, len);
}
项目:jdk8u_corba    文件:CodeSetConversion.java   
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
                        int alignmentForEncoding) {

    try {
        ctb = cache.getCharToByteConverter(codeset.getName());
        if (ctb == null) {
            Charset tmpCharset = Charset.forName(codeset.getName());
            ctb = tmpCharset.newEncoder();
            cache.setConverter(codeset.getName(), ctb);
        }
    } catch(IllegalCharsetNameException icne) {

        // This can only happen if one of our Entries has
        // an invalid name.
        throw wrapper.invalidCtbConverterName(icne,codeset.getName());
    } catch(UnsupportedCharsetException ucne) {

        // This can only happen if one of our Entries has
        // an unsupported name.
        throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
    }

    this.codeset = codeset;
    alignment = alignmentForEncoding;
}
项目:jdk8u_corba    文件:CodeSetConversion.java   
/**
 * Utility method to find a CharsetDecoder in the
 * cache or create a new one if necessary.  Throws an
 * INTERNAL if the code set is unknown.
 */
protected CharsetDecoder getConverter(String javaCodeSetName) {

    CharsetDecoder result = null;
    try {
        result = cache.getByteToCharConverter(javaCodeSetName);

        if (result == null) {
            Charset tmpCharset = Charset.forName(javaCodeSetName);
            result = tmpCharset.newDecoder();
            cache.setConverter(javaCodeSetName, result);
        }

    } catch(IllegalCharsetNameException icne) {
        // This can only happen if one of our charset entries has
        // an illegal name.
        throw wrapper.invalidBtcConverterName( icne, javaCodeSetName ) ;
    }

    return result;
}
项目:planb-android    文件:DemoAppUtil.java   
public static void throwRandomRuntimeException() {
    String random = "planb:" + UUID.randomUUID().toString();
    RuntimeException[] exceptions = new RuntimeException[]{
            new IllegalStateException("This is a test exception because the sate " + random),
            new IllegalArgumentException("Wrong argument test exception" + random),
            new RuntimeException("This is a test exception " + random),
            new IllegalSelectorException(),
            new IndexOutOfBoundsException("A test index exception " + random),
            new ClassCastException("A test class cast exception " + random),
            new NoSuchElementException("A test no such element exception " + random),
            new MalformedParameterizedTypeException(),
            new BufferOverflowException(),
            new EmptyStackException(),
            new NullPointerException("This is not a real nullpointer " + random),
            new SecurityException("This is not a real security exception " + random),
            new ArithmeticException("This is not a real arithmetic exception " + random),
            new IllegalThreadStateException("This is a test exception with threads " + random),
            new IllegalCharsetNameException("Charset is wrong test exception " + random),
            new IllegalMonitorStateException("This is a test exception with illegal monitor " + random)};

    throw exceptions[new Random().nextInt(exceptions.length)];
}
项目:jtransc    文件:PrintStream.java   
/**
 * Constructs a new {@code PrintStream} with {@code out} as its target
 * stream and using the character encoding {@code charsetName} while writing. The
 * parameter {@code autoFlush} determines if the print stream automatically
 * flushes its contents to the target stream when a newline is encountered.
 *
 * @param out
 *            the target output stream.
 * @param autoFlush
 *            indicates whether or not to flush contents upon encountering a
 *            newline sequence.
 * @param charsetName
 *            the non-null string describing the desired character encoding.
 * @throws NullPointerException
 *             if {@code out} or {@code charsetName} are {@code null}.
 * @throws UnsupportedEncodingException
 *             if the encoding specified by {@code charsetName} is not supported.
 */
public PrintStream(OutputStream out, boolean autoFlush, String charsetName)
        throws UnsupportedEncodingException {
    super(out);
    if (out == null) {
        throw new NullPointerException("out == null");
    } else if (charsetName == null) {
        throw new NullPointerException("charsetName == null");
    }
    this.autoFlush = autoFlush;
    try {
        if (!Charset.isSupported(charsetName)) {
            throw new UnsupportedEncodingException(charsetName);
        }
    } catch (IllegalCharsetNameException e) {
        throw new UnsupportedEncodingException(charsetName);
    }
    encoding = charsetName;
}
项目:Geometry-wars    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            Charset oldCs = charsetsByAlias.putIfAbsent(alias, cs);
            if (oldCs != null) {
                // if the previous value was recently set by another thread we return it instead of value we found here
                cs = oldCs;
            }
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:TPKB    文件:StringUtils.java   
static Charset findCharset(String alias) throws UnsupportedEncodingException {
    try {
        Charset cs = charsetsByAlias.get(alias);

        if (cs == null) {
            cs = Charset.forName(alias);
            charsetsByAlias.putIfAbsent(alias, cs);
        }

        return cs;

        // We re-throw these runtimes for compatibility with java.io
    } catch (UnsupportedCharsetException uce) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalCharsetNameException icne) {
        throw new UnsupportedEncodingException(alias);
    } catch (IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(alias);
    }
}
项目:intellij-ce-playground    文件:BinaryContent.java   
@Override
@Nullable
public Document getDocument() {
  if (myDocument == null) {
    if (isBinary()) return null;

    String text = null;
    try {
      Charset charset = ObjectUtils.notNull(myCharset, EncodingProjectManager.getInstance(myProject).getDefaultCharset());
      text = CharsetToolkit.bytesToString(myBytes, charset);
    }
    catch (IllegalCharsetNameException ignored) { }

    //  Still NULL? only if not supported or an exception was thrown.
    //  Decode a string using the truly default encoding.
    if (text == null) text = new String(myBytes);
    text = LineTokenizer.correctLineSeparators(text);

    myDocument = EditorFactory.getInstance().createDocument(text);
    myDocument.setReadOnly(true);
  }

  return myDocument;
}
项目:OSBuild    文件:ReaderActivity.java   
public boolean addCharset(String charset)
{
    boolean result = false;
    if (TextUtils.isEmpty(charset))
    {
        return result;
    }

    try
    {
        if (Charset.isSupported(charset))
        {
            this.charsets[2] = charset;
            this.id_charset = 2;
            this.charset = charset;

            result = true;
        }
    }
    catch (IllegalCharsetNameException e)
    {
        e.printStackTrace();
    }

    return result;
}