Redirect the class output.

Hi!
I am new to java.
I have a class file that print to output a result from three parameters I pass to it, this class are byte code compiled and I am not have the source code.
I want to know how to redirect this output to an variable into my program.
thank in advance.
Paulo

It's possible, although slightly involved. If you look at the System class, you'll see a method [url http://java.sun.com/j2se/1.4/docs/api/java/lang/System.html#setOut(java.io.PrintStream)]setOut. This allows you to set the stream to which the other class is writing its output. So what to set it to? Well, you presumably want to get the output as a String, so I suggest the following: import java.io.*
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
// Call other class here.
String output = out.toString();

Similar Messages

  • Can you redirect the audio output of iTunes via Apple TV?

    I currently have iTunes running on Windows XP with an Airport Express connected to my home stereo. I toggle the iTunes audio between my PC and the Airport Express via the iTunes speaker setting. With Apple TV, will I be able to toggle the audio output from the Apple TV interface?
    Thanks,
    Chaaad

    No, you can use AppleTV like an Express to have audio playing in iTunes relayed to it, but you can't play something on AppleTV and direct the output to the Express.
    AC

  • Redirect the refcursor output of an SP to a table ?

    hi.
    i have an SP which returns a refcursor. now what i need is to get this output to a table so that i can manupulate the data.
    this is how i executed the table
    var a refcursor
    exec packagename.spname(:a,'inputchar');
    print :a;
    please help.
    i tried create table temp as select * from :a
    and
    create table temp as select * from table (cast a as a)
    but both didnt work..
    what am i missing here ????

    novicedba wrote:
    the SP is not mine. so i cannot alter it.So? That does not make something less wrong.
    suppose the refursor returns itemcode, purchase_time, price. and details of 100+ items are returning in thi refcursor. what i need is first to get the results. and then filter it only to view detaild of one item. Why? That cursor does work (in the SQL engine) to find the relevant rows (using indexes and/or tables reading data blocks). It does +"x"+ amount of work to output the results for that SQL select statement.
    Now you want to filter, in PL/SQL or another client language, the output of that cursor. That filtering should be done by the SQL engine - as it is best suited for doing that work. And the workload of +"x"+ that was needed, can now be +"x/2"+ as a result - as the filtering and elimination of columns not needed from the SQL projection can significantly decrease the workload and increase performance.
    So what benefits are there to filter the output of a cursor? NONE! There are no benefits. Not a single one.
    this is why i need to get the Output into a table.The cursor returns data from the SQL engine. This data needs to be pushed from the SGA db buffer cache all the way to the client language. In the case of PL/SQL, into the private heap space of the process (called the PGA).
    Then you take that very same data, create an insert SQL cursor, and send that data back to the SQL engine to be inserted.
    So what benefits are there pushing and pulling SQL data like this across memory and process and even platform boundaries, when the both the read data and write data processes could have been done as a SQL "+insert .. select+" cursor? NONE! There are no benefits. Not a single one.
    (no wonder this sounds like TSQL coz i am more familiar to TSQL than PL ;) (irrelevant stuff) )Treating PL/SQL like TSQL 'cause your are "familiar" with TSQL is, bluntly put, idiotic. PL/SQL is not TSQL. Oracle is not MS-SQL Server.
    if i am going for a cast.. what should i do ?I would go instead for the manuals.. and educate myself on the concepts and fundamentals of the product and languages I'm using. And design and write robust and performant and flexible and scalable code.

  • Redirecting the servlet output to jsp

    Hi i need to redirect my servlet out put to jsp
    in result set's every row i have 9 columns
    this result set how can i redirct to jsp
    plz can any one let me know with an example
    thanks a lot in advance

    inamdar wrote:
    Hi i have never used DTO's and DAO classes
    plz colud u let me know without using that..Huh? It is never too late to start with it. Just create two simple classes. A DTO class is basically a simple javabean with private (encapsulated) properties and a public getter and setter for each property. A DAO class is basically a class which contains purely JDBC code.
    Sample DTO:public class MyData {
        private Long id;
        private String name;
        private Integer value;
        public Long getId() { return id; }
        public String getName() { return name; }
        public Integer getValue() { return value; }
        public void setId(Long id) { this.id = id; }
        public void setName(String name) { this.name = name; }
        public void setValue(Integer value) { this.value = value; }
    }Sample DAO:public class MyDataDAO {
        public List<MyData> listAll() {
            String listAllQuery = "SELECT id, name, value FROM data";
            List<MyData> myDataList = new ArrayList<MyData>();
            Connection connection = null;
            Statement statement = null;
            ResultSet resultSet = null;
            try {
                connection = getConnectionSomehow(); // DriverManager or Connection Pool, your choice.
                statement = connection.createStatement();
                resultSet = statement.executeQuery(listAllQuery);
                while(resultSet.next()) {
                    MyData myData = new MyData();
                    myData.setId(new Long(resultSet.getLong("id")));
                    myData.setName(resultSet.getString("name"));
                    myData.setValue(new Integer(resultSet.getInt("value")));
                    myDataList.add(myData);
            } catch (SQLException e) {
                // Handle it. Print it, throw it, log it, mail it, your choice.
                e.printStackTrace();
            } finally {
                // You can write an utility class/method for those lines as well.
                if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } }
                if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } }
                if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } }
            return myDataList;
    }Sample Servlet code:List<MyData> myDataList = new MyDataDAO().listAll();
    request.setAttribute("myDataList", myDataList);
    request.getRequestDispatcher("someJspFile.jsp").forward(request, response);Sample JSTL code in someJspFile.jsp:<table>
        <c:forEach items="${myDataList}" var="myData">
            <tr>
                <td>${myData.id}</td>
                <td>${myData.name}</td>
                <td>${myData.value}</td>
            </tr>
        </c:forEach>
    </table>Simple and clean, isn't it?

  • How to redirect the tomcat (5.0) console output to a text file

    Hello,
    I am looking for a way of redirecting the tomcat console output [the System.out.println("xyzabc")�s from the java classes running on the container] to a text file.
    The reason is that the programmers need to have that console�s output and the server (windows) have to be rebooted often (no wonder: windows) and then Tomcat start as a service -> console is not visible.
    Thanks!

    The console out put should still be in the log files if tomcat is running as a windows service. It will either be in logs\stdout_xxxx.log and logs\stderr_xxxx.log or in logs\catalina.xxxx.log.
    If you are using 5.5.
    It will either be in logs\stdout.log and logs\stderr.log or in logs\catalina.out.
    if you are using 5.0

  • Output in word file: Methods or the class name required

    Hi Gurus,
    I am trying to get output of the program in a word document directly without any Script or Report in between.
    Steps i follow are:
    Fetching the data
    Invoking word
    Writing the data into the word file created using methods like 'tablegridlines', 'insert' etc.
    When i get this data in the word file , in between every two lines i get one empty (extra) line.
    What can i do to remove that extra line in between. Everything has to be done in my own program using methods.
    Is there any method to delete the line comming between two lines i have created.
    Is there any method to convert the layout of the word file created to "Landscape".
    I would appreciate if somebody could tell me the class which has the methods like 'tablegridlines'
    'insert' 'viewheaderfooter' etc which are used for word output in this case.
    The object that i have created is of the type ole2_object.
    Helpful answers would certainly be rewarded.
    Thanks
    Suruchi
    Edited by: Suruchi Mahajan on May 14, 2008 6:04 AM

    Hi All,
    For the possible methods ,search in table OLELOAD.
    Regards
    Suruchi

  • ALV Tree list output using the Class and method

    Hi,
    How to get the internal table values of ALV Tree List in classes.
    My requirement is i need to store the output values in Ztable of a SAP Transaction of CK86_99.
    for this, i copied the SAP Standard Transaction into Z tcode and i am trying to poplulate the output display into Ztable. But this standard tcode CK86_99 is using the classes of ALV tree list to display output.
    CL_STRUCTURE_EXPLOSION_TREE -- Class
    CONSTRUCTOR - method
    Finally in the above mentioned method, i am able to see the output values of ALV tree list in the internal table of mt_output_table.
    But these are SAP Standard Class and method.
    My doubt is, How to get these internal table values in my Zprogram.
    is there any user exit or badi can we use in the method of class???? Actually my system is 4.6C
    Please suggest me on this problem.
    Thanks in advance
    KBS Reddy

    First your getInstance() method returns 'singleton' which you havent declared/init anywhere.
    your getAll() method needs to be static if you need to call it the way you are doing.
    In your getAll() method u are passing a parameter called patientRecord ... where have you declared/init it.
    i think you have to do something like this ... if i have understood you correctly.
    /* THIS IS IN YOUR SERVLET*/
    Collections c = database.getAll();
    out.println(C);
    /* YOUR FlatfileDatabase CLASS HAS SOMETHING LIKE THIS*/
    public static FlatfileDatabase getInstance() {
    return new FlatfileDatabase();
    public static Collections getAll() {

  • Redirect the output of SQL*Plus to the file

    Hi all,
    I have the following command to run:
    sqlplus username/password @myfile.sql
    I don't know how to redirect the output to the file.
    Also in the script myfile.sql I have the defined variable, &VP and
    How can I substitute this variable(&VP) at the run time.
    Thanks,
    JP

    Assumed you like to replace your defined variable VP by number 4. SInce it is posintional parameter,instead of wrinting &VP, write
    VP:=&1
    sqlplus>spool redirect.txt
    sqlplus>@myfile.sql 4
    sqlplus>spool off

  • IS IT POSSIBLE TO REDIRECT THE OUTPUT TO ANOTHER PAGE?

    Hi all,
    Is it possible to redirect the output when I excute my query in iSQL*plus to another predifined html page?
    If yes how do I do this?
    Thanks a mill

    You could do this..just read on..
    It would generate a html page for you...and..so on..!
    In addition to plain text output, the SQL*Plus command-line interface enables you to generate either a complete web page, or HTML output which can be embedded in a web page. You can use SQLPLUS -MARKUP "HTML ON" or SET MARKUP HTML ON SPOOL ON to produce complete HTML pages automatically encapsulated with <HTML> and <BODY> tags.
    By default, data retrieved with MARKUP HTML ON is output in HTML, though you can optionally direct output to the HTML <PRE> tag so that it displays in a web browser exactly as it appears in SQL*Plus. See the SQLPLUS MARKUP Options and the SET MARKUP command for more information about these commands.
    SQLPLUS -MARKUP "HTML ON" is useful when embedding SQL*Plus in program scripts. On starting, it outputs the HTML and BODY tags before executing any commands. All subsequent output is in HTML until SQL*Plus terminates.
    The -SILENT and -RESTRICT command-line options may be effectively used with -MARKUP to suppress the display of SQL*Plus prompt and banner information, and to restrict the use of some commands.
    SET MARKUP HTML ON SPOOL ON generates an HTML page for each subsequently spooled file. The HTML tags in a spool file are closed when SPOOL OFF is executed or SQL*Plus exits.
    You can use SET MARKUP HTML ON SPOOL OFF to generate HTML output suitable for embedding in an existing web page. HTML output generated this way has no <HTML> or <BODY> tags.

  • Can't redirect the Runtime exec output

    I'm trying to get mysqldump to give me some output which I can redirect to the tmp1 location
                   String tmp2 = "mysqldump";
                   Runtime rt1 = Runtime.getRuntime();
                   if(File.separatorChar == '\\') {
                        tmp2 = "\"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";
                   tmp1 = tmp2 + " > " + tmp1;
                   rt1.exec(tmp1);All I want to see at this point is just the error message telling me how to use mysqldump.
    After that I'll do something useful.
    I'm running under NetBeans and if I don't try to redirect I get nothing in the output window.
    Of course, if I run it from a Command box, I see the expected output.
    I know I'm running the program because if I change it to the nonsense mysqldump3, it will tell me that it can't find the file.
    I can't figure out where the output is going and how to capture it.
    Any ideas would be appreciated.
    Ilan

    Ilan wrote:
    Hi Sabre,
    Since I didn't understand your code, I'll use it as a chance to learn something.
    I don't understand what cmd.exe is doing. It is just opening a DOS box?No! It is interpreting the command string.
    Why do you need that? (Maybe I do and I don't know so....)You need to learn a good bit more about your operating system. Get a good book on Windows.
    >
    The simplest thing would be String command = "mysqldump > file.sql".
    Why shouldn't that work?1) Because the directory containing your mysqldump is not in the PATH.
    2) Because the redirection operator '>' is only applicable when interpreted by the command processor (cmd.exe). Reads your Windows manual.
    >
    The reason I need the explicit path is because mysqldump isn't on my Windows path (Linux is nicer that it is in usr/bin, so there is no problem.)
    So I detect Windows and for Windows put the path and command in quotes.
    (Now that I think about it, cmd.exe probably wouldn't work in Linux anyway.)On Linux you will need your shell to interpret the redirection operator '>' .
    >
    What is that "/C" all about? Go to drive c:?
    Your first attempt looks like a confusion with mysqldump, once without a path followed by a path.
    That one I don't understand at all.
    How do I go about getting control of the stderr, if I don't already have control?
    BTW, I haven't yet tried it in Linux. First I'll get the Windows version going.
    Thanks for your reply. I'll try to learn from it.You need to read, read again, study and then implement the recommendations in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    Sorry if this sounds like I'm passing the buck but your lack of knowledge of Windows, Linux and Runtime.exec() means I cannot help without writing a large tutorial.

  • Redirecting the output

    Hi Satya, Thanks for helping me out couple of times earlier. I am having one more problem.
    I am able to get the runtime values of the server, but while I am unable to redirect the output to a dat file in the local box, from which I am extracting the results. I tried to use redirect(), but not able to make it work. I need help with the right command and any suggestions, that I can use to output the results to a dat file.
    Thanks again.

    Not sure I understand what you are trying to achieve. When you use redirect('./foo.dat') wlst will write the output that comes out of WLST to foo.dat. You should be able to read this file and get the outout and parse it.
    I am not sure what you are trying to do, can you post any errors you are seeing?
    -satya
    BEA Blog: http://dev2dev.bea.com/blog/sghattu/

  • Junk Characters in Report Output(While redirecting the output to text file)

    While generating the report (Reports 9i) output to a text file, I get the report output that contains junk characters. The other output formats viz. pdf, rtf have no problem.
    Please share how to correct it.
    Thanks.

    Yes, the MODE is set to Character and DESFORMAT is set to DFLT.
    Still the problem exists.
    Any idea please?

  • Redirecting the output of java compilation to a text file

    i tried to redirect the result of the java compilation to the text file using
    javac zz.java > compile.txt
    It works if the program has no errors and it did not work if it have errors. Wat is the reason it did not work for wrong programs.

    This has nothing to do with Java. It's your command shell.
    If you're on linux, then it's because the errors go to stderr and you're only redirecting stdout. I assume Windows is similar, but I don't know much about that.
    For bourne shell family on linux (sh, ksh, bash, zsh), you'd do
    javac zz.java > compile.txt 2>&1I'm not sure what the syntax is for csh family.

  • How do you redirect the user to a custom page after the "Save" button is clicked?

    In SharePoint 2010, I could add the following code to a save button to redirect the user to a custom page.
    <input type="button" value="Submit" class="btnStyle" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/SitePages/Thankyou.aspx}')}" />
    However, how do you do this for a save button in SharePoint Online? The code of a save button in SharePoint Online looks like
    <input type="button" value="Save" name="ctl00$ctl33$g_175de2e0_43c1_4005_bac5_0ab02439686f$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem" onclick="if (!PreSaveItem()) return false;if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ1')) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl33$g_175de2e0_43c1_4005_bac5_0ab02439686f$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true;javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/SitePages/Thankyou.aspx}')}))" id="ctl00_ctl33_g_175de2e0_43c1_4005_bac5_0ab02439686f_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" accesskey="O" class="ms-ButtonHeightWidth" target="_self">

    Not exactly what you are asking for, but if you are creating the link then you could add "?Source=" to the URL.
    http://yourServer/sites/yourSite/Lists/TestList/NewForm.aspx?Source=/SitePages/Thankyou.aspx
    Mike Smith TechTrainingNotes.blogspot.com
    Books:
    SharePoint 2007 2010 Customization for the Site Owner,
    SharePoint 2010 Security for the Site Owner

  • How to determine the Class of a static methods class?

    hi,
    is there a way to get the code below to output
    foo() called on One.class
    foo() called on Two.classthanks,
    asjf
    public class Two extends One {
       public static void main(String [] arg) {
          One.foo(); // should say "foo() called on One.class"
          Two.foo(); // should say "foo() called on Two.class"
    class One {
       public static final void foo() {
          System.out.println("foo() called on "/*+something.getClass()*/);
    }

    - One.class won't resolve to Two.class when the static
    method is called via the class TwoThat's because static methods are not polymorphic. They cannot be overridden. For example try this:
    public class Two extends One {
       public static void main(String [] arg) {
          One.foo(); // should say "foo() called on One.class"
          Two.foo(); // should say "foo() called on Two.class"
          One one = new Two();
          one.foo();
          ((Two) one).foo();
       public static void foo() {
          System.out.println("foo() called on Two");
    class One {
       public static void foo() {
          System.out.println("foo() called on One");
    }

Maybe you are looking for

  • How to edit text in the yellow text box of a URL-link?

    Hey guys! I´m currently working on a website in Iweb. My current challenge is the following: - I´ve made a marked text a hyperlink. But when I rollover it, a yellow text box appears and shows the entire URL. Now, I want it to show a custom edit text.

  • Updating N95 Firmware! Some important questions

    My N95 is currently running on V20.0.013. A major improvement in update were found in V20.0.015. Now a days the latest firmware is V21.0.016. Q1. If I update my N95 to 21.0.016, then would I get all the improved features of V20.0.015 as well or shoul

  • Yosemite - Desktop Call doesn't work

    I have a Late 2011 Macbook Pro and I've just upgraded to Yosemite. However, I can't receive my calls from my MBP. The notification which should be appearing on the upper right corner, doesn't show up. Any ideas, why ?

  • To-Do Printing in random order!?!?

    I've organized my to do list exactly how i want it (by calendar) and when i go to print, they all appear in random order! All i want is the title of the to-do and the calander it belongs in. Can anyone help me out?

  • Need Adobe Air To Install Adobe Air

    While trying to install another product my MacBook Pro i7 OS X verizion 10.7.2 informed me that it needed Adobe Air to install completely, so i travled to the Adobe page and downloaded Adobe Air, when trying to install this product I was informed tha