本文整理汇总了Java中java.io.CharConversionException类的典型用法代码示例。如果您正苦于以下问题:Java CharConversionException类的具体用法?Java CharConversionException怎么用?Java CharConversionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CharConversionException类属于java.io包,在下文中一共展示了CharConversionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDetails
import java.io.CharConversionException; //导入依赖的package包/类
private JComponent createDetails(String text, ActionListener action) {
try {
text = (action == null ? "<html>" : "<html><a href=\"_blank\">") + XMLUtil.toElementContent(text); //NOI18N
} catch (CharConversionException ex) {
throw new IllegalArgumentException(ex);
}
if (null == action) {
return new JLabel(text);
}
JButton btn = new JButton(text);
btn.setFocusable(false);
btn.setBorder(BorderFactory.createEmptyBorder());
btn.setBorderPainted(false);
btn.setFocusPainted(false);
btn.setOpaque(false);
btn.setContentAreaFilled(false);
btn.addActionListener(action);
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
Color c = UIManager.getColor("nb.html.link.foreground"); //NOI18N
if (c != null) {
btn.setForeground(c);
}
return btn;
}
示例2: testSimpleEOFs
import java.io.CharConversionException; //导入依赖的package包/类
public void testSimpleEOFs() throws Exception
{
// 2 spaces
byte[] data = { 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x20
};
for (int len = 5; len <= 7; ++len) {
JsonParser parser = FACTORY.createParser(ObjectReadContext.empty(), data, 0, len);
try {
parser.nextToken();
fail("Should not pass");
} catch (CharConversionException e) {
verifyException(e, "Unexpected EOF");
verifyException(e, "of a 4-byte UTF-32 char");
}
parser.close();
}
}
示例3: testSimpleInvalidUTF32
import java.io.CharConversionException; //导入依赖的package包/类
public void testSimpleInvalidUTF32() throws Exception
{
// 2 characters, space, then something beyond valid Unicode set
byte[] data = {
0x00,
0x00,
0x00,
0x20,
(byte) 0xFE,
(byte) 0xFF,
0x00,
0x01
};
JsonParser parser = FACTORY.createParser(ObjectReadContext.empty(), data);
try {
parser.nextToken();
fail("Should not pass");
} catch (CharConversionException e) {
verifyException(e, "Invalid UTF-32 character 0xfefe0001");
}
parser.close();
}
示例4: appendMarkedTextPrefix
import java.io.CharConversionException; //导入依赖的package包/类
/**
* Append part of line that is before matched text.
*
* @param text Buffer to append to.
* @param prefixStart Line index of the first character to be displayed.
* @param matchStart Line index of the matched text.
* @param trim Skip leading whitespace characters.
*/
private void appendMarkedTextPrefix(StringBuilder text, int prefixStart,
int matchStart, boolean trim) throws CharConversionException {
int first = 0; // index of first non-whitespace character
if (trim) {
CharSequence lineText = txtDetail.getLineText();
while (first < matchStart && lineText.charAt(first) <= '\u0020') {
first++;
}
}
if (prefixStart > 0 && first < prefixStart) {
text.append(ELLIPSIS);
}
text.append(escape(txtDetail.getLineTextPart(
Math.max(prefixStart, first), matchStart)));
}
示例5: appendMarkedTextMatch
import java.io.CharConversionException; //导入依赖的package包/类
/**
* Append part of line that contains the matched text.
*
* @param text Buffer to append to.
* @param matchStart Line index of the first character of the matched
* text.
* @param matchEnd Line index after the last character of the matched
* text.
* @param lineLength Lenght of the line.
* @param detailLength Lengt of matched part.
*/
private void appendMarkedTextMatch(StringBuilder text, int matchStart,
int matchEnd, int lineLength, int matchedLength)
throws CharConversionException {
text.append("<b>"); // NOI18N
if (matchedLength > DETAIL_DISPLAY_LENGTH) {
int off = (DETAIL_DISPLAY_LENGTH - ELLIPSIS.length()) / 2;
text.append(escape(txtDetail.getLineTextPart(
matchStart, matchStart + off)));
text.append("</b>");
text.append(ELLIPSIS);
text.append("<b>");
text.append(escape(txtDetail.getLineTextPart(
matchEnd - off, matchEnd)));
} else {
text.append(escape(
txtDetail.getLineTextPart(matchStart, matchEnd)));
}
int markEnd = matchStart + txtDetail.getMarkLength();
text.append("</b>"); // NOI18N
if (markEnd > lineLength) { // mark up to the text end?
text.append(ELLIPSIS);
}
}
示例6: getListCellRendererComponent
import java.io.CharConversionException; //导入依赖的package包/类
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
String text;
if (value == UIUtil.WAIT_VALUE) {
text = UIUtil.WAIT_VALUE;
} else if (value == INVALID_PLATFORM) {
text = INVALID_PLATFORM;
renderer.setHtml(true);
} else {
ModuleDependency md = (ModuleDependency) value;
// XXX the following is wrong; spec requires additional logic:
boolean bold = boldfaceApiModules && md.getModuleEntry().getPublicPackages().length > 0;
boolean deprecated = md.getModuleEntry().isDeprecated();
renderer.setHtml(bold || deprecated);
String locName = md.getModuleEntry().getLocalizedName();
text = locName;
if (bold || deprecated) {
try {
text = "<html>" + (bold ? "<b>" : "") + (deprecated ? "<s>" : "") + XMLUtil.toElementContent(locName); // NOI18N
} catch (CharConversionException e) {
// forget it
}
}
}
return renderer.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}
示例7: getHtmlDisplayName
import java.io.CharConversionException; //导入依赖的package包/类
public @Override String getHtmlDisplayName() {
String htmlName = getOriginal().getHtmlDisplayName();
if (htmlName == null) {
try {
htmlName = XMLUtil.toElementContent(getOriginal().getDisplayName());
} catch (CharConversionException ex) {
// ignore
}
}
if (htmlName == null) {
return null;
}
if (files != null && files.iterator().hasNext()) {
try {
String annotatedMagic = files.iterator().next().getFileSystem().
getDecorator().annotateNameHtml(MAGIC, files);
if (annotatedMagic != null) {
htmlName = annotatedMagic.replace(MAGIC, htmlName);
}
} catch (FileStateInvalidException e) {
LOG.log(Level.INFO, null, e);
}
}
return isMainAsync()? "<b>" + htmlName + "</b>" : htmlName;
}
示例8: getListCellRendererComponent
import java.io.CharConversionException; //导入依赖的package包/类
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
AnalyzerFactory a = (AnalyzerFactory) value;
String text = SPIAccessor.ACCESSOR.getAnalyzerDisplayName(a);
boolean isErroneous;
synchronized (errors) {
isErroneous = errors.containsKey(a);
}
if (isErroneous) {
try {
text = "<html><font color='ref'>" + XMLUtil.toElementContent(text);
} catch (CharConversionException ex) {
LOG.log(Level.FINE, null, ex);
}
}
return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
}
示例9: checkCoord
import java.io.CharConversionException; //导入依赖的package包/类
@Messages("ERR_Coord_breaks_pom=Error: Group Id or Artifact Id would invalidate Maven POM xml file.")
private boolean checkCoord(JTextField field) {
String coord = field.getText();
boolean result = false;
try {
String escaped = XMLUtil.toAttributeValue(coord);
result = escaped.length() == coord.length() && coord.indexOf(">") == -1
&& coord.indexOf(" ") == -1;
} catch (CharConversionException ex) {
// ignore this one
}
if (result) {
result = !containsMultiByte(coord);
} else {
category.setErrorMessage(ERR_Coord_breaks_pom());
}
if (result) {
category.setErrorMessage(null);
}
return result;
}
示例10: getHtmlDisplayName
import java.io.CharConversionException; //导入依赖的package包/类
@Override
public String getHtmlDisplayName () {
final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
if (platHolder == null) {
return null;
}
final JavaPlatform jp = platHolder.second();
if (jp == null || !jp.isValid()) {
String displayName = this.getDisplayName();
try {
displayName = XMLUtil.toElementContent(displayName);
} catch (CharConversionException ex) {
// OK, no annotation in this case
return null;
}
return "<font color=\"#A40000\">" + displayName + "</font>"; //NOI18N
} else {
return null;
}
}
示例11: escape
import java.io.CharConversionException; //导入依赖的package包/类
static String escape(String s) {
if (s != null) {
//unescape unicode sequences first (would be better if Pretty would not print them, but that might be more difficult):
Matcher matcher = UNICODE_SEQUENCE.matcher(s);
if (matcher.find()) {
StringBuilder result = new StringBuilder();
int lastReplaceEnd = 0;
do {
result.append(s.substring(lastReplaceEnd, matcher.start()));
int ch = Integer.parseInt(matcher.group(1), 16);
result.append((char) ch);
lastReplaceEnd = matcher.end();
} while (matcher.find());
result.append(s.substring(lastReplaceEnd));
s = result.toString();
}
try {
return XMLUtil.toAttributeValue(s);
} catch (CharConversionException ex) {
}
}
return null;
}
示例12: perform
import java.io.CharConversionException; //导入依赖的package包/类
@Override
public void perform() {
if (!terminal().isVisibleInContainer()) {
return ;
}
String newTitle = terminal().getTitle();
if (terminal().isConnected() && newTitle != null) {
String escaped;
try {
escaped = XMLUtil.toAttributeValue(newTitle);
} catch (CharConversionException ex) {
escaped = newTitle;
}
newTitle = "<html><b>" + escaped + "</b></html>"; // NOI18N
}
container().setTitle(terminal(), newTitle);
}
示例13: messageHtmlName
import java.io.CharConversionException; //导入依赖的package包/类
@Override
protected String messageHtmlName() {
if (! obj.isValid()) {
return null;
}
String name = obj.getNodeDelegate().getHtmlDisplayName();
if (name == null) {
try {
name = XMLUtil.toElementContent(obj.getNodeDelegate().getDisplayName());
} catch (CharConversionException ex) {
return null;
}
}
return annotateName(name, true, isModified(), !obj.getPrimaryFile().canWrite());
}
示例14: target2String
import java.io.CharConversionException; //导入依赖的package包/类
public static String target2String(TypeElement target) {
final Name qualifiedName = target.getQualifiedName(); //#130759
if (qualifiedName == null) {
Logger.getLogger(Utilities.class.getName()).warning("Target qualified name could not be resolved."); //NOI18N
return ""; //NOI18N
} else {
String qnString = qualifiedName.toString();
if (qnString.length() == 0) {
//probably an anonymous class
qnString = target.asType().toString();
}
try {
qnString = XMLUtil.toElementContent(qnString);
} catch (CharConversionException ex) {
Logger.getLogger(Utilities.class.getName()).log(Level.FINE, null, ex);
}
return qnString;
}
}
示例15: writeProperties
import java.io.CharConversionException; //导入依赖的package包/类
private static void writeProperties(
@NonNull final Map<String,String> props,
@NonNull final Element element,
@NonNull final Document doc) throws IOException {
final Collection<String> sortedProps = new TreeSet<>(props.keySet());
for (String name : sortedProps) {
final String val = props.get(name);
try {
XMLUtil.toAttributeValue(name);
XMLUtil.toAttributeValue(val);
final Element propElement = doc.createElement(ELM_PROPERTY);
propElement.setAttribute(ATTR_NAME,name);
propElement.setAttribute(ATTR_VALUE,val);
element.appendChild(propElement);
} catch (CharConversionException e) {
LOG.log(
Level.WARNING,
"Cannot store property: {0} value: {1}", //NOI18N
new Object[] {
name,
val
});
}
}
}