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

下面列出了怎么用java.nio.charset.IllegalCharsetNameException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk1.8-source-analysis   文件: 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);
}
 
源代码2 项目: astor   文件: DataUtil.java
/**
 * Parse out a charset from a content type header. If the charset is not supported, returns null (so the default
 * will kick in.)
 * @param contentType e.g. "text/html; charset=EUC-JP"
 * @return "EUC-JP", or null if not found. Charset is trimmed and uppercased.
 */
static String getCharsetFromContentType(String contentType) {
    if (contentType == null) return null;
    Matcher m = charsetPattern.matcher(contentType);
    if (m.find()) {
        String charset = m.group(1).trim();
        charset = charset.replace("charset=", "");
        if (charset.length() == 0) return null;
        try {
            if (Charset.isSupported(charset)) return charset;
            charset = charset.toUpperCase(Locale.ENGLISH);
            if (Charset.isSupported(charset)) return charset;
        } catch (IllegalCharsetNameException e) {
            // if our advanced charset matching fails.... we just take the default
            return null;
        }
    }
    return null;
}
 
/**
 * 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;
}
 
源代码4 项目: openjdk-8   文件: 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;
}
 
源代码5 项目: consulo   文件: BinaryContent.java
@Override
@SuppressWarnings({"EmptyCatchBlock"})
@Nullable
public Document getDocument() {
  if (myDocument == null) {
    if (isBinary()) return null;

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

    //  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;
}
 
源代码6 项目: saros   文件: FileActivityConsumer.java
private void handleFileActivity(FileActivity activity)
    throws CoreException, IOException, IllegalCharsetNameException, UnsupportedCharsetException {

  if (activity.isRecovery()) {
    handleFileRecovery(activity);
    return;
  }

  // TODO check if we should open / close existing editors here too
  switch (activity.getType()) {
    case CREATED:
      handleFileCreation(activity);
      break;
    case REMOVED:
      handleFileDeletion(activity);
      break;
    case MOVED:
      handleFileMove(activity);
      break;
  }
}
 
源代码7 项目: TencentKona-8   文件: 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;
}
 
源代码8 项目: TencentKona-8   文件: 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;
}
 
源代码9 项目: dble   文件: Security.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);
    }
}
 
源代码10 项目: Zebra   文件: 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);
	}
}
 
源代码11 项目: jdk8u60   文件: 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;
}
 
源代码12 项目: hottub   文件: 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;
}
 
源代码13 项目: maven-jaxb2-plugin   文件: OptionsFactory.java
private String createEncoding(String encoding)
		throws MojoExecutionException {
	if (encoding == null) {
		return null;
	}
	try {
		if (!Charset.isSupported(encoding)) {
			throw new MojoExecutionException(MessageFormat.format(
					"Unsupported encoding [{0}].", encoding));
		}
		return encoding;
	} catch (IllegalCharsetNameException icne) {
		throw new MojoExecutionException(MessageFormat.format(
				"Unsupported encoding [{0}].", encoding));
	}

}
 
源代码14 项目: netbeans   文件: TplDataObject.java
private CoderResult handleHead(CharBuffer in, ByteBuffer out) {
    String encoding = null;
    try {
        encoding = getEncoding();
    } catch (IOException ioe) {
        Exceptions.printStackTrace(ioe);
    }
    if (encoding == null) {
        buffer = null;
        throwUnknownEncoding();
        return null;
    } else {
        Charset c;
        try {
            c = cache(Charset.forName(encoding));
        } catch (UnsupportedCharsetException | IllegalCharsetNameException e) {
            buffer = null;
            throwUnknownEncoding();
            return null;
        }
        encoder = c.newEncoder();
        return flushHead(in, out);
    }
}
 
源代码15 项目: r-course   文件: 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);
    }
}
 
源代码16 项目: JDKSourceCode1.8   文件: 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;
}
 
源代码17 项目: hottub   文件: 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);
}
 
源代码18 项目: jdk-1.7-annotated   文件: 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);
}
 
源代码19 项目: 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);
}
 
源代码20 项目: openjdk-jdk8u   文件: 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;
}
 
源代码21 项目: openjdk-8-source   文件: 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);
}
 
源代码22 项目: openjdk-jdk8u   文件: 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);
}
 
源代码23 项目: openjdk-8   文件: 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);
}
 
源代码24 项目: jsflight   文件: JMeterProxy.java
/**
 * Add the page encoding of the sample result to the Map with page encodings
 *
 * @param result the sample result to check
 * @return the page encoding found for the sample result, or null
 */
private String addPageEncoding(SampleResult result)
{
    String pageEncoding = null;
    try
    {
        pageEncoding = ConversionUtils.getEncodingFromContentType(result.getContentType());
    }
    catch (IllegalCharsetNameException ex)
    {
        LOG.warn("Unsupported charset detected in contentType:'" + result.getContentType()
                + "', will continue processing with default charset", ex);
    }
    if (pageEncoding != null)
    {
        String urlWithoutQuery = getUrlWithoutQuery(result.getURL());
        pageEncodings.put(urlWithoutQuery, pageEncoding);
    }
    return pageEncoding;
}
 
源代码25 项目: jaybird   文件: DefaultEncodingDefinition.java
private void initCharset() {
    try {
        charset = Charset.forName(charsetName);
    } catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
        // Prevent further attempts
        encoding = null;
        String message = String.format("charsetName=\"%s\" specified for Firebird encoding \"%s\" is an illegal or "
                        + "unsupported character set name, handling as information-only",
                charsetName, firebirdEncodingName);
        logger.warn(message + ": " + e + "; see debug level for stacktrace");
        logger.debug(message, e);
    }
}
 
源代码26 项目: jdk-1.7-annotated   文件: PrintWriter.java
/**
 * Returns a charset object for the given charset name.
 * @throws NullPointerException          is csn is null
 * @throws UnsupportedEncodingException  if the charset is not supported
 */
private static Charset toCharset(String csn)
    throws UnsupportedEncodingException
{
    Objects.requireNonNull(csn, "charsetName");
    try {
        return Charset.forName(csn);
    } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
        // UnsupportedEncodingException should be thrown
        throw new UnsupportedEncodingException(csn);
    }
}
 
源代码27 项目: Java8CN   文件: PrintWriter.java
/**
 * Returns a charset object for the given charset name.
 * @throws NullPointerException          is csn is null
 * @throws UnsupportedEncodingException  if the charset is not supported
 */
private static Charset toCharset(String csn)
    throws UnsupportedEncodingException
{
    Objects.requireNonNull(csn, "charsetName");
    try {
        return Charset.forName(csn);
    } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
        // UnsupportedEncodingException should be thrown
        throw new UnsupportedEncodingException(csn);
    }
}
 
源代码28 项目: jdk1.8-source-analysis   文件: PrintStream.java
/**
 * Returns a charset object for the given charset name.
 * @throws NullPointerException          is csn is null
 * @throws UnsupportedEncodingException  if the charset is not supported
 */
private static Charset toCharset(String csn)
    throws UnsupportedEncodingException
{
    requireNonNull(csn, "charsetName");
    try {
        return Charset.forName(csn);
    } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
        // UnsupportedEncodingException should be thrown
        throw new UnsupportedEncodingException(csn);
    }
}
 
源代码29 项目: jdk1.8-source-analysis   文件: Encodings.java
/**
 * Returns the EncodingInfo object for the specified
 * encoding.
 * <p>
 * This is not a public API.
 *
 * @param encoding The encoding
 * @return The object that is used to determine if
 * characters are in the given encoding.
 * @xsl.usage internal
 */
static EncodingInfo getEncodingInfo(String encoding)
{
    EncodingInfo ei;

    String normalizedEncoding = toUpperCaseFast(encoding);
    ei = _encodingInfos.findEncoding(normalizedEncoding);
    if (ei == null) {
        // We shouldn't have to do this, but just in case.
        try {
            // This may happen if the caller tries to use
            // an encoding that wasn't registered in the
            // (java name)->(preferred mime name) mapping file.
            // In that case we attempt to load the charset for the
            // given encoding, and if that succeeds - we create a new
            // EncodingInfo instance - assuming the canonical name
            // of the charset can be used as the mime name.
            final Charset c = Charset.forName(encoding);
            final String name = c.name();
            ei = new EncodingInfo(name, name);
            _encodingInfos.putEncoding(normalizedEncoding, ei);
        } catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
            ei = new EncodingInfo(null,null);
        }
    }

    return ei;
}
 
源代码30 项目: nifi   文件: TestRecordPath.java
@Test(expected = IllegalCharsetNameException.class)
public void testToStringBadCharset() {
    final List<RecordField> fields = new ArrayList<>();
    fields.add(new RecordField("id", RecordFieldType.INT.getDataType()));
    fields.add(new RecordField("bytes", RecordFieldType.CHOICE.getChoiceDataType(RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.BYTE.getDataType()))));

    final RecordSchema schema = new SimpleRecordSchema(fields);

    final Map<String, Object> values = new HashMap<>();
    values.put("id", 48);
    values.put("bytes", "Hello World!".getBytes(StandardCharsets.UTF_16));
    final Record record = new MapRecord(schema, values);

    RecordPath.compile("toString(/bytes, \"NOT A REAL CHARSET\")").evaluate(record).getSelectedFields().findFirst().get().getValue();
}