Java bridge to octave

: why the file.txt is not created?
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Scanner;
public class BridgeToOctave {
    //jMatrix the normalized matrix
    public static double[][] imageReshape(double[][] normalizedMatrix, int sameHeight, int sameWidth)
        StringBuilder octaveCommands =
                createOctaveCommand(normalizedMatrix, sameHeight, sameWidth);
        System.out.println("octave command created");
        executeViaTerminal(octaveCommands);
        System.out.println("octave command executed");
        double[][] reshapedM = readFile(sameHeight, sameWidth);
        if(reshapedM == null){
            System.err.println("Null matrix! ERROR");
            System.exit(1);
        System.out.println("the reshaped matrix was loaded");
        return(reshapedM);
    } //end of method
    private static StringBuilder createOctaveCommand(double[][] normalizedMatrix, int sameHeight, int sameWidth){
        StringBuilder octaveCommands = new StringBuilder("A=[");
        try{
            int rows = normalizedMatrix.length;
            int cols = normalizedMatrix[0].length;
             //System.out.println("rows = " + rows);
             //System.out.println("width = " + cols );
             rows = rows - 1;
             cols = cols -1;
            //read the normalized matrix
             //System.out.println("Reading the normalized matrix");
             for(int i=0; i< rows; i++){
                 for(int j=0; j< cols; j++ ){
                     octaveCommands.append(normalizedMatrix[i][j] + " ");
                 octaveCommands.append(";");
            octaveCommands.append("];");
            //now lets call the imresize function via octave
            octaveCommands.append(" resizedA = imresize(A, [" +
                    sameHeight + " " + sameWidth +
                    "]" + "," + "'bicubic'); ");
            //and then save that resized image as an array, in fileTxt.txt
            octaveCommands.append("save ('-text', '/home/elias85/file.txt', 'resizedA');");
            return(octaveCommands);
        }catch(Exception e){
            e.printStackTrace();
            return(null);
    private static void executeViaTerminal(StringBuilder octaveCommands){
        BufferedWriter out;
        try {
            out = new BufferedWriter(new FileWriter(new File("/home/elias85/commands.m")));
            //now parse the octave commands to the commandsMFile.m fileTxt
            out.write(octaveCommands.toString());
            //System.out.println("wrote commands to file");
            out.close();
            //now lets EXECUTE this fileTxt with octave
            Runtime r = Runtime.getRuntime();
            String cmd[] = { "/usr/bin/octave", " /home/elias85/commands.m"};
            //System.out.println("> octave /home/elias85/commands.m");
            Process p = r.exec(cmd);
            r.gc();
            p.destroy();
        } catch (IOException ex) {
            ex.printStackTrace();
    private static double[][] readFile(int sameHeight, int sameWidth){
        try{
                  File fileTxt = new File("/home/elias85/file.txt");
                  // Create a scanner to read the fileTxt
                  //System.out.println("creating scanner");
                  Scanner scanner = new Scanner (fileTxt);
                  //String unused = null;
                  //System.out.println("About to ignore the 1st 5 lines");
                  for(int i =0; i< 5; i++) //5 comment lines in the octave saved fileTxt
                      /*unused  += */scanner.nextLine();
                  //System.out.println("unused string = " + unused);
                  double[][] reshapedM = new double[sameHeight][sameWidth];
                  DecimalFormat df = new DecimalFormat("#.#####");
                  for(int i=0; i<sameHeight; i++){
                      for(int j=0; j<sameWidth; j++){
                          reshapedM[i][j] = Double.parseDouble(df.format(scanner.nextFloat()));
                  fileTxt.delete();
                  scanner.close();  //close the scanner
                  return(reshapedM);
              }catch(Exception e){
                  e.printStackTrace();
                  return(null);
} //end of classthis is a Java-Octave bridge. Even though it seems working, when it executes it can't find the file.txt file.why is that? i tell octave to save to file.txt file.when I do the same using the linux console then the file.txt is created fine

You cannot delete a file which which is open. Close the scanner before attempting to delete the file.
when it executes it can't find the file.txt file.why is that?Try checking that txtFile.exists() and txtFile.canRead()
What is the exact exception?

Similar Messages

  • PHP/Java Bridge deploy error

    I am getting the following error upon deploying a web-app PHP/Java Bridge and wonder if someone with more web-app experience can tell me if in fact that Java Server Faces is not available or if the web-app needs some
    internal changes. This might be more suitable to a development forum, but thought i'd give a try.
    Sun Java System Web Server 7.0U1 B06/12/2007 21:15
    info: FCGI1000: Sun Java System Web Server 7.0U1 FastCGI NSAPI Plugin B06/12/2007 21:15
    info: CORE5076: Using [Java HotSpot(TM) Server VM, Version 1.5.0_09] from [Sun Microsystems Inc.]
    info: WEB0100: Loading web module in virtual server [kady-amd] at [javabridge]
    info: PWC1412: WebModule[javabridge] ServletContext.log():PHP/Java Bridge servlet /webdocs/javabridge version 3.2.1b ready.
    *failure: WebModule[javabridge]ERROR: Java Server Faces is not available*
    java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory

    A step-by-step guide you find here:
    https://websmp202.sap-ag.de/~sapdownload/011000358700000877852006E/HowToWorkWithJavaProxies.pdf
    Code samples are here:
    http://de.geocities.com/stefan_grube/JavaProxyExample.zip
    Regards
    Stefan

  • VB-Java bridge strange  problem

    Hi,
    We are using JCom for our application. Our server is a weblogic 6.1 app server
    hosting EJB's and our client is a Visual Basic(VB) trying to access these EJB's.
    I am using "zero client installation" programming model.
    I am getting a strange problem. When I run my jcom bridge from the startup classes
    of Weblogic(using Runtime.exec()) the bridge is not accepting requests from VB.
    But if I run the same bridge from a command line DOS prompt, the bridge accepts
    the request from VB. I have ensured that in both cases the classpath/path variables
    are properly set.
    WOULD REALLY APPRECIATE, if someone can give inputs on this strange issue.(I am
    running my VB client on Win 2k platform and also my weblogic server runs on the
    same m/c).
    reg
    nilesh

    Hi,
    Am also facing java.lang.OutOfMemoryError: Java heap space. My JSF page retrieves more than 5000 records, the list is iterated and existed the controller(or action) , but throws this exception while displaying the JSF page. I have tried to increase the ram size, but no solution... Can any bosy please help me on this, would really appreciate.
    Thanks,
    Shan

  • WebView js-java bridge error

    I've been trying to run the WebViewSample from this page in Netbeans but get the following exception when it tries to call javafx from javascript *i.e. when you click the link to exit the help screen)
    Exception in thread "JavaFX Application Thread" java.lang.NoSuchMethodError: booleanValue
         at com.sun.webpane.webkit.JSObject.setMemberImpl(Native Method)
         at com.sun.webpane.webkit.JSObject.setMember(JSObject.java:37)
    I'm using jdk1.7.0_06 (which includes the javafx runtime) on Ubuntu 12.04. I get the same exception when I try the sample on my macBookPro.
    Should the sample work ? Any idea of how I might fix this ?
    Thanks
    Allan

    Should the sample work ? Any idea of how I might fix this ? Checking jira I noted:
    http://javafx-jira.kenai.com/browse/RT-22725 "JS2Java Bridge arrays and other parts of JS2Java Bridge do not work on Linux"
    Which generates the same error message and stack trace as that in your post.
    Looks like the error has been fixed and will be available in javafx 2.2b17.
    The sample does work for me (runs and does not throw exception) on Windows - I think the bug was Linux/Mac related only.
    My environment is:
    java.runtime.version=1.7.0_06-ea-b17
    javafx.runtime.version=2.2.0-beta-b16
    WindowsXP
    Loading the project up in NetBeans 7.1.2 generated a message that it was upgrading the project and getting it to build correctly was problematic (NetBeans couldn't find jfxrt.jar probably due to the old project format or a version of NetBeans predating the co-bundling of JavaFX and the JDK). So I just went to command line and ran ant to build the project from there and then it built fine. After that, I followed the test steps you described and everything worked ok with no exception printed.
    Edited by: jsmith on Jul 12, 2012 4:27 PM
    Updated answer based on finding related known issue in Jira.

  • Browser plug-in & Java components

    I post my topic here as I realized the JavaBean forum wasn't the right place. Sorry for the double post.
    As part of an application, I have developped a specific component/javabean that displays some data that may be stored in a file (*.ppp).
    I would like to register that component so that IE, Netscape, etc. use it to display a file when a user clicks on a or when a corresponding content-type is reached. This effect is actually used by Adobe for its pdf file format: when a user clicks on a .pdf link, the pdf will be displayed in the browser window.
    I found several strategies to (apparently) achieve this. Which ones are working? Which ones should be used? Which ones spare the most rewritting? Which ones are the most convenient for the user?
    - Using the JAF, JAVABEANS ACTIVATION FRAMEWORK (see http://java.sun.com/products/javabeans/glasgow/jaf.html). Does it work for IE?
    - Using the Java bridge for ActiveX (see http://java.sun.com/products/javabeans/software/bridge/). IE now requires plug-in to be written as ActiveX...
    - Java Pluglet API (see http://www.mozilla.org/projects/blackwood/java-plugins/). But does it work for IE? It does not even seem maintained...How would I rewrite my bean?
    I wish there was just a simple mechanism where you register your jar component and it would be used automatically when the browser reached the corresponding content-type :D
    Thanksfoo.ppp<a /> or when a corresponding content-type is reached. This effect is actually used by Adobe for its pdf file format: when a user clicks on a .pdf link, the pdf will be displayed in the browser window.
    I found several strategies to (apparently) achieve this. Which ones are working? Which ones should be used? Which ones spare the most rewritting? Which ones are the most convenient for the user?
    - Using the JAF, JAVABEANS ACTIVATION FRAMEWORK (see http://java.sun.com/products/javabeans/glasgow/jaf.html). Does it work for IE?
    - Using the Java bridge for ActiveX (see http://java.sun.com/products/javabeans/software/bridge/). IE now requires plug-in to be written as ActiveX...
    - Java Pluglet API (see http://www.mozilla.org/projects/blackwood/java-plugins/). But does it work for IE? It does not even seem maintained...How would I rewrite my bean?
    I wish there was just a simple mechanism where you register your jar component and it would be used automatically when the browser reached the corresponding content-type :D
    Thanks

    You can get it done at : http://www.thesoftwareobjects.com

  • Integrating Excel with Java

    Hi,
    How can Excel be integrated with Java such that if a user is working on an Excel , my Java application should be able to capture all the events from Excel Sheet.
    I have looked into POI, but it seems to me , it can read and wriite to Excel from Java, but i would like that if a user is making changes to a spredsheet then my Java Application should be notified about those changes
    In short, i would like to expose front end of a web application in Execl!
    Is there any open source package that can help in doing the integration
    Kindly share your views/ suggestions

    jschell wrote:
    If you just want most of what is occuring in Excel only then there are probably events in the Excel API (OLE >probably) that allow you to modify and react to changes. In my experience figuring out how to do that is very >difficult even for small bits of functionality.Can u please explain a little more on this.
    Can i use JNI to listen to COM server, probaly if i create some proxies for Excel that use JNI to listen to COM Server.
    I found a link on the internet http://www.ibm.com/developerworks/java/library/j-bridge/
    This Java bridge can integrate COM objects into their applications. But i am not sure if i can capture the live stuff from an Excel file when somebody is editing it.
    Also i would like to know, what should be the best stratergy when i would like to expose the Front end of an application in Excel , since the application involves a lot of numbers and users are more comfortable with Excel interface, and the rest of the application you want in Java.
    Kindly share your views on this!

  • JAVA 101: I need help with the terminology !

    WARNING: Long post, lots of silly questions. But It might help a
    lot of people.
    Hello,
    I'm having a tough time understanding BASIC JAVA technology in
    general and the way it is used to deploy web forms. Apart form
    the marketing droid stuff (Easy to install, works just fine,
    etc..), Oracle does not give any documentation about what gets
    installed and how the technology works with respect to oracle.
    I don't want to learn the JAVA language, I don't need it in my
    job. But I'd like to be able to determine what might be
    hapenning when oracle crashes and I'd like to know what to tell
    me developpers when they ask me what's available etc.. For
    example, if one of my developpers wants to work with java beans
    I have 2 problems:
    a) I don't have any idea about what a Java bean REALLY is
    b) I don't even know how oracle works with it and where to
    install the beans I could download.
    I need a terminology guide. What is a class ? whis is ewt ? How
    can I extend the java code that oracle gives us ? Is it
    possible ? Where do I start ?
    Looking at the $ORACLE_HOME/forms60/java/forms directory, I can
    see that all that is under this directory seems to be some kind
    of java objects (with dots in it, etc..) am I right ? At least
    when the java applet console is running, the messages that pass
    accross seems to relate to this directory in some way...
    What about the ewt directory ? What is it used for ? Do I really
    need it to deploy java web forms on the web ? Which product
    installed this directory ?
    What if I use jinitiator, do I still need the JDK (JDK or JRE ?)
    or is it "bundled" under the jinitiator directory somewhere ?
    What is JRE ? Is is installed by Sun's JDK, oracle's JDK or
    Jinitiator ? Applet viewer ?
    What about the BASIC virtual machines that come with the
    browsers (IE and Netscape) ? Do they need the JDK ? Where do
    they install their stuff ? Can they conflict with oracle's ?
    Can there be more than one JDK installed on my windows machine
    without me knowing ? In what registry keys to the JDK/JRE stuff
    puts stuff ?
    MOST IMPORTANT: How do I TOTALLY get rid of ALL the java stuff
    on my windows clients so I can later perform a FULL reinstall ?
    I think some of our clients are pretty messed up, after
    installing, deinstalling and reinstalling different versions of
    applet viewer, JDK and jiniiator. I'm pretty sure there are some
    pointers in the registry that are wrong (in Netscape, I get a
    lot of error talking about a java "bridge" that's broken, but
    don't know how to fix it or even what it is !)
    I don't think the ORACLE JINITIATOR UNinstall does a good job or
    removing all it installed in the registry and that may be the
    source of the myriads of problems we have with Web Forms.
    We don't know who to blame when a problem occurs in web forms:
    Forms Server ? OAS ? Solaris ? Windows ? Jinitiator ? At lkease
    if we KNOW that Jinitiator is OK...
    Any GOOD documentation explaining the basics (and if possible,
    something putting it in the context of Oracle, stating the
    differences) would be greatly appreciated.
    Thanks for your patience and your time.
    null

    See page 207 of the iPhone iOS4 User Guide

  • How to get Flex to communicate with a Java applet?

    We are building a Flex 2.0 app which needs to talk to a Java
    applet. The applet lives in the same HTML page as the Flex app. My
    guess is that we can use the Flex-Ajax bridge combined with some
    Javascript-java bridge. Any suggestions on specific libraries to
    use, web sites to consult, or techniques to use?

    Maybe this could help:
    http://www.kellyjo.com/code/flexjava/FlexJava.html

  • Linking java programs to spreadsheets

    I am trying to write a program that accepts numeric input and generates four different sets of numeric data. I want to link the program to Microsoft Excel so that as the program generates the numbers, it automatically populates the cells of an Excel spreadsheet. Also I want the program and the spreadsheet to be linked in such a way that changes in the values generated in the source program due to changes in input, are reflected in the cells of the spreadsheet.
    I am using the jdk1.1.1 on a Windows 98 machine.

    JIntegra also provide a COM-Java bridge that will allow you to do something like this.
    I didn't find that any COM bridges were very successful in the end, though, since there didn't seem to be a means of differentiating between various instances of Excel that might be open (Office assumes that the first instance should always be used). For simple applications a COM bridge should prove alright, though.

  • Java+php+linuxruntime  error

    Dear all i have one java class i amm using php pages to to use this class
    currently i am getting below error
    Fatal error: Uncaught exception 'java_RuntimeException' with message 'Could
    not connect to the context server . Error message: Connection refused (111)
    ' in /usr/local/apache2/htdocs/java/Java.inc:1163 Stack trace: #0
    /usr/local/apache2/htdocs/java/Java.inc(1180):
    java_Protocol->createSimpleHandler('@java-bridge-10...') #1
    /usr/local/apache2/htdocs/java/Java.inc(1187):
    java_Protocol->createHandler() #2
    /usr/local/apache2/htdocs/java/Java.inc(365):
    java_Protocol->java_Protocol(Object(java_Client)) #3
    /usr/local/apache2/htdocs/java/Java.inc(1541): java_Client->java_Client() #4
    /usr/local/apache2/htdocs/java/Java.inc(1650):
    __javaproxy_Client_getClient() #5
    /usr/local/apache2/htdocs/java/Java.inc(1665): java_session_array(Array) #6
    /usr/local/apache2/htdocs/java.php(3): java_session() #7 {main} thrown in
    /usr/local/apache2/htdocs/java/Java.inc on line 1163

    "Connection refused"
    I think it is safe to assume your network settings are wrong and it actually has nothing to do with java. Firewall problem perhaps?

  • Execute Java from PHP (Classpath problem?)

    Hi,
    I'm trying to execute a java application (just a few classes really), using PHP (so the app can be executed by the click of a button on a webpage). It is an Apache server running on windows.
    The code to execute the java from the webpage is as follows...
    <?php
    echo "<pre>> EXECUTING...</pre>";
    $output = shell_exec('java UpdateStock');
    echo "<pre>$output</pre>";
    ?>However, I get this error.
    java.lang.ClassNotFoundException: com.mysql.jdbc.DriverThe class runs fine from the command line (it's all setup using the typical classpath method), so I suspect its something to do with the server's configuration and not being able to find the drivers. How do I point the server-based app to the mysql drivers?
    Many thanks for your help
    Edited by: chezza on Nov 13, 2008 3:04 AM

    Is it that your CLASSPATH has to be a system variable, and you've got it setup as a user variable... and the tomcat service runs as the "system" user, so it knows not your kinky CLASSPATH.
    To totally avert such problems allways execute every java app you ever run with the -classpath (or -cp ?1.5? or later) switch... including those you launch from php.
    BTW... The [PHP Java Bridge|http://php-java-bridge.sourceforge.net/pjb/installation.php] might be an option for you.

  • Accessing non-Java components from Struts

    I want to access a PHP forum package through my Struts classes.
    Can someone pls help?

    I want to access a PHP forum package through my Struts classes.Do you know how to use a Search Engine ?
    http://php-java-bridge.sourceforge.net/
    andi

  • Talking to an OCX from Java?

    Hello again. I need to know how to instance an OCX object. I am using rJAX. It�s a soft that converts an OCX into a .jar
    The question is how do I instantiate a com object or an OCX (ofcourse inside my .jar). If somebody has an exampe, I would very much appreciate it.
    Thanx...

    Check out www.linar.com. They have an excellent Com-to-Java bridge package that I have used in a production system

  • Recommendation of plugin for Java Exchange  (or IMAP) connector.

    Hello,
    We have been using Moyosoft as a Java to Exchange connector. We have been having issue with a few of our data feeds coming through this avenue. I was just wondering of anyone in this forum could recommend a different approach. At present we.
    1. Have datafeeds come to an email box.
    2. Moyosoft scans email box and extracts datafeed into our system.
    Is there other solutions.
    Thanks,

    Adam Y wrote:
    We have been using Moyosoft as a Java to Exchange connector. I can only presume you mean you are using the "Java Bridge to Exchange" product from them.
    However far as I can tell that has nothing to do with JDBC - which is the point of this particular forum.
    We have been having issue with a few of our data feeds coming through this avenue. I was just wondering of anyone in this forum could recommend a different approach. At present we. In terms of a forum that might provider alternatives one of the JEE forums or just the main Java one might suggest alternatives.
    One alternative of course is to write your own interface either JNI or a server to which you use TCP to communicate in java (actually I am pretty sure exchange already has a TCP interface so all you need to do is implement that in java directly.)
    Or maybe buy the source code from that company and figure out the problem.

  • Advanced math functions/libraries

    Are there any more advanced math functions/libraries available for Java (other than in the normal Math class)? Right now I'm looking for something that will rapidly return all the factors of an integer, but I am likely to be interested in other features in the future as well. Thanks.

    Kramis wrote:
    Are there any more advanced math functions/libraries available for Java (other than in the normal Math class)? Right now I'm looking for something that will rapidly return all the factors of an integer, but I am likely to be interested in other features in the future as well. Thanks.Not in the standard classes.
    You could look at the Apache Math library:
    [http://commons.apache.org/math/]
    perhaps it has some number theory methods.
    Or you could look into a Java bridge/interface between existing computer algebra systems (CAS) like Maple, Mathcad (both commercial) or the excellent opensource alternative: Octave. All these CAS have a bridge/interface to Java.

Maybe you are looking for