I have this patch code which i downloaded from a web article (Calling Matlab from Java).
http://www.cs.virginia.edu/~whitehouse/matlab/JavaMatlab.html
But I donot know how to apply it in my windowsXp running computer.
What I'm trying to do is call Matlab script file from java. I have found the necessary source codes and every thing but this mater is holding be back.
Any help is highly appreciated. Thank you.
Here's the patch code.
Index: MatlabControl.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/java/net/tinyos/matlab/MatlabControl.java,v
retrieving revision 1.3
diff -u -r1.3 MatlabControl.java
--- MatlabControl.java 31 Mar 2004 18:43:50 -0000 1.3
+++ MatlabControl.java 16 Aug 2004 20:36:51 -0000
## -214,7 +214,8 ##
matlab.evalConsoleOutput(command);
}else{
- matlab.fevalConsoleOutput(command, args, 0, null);
+ // matlab.fevalConsoleOutput(command, args, 0, null);
+ matlab.fevalConsoleOutput(command, args);
}
} catch (Exception e) {
System.out.println(e.toString());
I'd download the standard UNIX patch tool and use:
patch -p0 <my_patch.diff
You need to apply that patch to the file MatlabControl.java. On Unix, you have the standard patch program to do that, but that ofcourse isn't normally present on Windows.
But looking at the patch file, it's very small and you could easily do the change by hand. Look at the patch file: The lines with a - in the left column must be removed. The lines with a + must be added.
So you must look in MatlabControl.java and remove this line:
matlab.fevalConsoleOutput(command, args, 0, null);
And add these lines:
// matlab.fevalConsoleOutput(command, args, 0, null);
matlab.fevalConsoleOutput(command, args);
In other words, it's a very small and simple change, you just have to remove the last two arguments to the method call to fevalConsoleOutput().
If you want the patch command (and lots of other Unix utilities) on Windows, you could download and install Cygwin.
If you use dev tools like Eclipse you can easily apply it as it is an option in the contextual menu (right click) go to Team - > Apply Patch. It should work.
This patch is so small, you can easily apply it by hand.
So simply open the file MatlabControl.java and change line 214 (the one prepended with -) to fit the lines prepended with +.
After that your code should look like:
else{
// matlab.fevalConsoleOutput(command, args, 0, null);
matlab.fevalConsoleOutput(command, args);
}
JMI (Java-to-Matlab Interface)'s Matlab class and its fevalConsoleOutput method are explained here: http://UndocumentedMatlab.com/blog/jmi-java-to-matlab-interface/
By Tortoise SVN, we can apply patch by following the below way. Click on Apply patch and browse the patch file.
Tortoise SVN
Related
I have a tarball that I can't open using python:
>>> import tarfile
>>> tarfile.open('/tmp/bad.tar.gz')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tarfile.py", line 1672, in open
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully
but I'm able to extract the file with no problem on the command line.
$ tar -xzvf /tmp/bad.tar.gz
I've traced the python tarfile code, and there's a function "nti" where they're converting bytes. It gets to this line:
obj.uid = nti(buf[108:116])
and blows up. These bits (for the UID) coming through as eight spaces. Not sure where to go from here...
Honestly it looks like the bug is in tarfile.py's nti function:
n = int(nts(s) or "0", 8)
The fall-through logic (or "0") is not working because s is spaces, not None, so int() blows up.
I copied tarfile.py from /var/lib/python2.7/ and wrapped that particular line with a try/catch, which fixed me up:
try:
obj.uid = nti(buf[108:116])
except InvalidHeaderError:
obj.uid = 0
It's a hack solution, though. Really I'd prefer that the python folk took a look at it and fixed the "or "0" logic.
Update
Turns out the tarball was created by the maven-assembly-plugin in a Java 6 project that had just been upgraded to Java 7. The issue was resolved by upgrading the maven-assembly-plugin to 2.5.3.
I have been using the JavaImp.vim script for auto importing Java statements in VIM
But trying out different directories in the JavaImpPaths, I am still unable to make JavaImp parse the Java files in the source to make auto imports possible
this is how my .vimrc looks like
let g:JavaImpPaths = "~/Documents/android-sdks/sources/android-21/android/content/"
let g:JavaImpClassList = "~/.vim/JavaImp/JavaImp.txt"
let g:JavaImpJarCache = "~/.vim/JavaImp/cache/"
This is what I get running JIG in new Vim window
:JIG
Do you want to create the directory ~/.vim/JavaImp/cache/?
Searching in path (package): ~/Documents/android-sdks/sources/android-21/android
/content/ ()
Sorting the classes, this may take a while ...
Assuring uniqueness...
Error detected while processing function <SNR>10_JavaImpGenerate:
line 75:
E37: No write since last change (add ! to override)
Done. Found 1 classes (0 unique)
Press ENTER or type command to continue
It might be late, but if anyone else comes along this might help them...
I got it working with the following changes to the script:
line 181 from
close
to
close!
And lines 207/208 from
let l:javaList = glob(a:cpath . "/**/*.java", 1, 1)
let l:clssList = glob(a:cpath . "/**/*.class", 1, 1)
to
let l:javaList = split(glob(a:cpath . "/**/*.java"), "\n")
let l:clssList = split(glob(a:cpath . "/**/*.class"), "\n")
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.
I'm trying to use Mozilla Rhino in my Java application for Android to evaluate some JavaScript. I am using Eclipse + ADT plugin.
First I tried simply downloading the Rhino .jar file from Mozilla's website and adding it to the project as a library in Eclipse. Eclipse recognised it fine and compiled the application. However, when running it I get an exception when calling Context.evaluateReader() (see below for stack trace).
Then I tried adding the Rhino source code as a separate Android project in Eclipse, marking it as a library and referencing it in my project, which was enough to get Eclipse to get it to compile, but led to the same error.
This is the stacktrace I get (java.lang.UnsupportedOperationException: can't load this type of class file)
Thread [<7> Thread-8] (Suspended (exception UnsupportedOperationException))
DefiningClassLoader(ClassLoader).defineClass(String, byte[], int, int, ProtectionDomain) line: 338
DefiningClassLoader.defineClass(String, byte[]) line: 62
Codegen.defineClass(Object, Object) line: 159
Codegen.createScriptObject(Object, Object) line: 114
Context.compileImpl(Scriptable, Reader, String, String, int, Object, boolean, Evaluator, ErrorReporter) line: 2440
Context.compileReader(Reader, String, int, Object) line: 1326
Context.compileReader(Scriptable, Reader, String, int, Object) line: 1298
Context.evaluateReader(Scriptable, Reader, String, int, Object) line: 1137
TimetableProcessor.evaluate(InputStream, String, String[]) line: 31
TimetableProcessor.processBasicData(InputStream, String) line: 58
TimetableProcessor.process(InputStream, String) line: 52
TimetableUpdater.update() line: 53
Main$1$1.run() line: 22
The bit of my code that hits the exception looks like this:
Context cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_1_7);
Scriptable scope = cx.initStandardObjects();
try {
Object result = cx.evaluateReader(scope, new InputStreamReader(data), /* <<< exception here */
filename, 0, null);
} catch (IOException e) {
// ...
}
I also found this blog post which contains similar code and says it works. The author says he used a jar file from the Android Scripting site. The only jar file I found there was in rhino_extras_r3.zip. However, it doesn't contain .class files but rather a classes.dex file. When I added this as a library in Eclipse, it didn't recognise the classes it contains and thus failed to compile my project because of the missing references to Rhino classes.
Any help at all on how to get this to work is appreciated!
I finally got it to work. I should have paid more close attention to that blog post I linked.
If I add the line
cx.setOptimizationLevel(-1);
to disable optimisations, everything works perfectly.
An Android-compatible edition of rhino1_7R2.jar is available on the SL4A site, in the version control system. Here is a sample project that wraps up Rhino and BeanShell into an Android interpreter service.
I've written a library which allows to run Rhino on Android.
Advantages include:
Rhino can only run on optimization level -1. The library supports all levels.
The library supports the use of JavaAdapter, which is not possible with base Rhino.
Altough i did not benchmark this, it should give a performance increase. (Compiled code is faster than interpreted code)
https://github.com/F43nd1r/rhino-android
In documentation code I see some things like this:
/*
* #(#)File.java 1.142 09/04/01
what does characters like #(#) meaning?
#(#) is the character string used by the Unix what command to filter strings from binaries to list the components that were used to build that binary. For instance what java on AIX yields:
java:
23 1.4 src/bos/usr/ccs/lib/libpthreads/init.c, libpth, bos520 8/19/99 12:20:14
61 1.14 src/bos/usr/ccs/lib/libc/__threads_init.c, libcthrd, bos520 7/11/00 12:04:14
src/tools/sov/java.c, tool, asdev, 20081128 1.83.1.36
src/misc/sov/copyrght.c, core, asdev, 20081128 1.8
while `strings java | grep '#(#)' yields:
#(#)23 1.4 src/bos/usr/ccs/lib/libpthreads/init.c, libpth, bos520 8/19/99 12:20:14
#(#)61 1.14 src/bos/usr/ccs/lib/libc/__threads_init.c, libcthrd, bos520 7/11/00 12:04:14
#(#)src/tools/sov/java.c, tool, asdev, 20081128 1.83.1.36
#(#)src/misc/sov/copyrght.c, core, asdev, 20081128 1.8
#(#) was chosen as marker because it would not occur elsewhere, source code controls systems typically add a line containing this marker and the description of the file version on synchronisation, expanding keywords with values reflecting the file contents.
For instance, the comment you list would be the result of expanding the SCCS keywords %Z% %M% %R%.%L% %E% where the %Z% translates into #(#).
From (hazy) memory, that was the tag used by SCCS back in the "good old days". Given that (to my knowledge), BitKeeper uses SCCS underneath, it could be BitKeeper.
It is usually something that is added automatically by the version control system.
That construct has no special meaning in Java. It is just some text in a comment.
It looks like something that's inserted by a version control system.