I want to use the infinity symbol (8 lying sideways) in java.
furthermore i want to use it as a String component.
i did not find a working charcode/ascii code for this (is there any?).
i tried:
String s=Character.toString(236);
String s=Character.toString('236');
am i missing something?
i got this now:
System.out.println(Character.toString('\u221E'));
but the output is ?
i am using java 1.7 jdk and eclipse. why is the infinity sign not showing up?
You need the Unicode infinity sign, U+221E. 236 is a Windows typing convention, that won't help you at all. '\u221e' is the character constant.
Now, I can't promise that this will result in any ∞ characters on your screen. That depends on what sort of computer you have, what font you are using, and what you set in -Dfile.encoding. Also see this question.
I know this is very late reply but the below information will definitely help someone.
In Eclipse by default Text File encoding for console is Cp1252, then
How to support UTF-8 encoding in Eclipse
and I will encourage to handle the infinity symbol in String like below source:
String infinitySymbol = null;
try {
infinitySymbol = new String(String.valueOf(Character.toString('\u221E')).getBytes("UTF-8"), "UTF-8");
} catch (UnsupportedEncodingException ex) {
infinitySymbol = "?";
//ex.printStackTrace(); //print the unsupported encoding exception.
} finally {
System.out.print("Symbol of infinity is : " + infinitySymbol);
}
Related
probably you may give me some hints what can I do/see in my case:)
There is an Oracle code that converts given hexadecimal input in AMERICAN_AMERICA.CL8ISO8859P5 to ASCII: utl_raw.cast_to_varchar2(utl_raw.convert(hextoraw('31383831303891353080853737303338385A5A'), 'AMERICAN_AMERICA.CL8ISO8859P5', 'AMERICAN_AMERICA.RU8PC866'))
Example input: 31383831303891353080853737303338385A5A, example output: 188108С50АЕ770388ZZ
My pain is to solve how can I do it in Java:) Prerequisite: I have no connection to the database and can't execute prepared SQL statement in order to call this function in Oracle package...
I am able to parsing everything except specific bytes (91 -> 'C1', 8085 -> 'B0B5', 5A -> 'Z') with the following code:
new String(DatatypeConverter.parseHexBinary("31383831303891353080853737303338385A5A"))
I've also tried all standards encodings in String constructor with encoding but there were no positive results:(
Do you know if there are encodings in Java that are identical to AMERICAN_AMERICA.CL8ISO8859P5? Or do you know some libraries or Java functions that are able to make this conversion (AMERICAN_AMERICA.CL8ISO8859P5 to ASCII) ?
Many thanks to you in advance!
AMERICAN_AMERICA.RU8PC866 Oracle encoding is IBM-866 encoding in Java (hint from #kfinity). My issue solved by using
new String(DatatypeConverter.parseHexBinary(input), "IBM-866")
CP866 worked as well.
The regular expression is
String regex = "^[\\p{IsHangul}\\p{IsDigit}]+";
And whenever i do
text.matches(regex);
It works fine in my system but not in some of the system.
I am not able to track the issue.
Thank you in advance.
Exception:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown character property name {Hangul} near index 13
^[\p{IsHangul}\p{IsDigit}]+
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.charPropertyNodeFor(Pattern.java:2437)
at java.util.regex.Pattern.family(Pattern.java:2412)
at java.util.regex.Pattern.range(Pattern.java:2335)
at java.util.regex.Pattern.clazz(Pattern.java:2268)
at java.util.regex.Pattern.sequence(Pattern.java:1818)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.util.regex.Pattern.matches(Pattern.java:928)
at java.lang.String.matches(String.java:2090)
at com.mycompany.helper.ApplicationHelper.main(ApplicationHelper.java:200)
According to Using Regular Expressions in Java:
Java 5 fixes some bugs and adds support for Unicode blocks. ...
Make sure you're using Java 5+ in the server.
It seems that Java version you are using is not able to recognise Hangul as correct script character so you can try to create your own character class which will cover same range as Hongul from newer versions of Java.
From what I see in code in source code of Character.UnicodeScript on Java 8 Hangul refers to Unicode ranges
1100..11FF
302E..302F
3131..318F
3200..321F
3260..327E
A960..A97F
AC00..D7FB
FFA0..FFDF
so maybe try with such pattern
Pattern.compile("^["
+ "\u1100-\u11FF"
+ "\u302E-\u302F"
+ "\u3131-\u318F"
+ "\u3200-\u321F"
+ "\u3260-\u327E"
+ "\uA960-\uA97F"
+ "\uAC00-\uD7FB"
+ "\uFFA0-\uFFDF"
+ "\\p{IsDigit}]+");
i have problem when initialize report in program at startup.
Sometime ago, it works correctly. But when i unistall JDK 1.7 update 17 to JDK 1.7 update 21, and fresh install Netbeans , the Exception exist :(
This is the error message :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:609)
at sun.font.ExtendedTextSourceLabel.getCharinfo(ExtendedTextSourceLabel.java:509)
at sun.font.ExtendedTextSourceLabel.getLineBreakIndex(ExtendedTextSourceLabel.java:455)
at java.awt.font.TextMeasurer.calcLineBreak(TextMeasurer.java:325)
at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:561)
at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:358)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLineBreakIndex(SimpleTextLineWrapper.java:561)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLine(SimpleTextLineWrapper.java:535)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.nextLine(SimpleTextLineWrapper.java:517)
at net.sf.jasperreports.engine.fill.TextMeasurer.renderNextLine(TextMeasurer.java:649)
at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:454)
at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:395)
at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:541)
at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:641)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:331)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:379)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:353)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:458)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
at com.ikbiz.gastroscope.controller.ReportController.initReport(ReportController.java:180)
at com.ikbiz.gastroscope.controller.ReportController.<init>(ReportController.java:111)
at com.ikbiz.gastroscope.view.PanelScope.<init>(PanelScope.java:32)
at com.ikbiz.gastroscope.view.PanelEntry.initComponents(PanelEntry.java:199)
at com.ikbiz.gastroscope.view.PanelEntry.<init>(PanelEntry.java:86)
at com.ikbiz.gastroscope.view.Application.initComponents(Application.java:203)
at com.ikbiz.gastroscope.view.Application.<init>(Application.java:35)
at com.ikbiz.gastroscope.view.Application.getInstance(Application.java:43)
at com.ikbiz.gastroscope.view.Application.main(Application.java:79)
Java Result: 1
And this is my code to initialize report.
public void initReport() {
try {
param.put("noMr", "0000");
param.put("visitCode", "V-199208300000");
param.put("templateLoco", iReportDir);
param.put("tools", "Tools");
param.put("medicine", "Medicine");
param.put("result", "Data hasil disini");
param.put("conclusion", "Data kesimpulan disini");
param.put("suggestion", "Suggestion");
param.put("SUBREPORT_DIR",iReportDir);
String imageLoco = iReportDir +"image-sample.jpg";
for (int i = 0; i < 20; i++) {
FileInputStream image = new FileInputStream(imageLoco);
param.put("imgResult"+(i+1), image);
}
param.put("emptyImg", iReportDir+"logo.jpg");
setTemplate("data/reports/templates/template_1.jasper");
jasperPrint = JasperFillManager.fillReport(getTemplate(), param, DatabaseUtility.getConnection());
} catch (JRException ex) {
System.out.println(ex.getMessage());
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
But, the And when I build to. Jar, the error disappears.
Please help, thanks before :)
Are you using the Calibri font? I've found that this is a jdk 1.7.0_21 bug and seems to be specific to Calibri.
Try switching the font to Arial and the error should go away.
If you have lots of reports and subreports to modify, this might help:
find . *.jrxml -type f -print0 |xargs -0 grep -lZ "Calibri" |xargs -0 sed -i 's/Calibri/Arial/g'
I have an application that also calls into the same JasperFillManager method and I can confirm that I see the same stacktrace in jdk 1.7_0_21. If I changing the jdk to 1.7_0_17 or 1.7_0_07 the error does not occur.
The class is in the rt.jar and as far as I know, source is not available. But 1.7 was based on openjdk and very similar source can be found at jdk7src.
Debugging the application, I can see that createCharinfo gets a StandardGlyphVector object and queries it for the number of glyphs, which returns 0. StandardGlyphVector.getGlyphCharIndices(0,0,null) then returns a non-null but empty array. The sun.font.ExtendedTextSourceLabel code doesn't check for null or empty array return cases and tries to access into the array which correctly throws the AIOOBE.
There seems to be a related bug report here.
I've also run into this issue and done a bit more testing on this. Here's the findings in short, but I've also commented on the OTN thread.
effected by the 1.6.0u45 and 1.7.0u21 Windows JVMs
only effected by the Calibri, Calibri Bold, Calibri Bold Italic, Calibri Italic and Cambria Bold fonts
most likely fixed in the non-public 1.6.0u51
fixed in 1.7.0u25
We were upgrading our jdk from b24 to b27 version of 1.6.
As we found the same problem, we got it fixed by font changes as following:
In iReport designer, for any element if we don't specify the font properties (fontName and fontSize), it will be set to default.
Hope this was giving problem.
So, we "specified the font properties (esp. fontName) for every element in each of our reports" and tried.
This has fixed the problem.
Root cause as expected:
In older versions of jdk the font manager is handling the default properties for the elements where font property is not specified.
In latest versions, may be the jdk is not able to handle the default font properties.
My app default encoding is set to "UTF-8" (using -Dfile.encoding=UTF-8 on startup).
When I use the String class method "getBytes(String charsetName)" with charset="ISO-8859-1", it appears that StringCoding.encode finally uses the default charset (UTF-8) instead of the given one (ISO-8859-1).
For an unknown reason, I can debug step by step on this method, but I'm not able to inspect inner elements value (only parameters which are named arg0, arg1 ...)
In java 1.6.10, StringCoding.encode is written :
static byte[] encode(String charsetName, char[] ca, int off, int len)
throws UnsupportedEncodingException
{
StringEncoder se = (StringEncoder)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);
}
With step by step debug, I never enter the if block and then no new StringEncoder with my ISO-8859-1 charset is created. Finally, the Charset.defaultCharset() method is called.
Any clues ?
Thanks
If you're not getting into the if block, then this expression must be false
(se == null) || !(csn.equals(se.requestedCharsetName())
|| csn.equals(se.charsetName()))
That means that:
se mustn't be null
The second part must be true before hitting the !, so one of these subexpressions must be true:
csn.equals(se.requestedCharsetName())
csn.equals(se.charsetName())
In other words, se is already appropriate for the charset name you've requested.
This isn't using the "default" encoding for the VM; it's using the encoder last used in this thread.
I highly doubt you've found a JRE bug - it looks okay to me. So what caused you to debug into this to start with? Can you provide a short but complete program which demonstrates an error using this? Something encoding to the wrong bytes?
You need to change the
-Dfile.ecoding=UTF-8
to
-Dfile.encoding=UTF-8
encode should never ignore the given charset to revert to the one given in -Dfile.encoding.
It does. As does decode by the way, even if the source does show that it finds the charset, and sets it in the line:
set(encoder, se);
Neither encode or decode are threadsafe, so the value is bound to be overridden by the system default, it may be before or after decode manages to use the set value though.
Imho, this is a bug in the JRE. True the OP had a typo, but that does not change the fact that if you ask String to decode a byte array to UTF-8, it should always return UTF-8, and not silently fall back to something else.
I'm trying to validate an Atom feed with Java 5 (JRE 1.5.0 update 11). The code I have works without problem in Java 6, but fails when running in Java 5 with a
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xml:base' to a(n) 'attribute declaration' component.
I think I remember reading something about the version of Xerces bundled with Java 5 having some problems with some schemas, but i cant find the workaround. Is it a known problem ? Do I have some error in my code ?
public static void validate() throws SAXException, IOException {
List<Source> schemas = new ArrayList<Source>();
schemas.add(new StreamSource(AtomValidator.class.getResourceAsStream("/atom.xsd")));
schemas.add(new StreamSource(AtomValidator.class.getResourceAsStream("/dc.xsd")));
// Lookup a factory for the W3C XML Schema language
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
// Compile the schemas.
Schema schema = factory.newSchema(schemas.toArray(new Source[schemas.size()]));
Validator validator = schema.newValidator();
// load the file to validate
Source source = new StreamSource(AtomValidator.class.getResourceAsStream("/sample-feed.xml"));
// check the document
validator.validate(source);
}
Update : I tried the method below, but I still have the same problem if I use Xerces 2.9.0. I also tried adding xml.xsd to the list of schemas (as xml:base is defined in xml.xsd) but this time I have
Exception in thread "main" org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Update 2: I tried to configure a proxy with the VM arguments -Dhttp.proxyHost=<proxy.host.com> -Dhttp.proxyPort=8080 and now it works. I'll try to post a "real answer" from home.
and sorry, I cant reply as a comment : because of security reasons XHR is disabled from work ...
Indeed, people have been mentioning the Java 5 Sun provided SchemaFactory is giving troubles.
So: did you include Xerces in your project yourself?
After including Xerces, you need to ensure it is being used. If you like to hardcode it (well, as a minimal requirement you'd probably use some application properties file to enable and populate the following code):
String schemaFactoryProperty =
"javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI;
System.setProperty(schemaFactoryProperty,
"org.apache.xerces.jaxp.validation.XMLSchemaFactory");
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Or, if you don't want to hardcode, or when your troublesome code would be in some 3rd party library that you cannot change, set it on the java command line or environment options. For example (on one line of course):
set JAVA_OPTS =
"-Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema
=org.apache.xerces.jaxp.validation.XMLSchemaFactory"
By the way: apart from the Sun included SchemaFactory implementation giving trouble (something like com.sun.org.apache.xerces.internal.jaxp.validation.xs.schemaFactoryImpl), it also seems that the "discovery" of non-JDK implementations fails in that version. If I understand correctly than, normally, just including Xerces would in fact make SchemaFactory#newInstance find that included library, and give it precedence over the Sun implementation. To my knowledge, that fails as well in Java 5, making the above configuration required.
I tried to configure a proxy with the VM arguments -Dhttp.proxyHost=<proxy.host.com> -Dhttp.proxyPort=8080 and now it works.
Ah, I didn't realize that xml.xsd is in fact the one referenced as http://www.w3.org/2001/xml.xsd or something like that. That should teach us to always show some XML and XSD fragments as well. ;-)
So, am I correct to assume that 1.) to fix the Java 5 issue, you still needed to include Xerces and set the system property, and that 2.) you did not have xml.xsd available locally?
Before you found your solution, did you happen to try using getResource rather than getResourceAsStream, to see if the exception would then have showed you some more details?
If you actually did have xml.xsd available (so: if getResource did in fact yield a URL) then I wonder what Xerces was trying to fetch from the internet then. Or maybe you did not add that schema to the list prior to adding your own schemas? The order is important: dependencies must be added first.
For whoever gets tot his question using the search: maybe using a custom EntityResolver could have indicated the source of the problem as well (if only writing something to the log and just returning null to tell Xerces to use the default behavior).
Hmmm, just read your "comment" -- editing does not alert people for new replies, so time to ask your boss for some iPhone or some other gadget that is connected to the net directly ;-)
Well, I assume you added:
schemas.add(
new StreamSource(AtomValidator.class.getResourceAsStream("/xml.xsd")));
If so, is xml.xsd actually to be found on the classpath then? I wonder if the getResourceAsStream did not yield null in your case, and how new StreamSource(null) would act then.
Even if getResourceAsStream did not yield null, the resulting StreamSource would still not know where it was loaded from, which may be a problem when trying to include references. So, what if you use the constructor StreamSource(String systemId) instead:
schemas.add(new StreamSource(AtomValidator.class.getResource("/atom.xsd")));
schemas.add(new StreamSource(AtomValidator.class.getResource("/dc.xsd")));
You might also use StreamSource(InputStream inputStream, String systemId), but I don't see any advantage over the above two lines. However, the documentation explains why passing the systemId in either of the 2 constructors seems good:
This constructor allows the systemID to be set in addition to the input stream, which allows relative URIs to be processed.
Likewise, setSystemId(String systemId) explains a bit:
The system identifier is optional if there is a byte stream or a character stream, but it is still useful to provide one, since the application can use it to resolve relative URIs and can include it in error messages and warnings (the parser will attempt to open a connection to the URI only if there is no byte stream or character stream specified).
If this doesn't work out, then maybe some custom error handler can give you more details:
ErrorHandlerImpl errorHandler = new ErrorHandlerImpl();
validator.setErrorHandler(errorHandler);
:
:
validator.validate(source);
if(errorHandler.hasErrors()){
LOG.error(errorHandler.getMessages());
throw new [..];
}
if(errorHandler.hasWarnings()){
LOG.warn(errorHandler.getMessages());
}
...using the following ErrorHandler to capture the validation errors and continue parsing as far as possible:
import org.xml.sax.helpers.DefaultHandler;
private class ErrorHandlerImpl extends DefaultHandler{
private String messages = "";
private boolean validationError = false;
private boolean validationWarning = false;
public void error(SAXParseException exception) throws SAXException{
messages += "Error: " + exception.getMessage() + "\n";
validationError = true;
}
public void fatalError(SAXParseException exception) throws SAXException{
messages += "Fatal: " + exception.getMessage();
validationError = true;
}
public void warning(SAXParseException exception) throws SAXException{
messages += "Warn: " + exception.getMessage();
validationWarning = true;
}
public boolean hasErrors(){
return validationError;
}
public boolean hasWarnings(){
return validationWarning;
}
public String getMessages(){
return messages;
}
}