本文整理汇总了Java中java.nio.charset.IllegalCharsetNameException类的典型用法代码示例。如果您正苦于以下问题:Java IllegalCharsetNameException类的具体用法?Java IllegalCharsetNameException怎么用?Java IllegalCharsetNameException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IllegalCharsetNameException类属于java.nio.charset包,在下文中一共展示了IllegalCharsetNameException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: charsetForName
import java.nio.charset.IllegalCharsetNameException; //导入依赖的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);
}
示例2: charsetForName
import java.nio.charset.IllegalCharsetNameException; //导入依赖的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));
}
示例3: findCharset
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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);
}
}
示例4: findCharset
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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);
}
}
示例5: JavaCTBConverter
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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;
}
示例6: getConverter
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
/**
* 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;
}
示例7: decode
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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);
}
示例8: encode
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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);
}
示例9: decode
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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);
}
示例10: EncodingModel
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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);
}
示例11: getFileCharset
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
/**
* 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;
}
示例12: getFileCharsetName
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
/**
* 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;
}
示例13: throwRandomRuntimeException
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
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)];
}
示例14: PrintStream
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
/**
* 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;
}
示例15: getDocument
import java.nio.charset.IllegalCharsetNameException; //导入依赖的package包/类
@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;
}