Files and Streaming

Hi. I am loading a big text file to a JTextPane and I'm using a URL from getResource() and URLConnection to get the stream. I'm using InputStreamReader to read the stream. The problem is the whole process is slow. A 139kb text file would take an hour to get. The technique im using is a simple one, straight from the io tutorials.
Another question on files: I have a JProgressBar for the above stream, but I use separate File object just to get the filesize. And I'm chaning the program in to an applet and using that File object violates applet restrictions and therefore cant be read. How do I get the filesize from a URL or any way that is valid from an applet?
Thanks.

Hi there. I think I solved it. The problem is inside the loop that reads the stream I have:
contents = contents + (char) buf;
where contents is the String that eventually gets setTexted in the textpane and int buf is the read byte from the stream. It is slow because when the string gets bigger, appending a single char to it becomes slow. I thought about it when I put a progressbar with it. The bar decelerates in time, therefore something inside is getting slower.

Similar Messages

  • File and Streams resources

    Can anyone tell me of any links where I can find extensive material about Files & Streams in Java?
    Many Thanks

    Hi there
    try
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    There is a section on Files and Streams
    Alternatively there is a very useful book by Elliot Rusty Haroldcalled "Java I/O" O'Reilly & Associates; ISBN: 1565924851
    This is very readable and helpful

  • Files and Streams java -- Sequential access file-- Plz help me

    I am able to add records in sequential file and then also I am able to display each record sequentially.
    But after closing the file if I open the file for adding records, the newly added records are not being displayed while clicking the "next" button to read them.
    How to bring the pointer to end of records in sequential file , so that when I stat adding records after opening an existing file, they should be added successively after the last record in that file.
    enter = gui.getTask1();
              enter.setText("Enter");
              enter.setEnabled(true);
              try
              FileOutputStream fos = new FileOutputStream("c:/file.txt",true);
              output = new ObjectOutputStream(fos);
              enter.addActionListener(
                        new ActionListener()
                             public void actionPerformed( ActionEvent e )
                                  addRecord1();
              catch(Exception e)
                   System.out.println("Error in ObjectOutputStream before pressing Enter button");
    private void addRecord1()
              String[] fieldValues = gui.getFieldValues();
              if(! fieldValues[0].equals(""))
                   try
                        int id=Integer.parseInt(fieldValues[0]);
                        if(id>0)
                             Record rcrd = new Record(id, fieldValues[1], fieldValues[2]);
                             System.out.println(" " +rcrd.getString()+"\n");
                             output.writeObject(rcrd);
                             output.flush();
                             gui.clearFields();
                             display.append(" "+rcrd.getId()+" "+rcrd.getName()+" "+rcrd.getAddr()+"\n");
                             readf.setEnabled(true);
                   catch (NumberFormatException nfe)
                        JOptionPane.showMessageDialog(this, "Incorrect id", "Invalid number formate", JOptionPane.ERROR_MESSAGE);
                   catch (IOException io)
                        closeFile();
         }Message was edited by:
    MissJavaa

    You can't append multiple ObjectOutputStreams to the same file unless you know where one ends and the other starts and you use a new ObjectInputStream at each join. And even that mightn't work because of buffering. Keep the file open or start a new file.
    And I wouldn't call the file 'file.txt', it isn't a text file.

  • Files and Streams Question

    Hi! Java is my first and only language; and I am very new to Java. This is my first somewhat knowledgeable attempt to get a question answered on a forum of any kind. I put a question in this forum about two weeks ago, but I lost it. So, I am very grateful for any comments that can improve my ability to get my questions answered. Thank you. Mike
    Here is my problem:
    Read File: I want to read pT.txt or plainText.txt file (that is encoded in Unicode) into a String variable (inputLine).
    (I want to do some processing of the inputLine String and assign the processing results into outputLine.)
    Write File: I want to write outputLine into aPT.txt or anotherPlainText.txt file (that is encoded in ASCII).
    Here is my question:
    What is the simplest or easiest code for the Read File and Write File instructions?
    Thanks. Mike

    Why am I not entering the while loop?
    import java.io.*;
    //not yet: import java.util.Scanner;
    public class FnS
         public static void main(String[] args) throws Exception
              File inFile = new File("pT.txt");
              BufferedReader input = new BufferedReader (new FileReader (inFile));          
              //not yet: PrintWriter outFile = new PrintWriter (new BufferedWriter (new FileWriter ("outFile.txt")));
              String peek1, peek2, peek3, peek4, peek5, peek6;
              boolean pk1 = false, pk2 = false, pk3 = false, pk4 = false, pk5 = false;
              int count = 0;
              while(input.ready())     // begin search
                   peek1  = input.readLine();
                   if (peek1.startsWith("One"))
                        pk1 = true;
                        peek2  = input.readLine();
                        if(pk1 && peek2.startsWith("Two"))
                             pk2 =true;
                             while(pk1 && pk2)
                                  peek3  = input.readLine();
                                  if(pk1 && pk2 && peek3.startsWith("Three"))
                                       pk3 = true;
                                       peek4 = input.readLine();
                                       if(pk1 && pk2 && pk3 && peek4.startsWith("Four"))
                                            pk4 = true;
                                            while(pk1 && pk2 && pk3 && pk4)
                                                 peek5 = input.readLine();
                                                 if(pk1 && pk2 && pk3 && pk4 && peek5.startsWith("Five"))
                                                      pk5 = true;
                                                      peek6 = input.readLine();
                                                      if(pk1 && pk2 && pk3 && pk4 && pk5 && peek6.startsWith("Six"))
                                                            *  (I want to do some processing of the inputLine String and assign the processing results into outputLine.)
                                                            *     Write File:  I want to write outputLine into aPT.txt or anotherPlainText.txt file (that is encoded in ASCII).
                                                            *     Here is my question:
                                                            *  What is the simplest or easiest code for the Read File and Write File instructions?
                                                            *     Thanks.  Mike
                                                           System.out.println("\n" + peek6 + "\n" + peek5 + "\n" + peek4 + "\n" + peek3);
                                                           count++;
                                                           pk1 = false;
                                                           pk2 = false;
                                                           pk3 = false;
                                                           pk4 = false;
                                                           pk5 = false;
                                                           break;
                                                      }//if pk1 && pk2 && pk3 && pk4 && pk5 && peek6
                                                      else
                                                           pk1 = false;
                                                           pk2 = false;
                                                           pk3 = false;
                                                           pk4 = false;
                                                           pk5 = false;
                                                           break;
                                                      }//else begin  new search
                                                 }//if pk1 && pk2 && pk3 && pk4 && peek5
                                            }//while pk1 && pk2 && pk3 && pk4
                                       }// if pk1 && pk2 && pk3 && peek4
                                       else
                                            pk1 = false;
                                            pk2 = false;
                                            pk3 = false;
                                            pk4 = false;
                                            pk5 = false;
                                            break;
                                       }//else begin new search
                                  }//if pk1 && pk2 && peek3
                             }//while pk1 && pk2                              
                        }//if pk1 && peek2
                        else
                             pk1 = false;
                             pk2 = false;
                             pk3 = false;
                             pk4 = false;
                             pk5 = false;
                        }//else begin new search
                   }//if peek1
              }//while hasNext
              System.out.println("\nemail count = " + count);
    }

  • Files and Streams in java -- How to display successive records

    Hi,
    I developed an application in which I enter name and id in a gui. Each time I enter, the records are added in the sequential file.
    Then I have a button to open that file. It also opens.
    Then I have a button to read the records(which has name and id) in sequential order. Each time I click next button records should be displayed in their respective text boxes. But, only the 1st record is displyed. Then I get IOException. Why am I not able to move to records after 1st record. How could I disply records till EOF is reached.
    Plz see my code for open function and read next function
    private void openFile()
    input=new ObjectInputStream(new FileInputStream("c:/file.dat"));
    openf.setEnabled(false);
    readf.setEnabled(true);
    private void readNext()
    rcrd=(Record)input.readObject();
    String val[]= {String.valueOf(rcrd.getId()),rcrd.getName(),rcrd.getAddr()};
    gui.setFieldValues(val);
    Why am I not able to move to records after 1st record. How could I disply records till EOF is reached.

    package files;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import files.FileGui;
    import files.Record;
    import java.util.*;
    import java.lang.*;
    public class CreateFile extends JFrame
         private ObjectOutputStream output;
         private FileGui gui;
         private JButton enter, readf, openf;
         private Record rcrd;
         private ObjectInputStream input;
         boolean eof;
         LinkedList link = new LinkedList();
         ListIterator li=link.listIterator();
         public CreateFile()
              super( "Creating sequential file" );
              getContentPane().setLayout( new BorderLayout() );
              gui = new FileGui();
              enter = gui.getTask1();
              enter.setText("Enter");
              enter.setEnabled(true);
              enter.addActionListener(
                        new ActionListener()
                             public void actionPerformed( ActionEvent e )
                                  addRecord1();
              addWindowListener(
                        new WindowAdapter()
                             public void windowClosing( WindowEvent e )
                                  if(output != null)
                                       closeFile();
                                  else
                                       System.exit(0);
              openf = gui.getTask2();
              openf.setText("Open");
              openf.addActionListener(
                        new ActionListener()
                             public void actionPerformed(ActionEvent e)
                                  openFile();
    readf = gui.getTask3();
              readf.setText("Read Next");
              readf.addActionListener(
                        new ActionListener()
                             public void actionPerformed(ActionEvent e)
                                  readFile();
              getContentPane().add(gui, BorderLayout.CENTER);
              setSize(300,200);
              show();
         private void readFile()
                        try
                             rcrd=(Record)input.readObject();
                             String val[]={String.valueOf(rcrd.getId()),rcrd.getName(),rcrd.getAddr()};
                             gui.setFieldValues(val);
                        catch(EOFException eof)
                             System.out.print("EOFException");
                        catch(ClassNotFoundException cnfe)
                             System.out.print("ClassNotFoundException");
                        catch(IOException ioe)
                             System.out.print("IOException");
         private void openFile()
                   JFileChooser fileChooser = new JFileChooser();
                   fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                   int result = fileChooser.showOpenDialog(this);
                   if(result==JFileChooser.CANCEL_OPTION)
                        return;
                   File fileName = fileChooser.getSelectedFile();
                   if(fileName==null || fileName.getName().equals(""))
                        JOptionPane.showMessageDialog(this, "Invalid file name", "Invalid file name", JOptionPane.ERROR_MESSAGE);
                   else
                        try
                             //File fileName=new File("c:/file.txt");
                             input=new ObjectInputStream(new FileInputStream("c:/file.dat"));
                             openf.setEnabled(false);
                             readf.setEnabled(true);
                   catch (Exception e)
                        System.out.println("Error in opening file");
         private void closeFile()
              try
                   output.close();
                   System.exit(0);
              catch(IOException ex)
                   JOptionPane.showMessageDialog(this, "Error Closing File", "Error", JOptionPane.ERROR_MESSAGE);
                   System.exit(1);
         private void addRecord1()
              String[] fieldValues = gui.getFieldValues();
              if(! fieldValues[0].equals(""))
                   try
                        int id=Integer.parseInt(fieldValues[0]);
                        if(id>0)
                             Record rcrd = new Record(id, fieldValues[1], fieldValues[2]);
                             System.out.println(" " +rcrd.getString());
                             link.add(" " +rcrd.getString());
                             //System.out.println("Hello3");
                             FileOutputStream fos = new FileOutputStream("c:/file.dat",true);
                             output = new ObjectOutputStream(fos);
                             output.writeObject(rcrd);
                             output.flush();
                             //gui.clearFields();
                             readf.setEnabled(true);
                   catch (NumberFormatException nfe)
                        JOptionPane.showMessageDialog(this, "Incorrect id", "Invalid number formate", JOptionPane.ERROR_MESSAGE);
                   catch (IOException io)
                        closeFile();
         public static void main(String args[])
              new CreateFile();
    }

  • Strip audio from video and stream

    Hi. We have the Flash Media Interactive Serve 3.5. Is there an automated way to strip the audio from video files and stream on FMIS? Thanks.

    Thanks for your reply. I believe we'll be broadcasting to a single channel.

  • How can I tell if and how a SWF  file is streaming?

    My department is new to Flash, but we've now been creating
    basic Flash Videos for websites for a few months. We've always
    encoded our videos to FLVs (Flash 8), and then used the Video
    Import Wizard in Flash 8 to import those FLVs into our FLA
    document. We now need to be able to error-check all of our files
    (each video comprised of four files: an HTML file, an FLV file, and
    two SWF files including the player skin) to make sure that
    progressive videos are indeed progressive and streaming videos are
    streaming.
    My process thus far:
    In Flash 8, I brought up the SWF file and opened the Output
    window; from the Debug menu I then selected variables. I was able
    to find the variable "isRTMP:false", which according to the
    documentation seems to mean that the video is progressive, not
    streaming. However, when I authored this FLA file, I know I chose
    the streaming option (FVSS not FCS) in the Video Import Wizard. Am
    I looking in the wrong place? Am I confused about the meaning of
    this variable?
    Bottom line, how do I determine after authoring whether an
    SWF is streaming or progressive, and moreover whether it's been
    authored to use FVSS or FCS?

    I'm sorry, perhaps I was a little unclear. The files are all
    still stored herelocally, since they have not yet been deployed.
    I'm looking for some property of the SWF file (maybe visible
    through Component Inspector?) that will tell me how it has been
    authored. Is there any place in the SWF file itself that contains
    this information (since the files are not yet deployed)?

  • Unable to stream SMIL files unless the html page, swf file and the smil ffile are on the FMS server.

    When I place the .swf, smil and http files on the FMS server the SMIL stream test sample works fine
    But When I move the files to my web server I get Connection error.
    This is the same issue discussed in http://forums.adobe.com/thread/554107
    I added a ‘base’ variable but it did not work for me.
    The SMIL file has the correct path to the sample files and FMS server
         <meta base="rtmp://200.200.200.23/vod/" />
    I am able to stream files from my html file on my webserver not the FMS server by pointing to the FMS server at rtmp://200.200.200.23/vod/mp4:sample1_1500kbps.f4v
    Is this a domain security setting? If so, where do I change it?
    If not How do I get FMS to stream SMIL files without installing a webserver with FMS?
    Thanks,

    Hi,
    I think there is bug with that videoPlayer.swf which is used by index.html of webroot folder of FMS to play media files, its not able to parse smil file correctly. I used some other player and used the smil file and kept it on http server other than fms server so it was able to dynamically stream videos. So I would suggest you to create your own player which uses smil file. You can take help from the below link to create player:
    http://www.adobe.com/devnet/flashmediaserver/articles/dynstream_advanced_pt1_05.html
    Regards,
    Amit

  • Best way to stream lots of data to file and post process it

    Hello,
    I am trying to do something that seems like it should be quite simple but am having some difficulty figuring out how to do it.  I am running a test that has over 100 channels of mixed sensor data.  The test will run for several days or longer at a time and I need to log/stream data at about 4Hz while the test is running.  The data I need to log is a mixture of different data types that include a time stamp, several integer values (both 32 and 64 bit), and a lot of floating point values.  I would like to write the data to file in a very compressed format because the test is scheduled to run for over a year (stopping every few days) and the data files can get quite large.  I currently have a solution that simply bundles all the date into a cluster then writes/streams the cluster to a binary file as the test runs.  This approach works fine but involves some post processing to convert the data into a format, typically a text file, that can be worked with in programs like Excel or DIAdem.   After the files are converted into a text file they are, no surprise, a lot larger than (about 3 times) the original binary file size.
    I am considering several options to improve my current process.  The first option is writing the data directly to a tdms file which would allow me to quicly import the data into DIAdem (or Excel with a plugin) for processing/visualization.   The challenge I am having (note, this is my first experience working with tdms files and I have a lot to learn) is that I can not find a simple way to write/stream all the different data types into one tdms file and keep each scan of data (containing different data types) tied to one time stamp.  Each time I write data to file, I would like the write to contain a time stamp in column 1, integer values in columns 2 through 5, and floating point values in the remaining columns (about 90 of them).  Yes, I know there are no columns in binary files but this is how I would like the data to appear when I import it into DIAdem or Excel.  
    The other option I am considering is just writing a custom data plugin for DIAdem that would allow me to import the binary files that I am currently creating directly into DIAdem.  If someone could provide me with some suggestions as to what option would be the best I would appreciate it.  Or, if there is a better option that I have not mentioned feel free to recommend it.  Thanks in advance for your help.

    Hello,
    Here is a simple example, of course here I only create one value per iteration in the while loop for simplicity. You can also set properties of the file which can be useful, and set up different channels.
    Beside, you can use multiple groups to have more flexibility in data storage. You can think of channels like columns, and groups as sheets in Excel, so you see this way your data when you import the tdms file into Excel.
    I hope it helps, of course there are much more advanced features with TDMS files, read the help docs!

  • Simultaneous Recording in file and  playing incoming rtp stream

    I want to Simultaneous Recording in file and  playing incoming rtp stream.I have cloned the data source. After cloning I created two data sinks and two processors.One processor/datasink is meant for recording the stream in a file and other processor/data sink is used to play the rtp through speaker.
    But at a time I am only able to achieve one operation i.e either recording or playing.For recording into the wav file I have to put Thread.sleep(30) so that I can record the rtp into the file.During this time I am not able to play the audio through speaker.I also create separate thread but this does not help.
    Please give suggestion on how to resolve this issue.

    thanks for the reply, but I think I've already solved the problem.

  • Upload file and link to sales order in SAP via rfc (C#)

    Hello all,
    In my company we have the possibility to attach files to sales orders, e.g. pdf files with the printing details.
    These files are added by the GUI user, this works fine.
    Now we have an extra order creation stream in which a pdf file has to be added to the SO without user interaction.
    In a previous question I had a little question about the linking, that has been solved, I will post the test program later.
    I now can link front end files (pdf's in this case) to the sales orders and it works fine.
    Now we are developing a frontend in C# (build by a third party) which creates a sales order via a RFC. We also want that RFC to include the PDF file and link it to the created order.
    In the interface of the RFC I included a table with 255 char lines. That is the same as in the example program. the problem is that our partner is yet unable to fill the interface in exact the same way as the example program does, so the linked pdf file is corrupted.
    Does anyone have hints how C# should fill the interface table, or how I can change the interface?
    code snippid table declaration for pdf table:
    IT_PDF     LIKE     ZETEX_TAB_PDF
    and
    structure ZETEX_TAB_PDF consists of
    LINE     CHAR255
    the sample program (see other topic on where I got it)
    REPORT  zzfb_brc LINE-SIZE 260.
    * Report  Z_RMTIWARI_ATTACH_DOC_TO_BO
    * Written By : Ram Manohar Tiwari
    * Function   : We need to maintain links between Business Object and
    *              the attachment.Attachment document is basiclally a
    *              business object of type 'MESSAGE'.In order to maintain
    *              links, first the attachment will be crated as Business
    *              Object of type 'MESSAGE' using Message.Create method.
    *              Need to check if we can also use FM
    *              'SO_DOC_INSERT_WITH_ORIG_API1' or SO_OBJECT_INSERT rather
    *              than using Message.Create method.
    * I took this program and removed all the parts for adding URL's and
    * notes.
    * Include for BO macros
    INCLUDE : <cntn01>.
    * Load class.
    CLASS cl_binary_relation DEFINITION LOAD.
    CLASS cl_obl_object      DEFINITION LOAD.
    PARAMETERS:
    *  Object_a
       p_botype LIKE obl_s_pbor-typeid DEFAULT 'BUS2032',    "SO
       p_bo_id  LIKE obl_s_pbor-instid DEFAULT '0000757830', "example number
    *  Object_b
       p_docty  LIKE obl_s_pbor-typeid DEFAULT 'MESSAGE' NO-DISPLAY,
       p_msgtyp LIKE sofm-doctp        DEFAULT 'EXT'     NO-DISPLAY,
    *  Relationship
       p_reltyp  LIKE mdoblrel-reltype DEFAULT 'ATTA'.
    TYPES: BEGIN OF ty_message_key,
            foltp     TYPE so_fol_tp,
            folyr     TYPE so_fol_yr,
            folno     TYPE so_fol_no,
            doctp     TYPE so_doc_tp,
            docyr     TYPE so_doc_yr,
            docno     TYPE so_doc_no,
            fortp     TYPE so_for_tp,
            foryr     TYPE so_for_yr,
            forno     TYPE so_for_no,
           END OF ty_message_key.
    DATA : lv_message_key TYPE ty_message_key.
    DATA : lo_message TYPE swc_object.
    DATA : lt_doc_content TYPE STANDARD TABLE OF soli-line,
           ls_doc_content TYPE soli-line.
    * Create an initial instance of BO 'MESSAGE' - to call the
    * instance-independent method 'Create'.
    swc_create_object lo_message 'MESSAGE' lv_message_key.
    * Upload the pdf file, for now from the frontend, in the future from
    * the server.
    DATA:
    *  dsn(40) TYPE C VALUE '/usr/sap/trans/convert/1.pdf', "server location
    l_lines TYPE i. "filelenght
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename   = 'c:tsimple.pdf'
        filetype   = 'BIN'
      IMPORTING
        filelength = l_lines
      TABLES
        data_tab   = lt_doc_content.
    * no exceptions, the file is there in this example
    clear l_lines.
    loop at lt_doc_content into ls_doc_content.
    l_lines = l_lines + 255.
    endloop.
    compute l_lines =   l_lines
                      + STRLEN( ls_doc_content ).
    ** the coding for the server input, for later
    *OPEN DATASET dsn FOR INPUT IN BINARY MODE.
    *IF sy-subrc <> 0.
    *  EXIT.
    *ENDIF.
    *READ DATASET dsn INTO ls_doc_content.
    *WHILE sy-subrc EQ 0.
    *  APPEND ls_doc_content TO lt_doc_content.
    *  READ DATASET dsn INTO ls_doc_content.
    *ENDWHILE.
    *CLEAR ls_doc_content.
    *CLOSE DATASET dsn.
    * define container to pass the parameter values to the method call
    * in next step.
    swc_container lt_message_container.
    * Populate container with parameters for method
    swc_set_element lt_message_container 'DOCUMENTTITLE' 'Some title'.
    swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.
    swc_set_element lt_message_container 'NO_DIALOG'     'X'.
    swc_set_element lt_message_container 'DOCUMENTNAME' p_docty.
    swc_set_element lt_message_container 'DOCUMENTTYPE' 'PDF'.
    swc_set_element lt_message_container 'DocumentSize'    l_lines.
    swc_set_element lt_message_container 'DocumentContent' lt_doc_content.
    swc_call_method lo_message 'CREATE' lt_message_container.
    * Refresh to get the reference of create 'MESSAGE' object for attachment
    swc_refresh_object lo_message.
    * Get Key of new object
    swc_get_object_key lo_message lv_message_key.
    * Now we have attachment as a business object instance. We can now
    * attach it to our main business object instance.
    * Create main BO object_a
    DATA: lo_is_object_a TYPE sibflporb.
    lo_is_object_a-instid = p_bo_id.
    lo_is_object_a-typeid = p_botype.
    lo_is_object_a-catid  = 'BO'.
    * Create attachment BO object_b
    DATA: lo_is_object_b TYPE sibflporb.
    lo_is_object_b-instid = lv_message_key.
    lo_is_object_b-typeid = p_docty.
    lo_is_object_b-catid  = 'BO'.
    *TRY.
    CALL METHOD cl_binary_relation=>create_link
      EXPORTING
        is_object_a = lo_is_object_a
        is_object_b = lo_is_object_b
        ip_reltype  = p_reltyp.
    * Check if everything OK...who cares!!
    COMMIT WORK.

    I woudl suggest you check ORDERS05 IDOC type (ORDCHG message type).
    FM - idoc_input_ordchg

  • How to encypt a .txt file and how to decrypt a same .txt file when i need

    My requirement is i want to encrypt a .txt file and
    keep it in some folder. In that file we put database connection
    information. when ever we need that file we have to access it and decrypt
    it. with that decrypted values we have make connection with database.
    i am sending a code in which i wrote both encyption and decrytion in same file, but i want to do it separately.
    Please help me regarding this.
    package com.businessobjects;
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    public class EncryptDecrypt
         public static void EncodeIt()
              try
              // generate Cipher objects for encoding and decoding
              Cipher itsocipher1 = Cipher.getInstance("DES");
              Cipher itsocipher2 = Cipher.getInstance("DES");
              // generate a KeyGenerator object
              KeyGenerator KG = KeyGenerator.getInstance("DES");
              System.out.println("Using algorithm " + KG.getAlgorithm());
              // generate a DES key
              Key mykey = KG.generateKey();
              // initialize the Cipher objects
              System.out.println("Initializing ciphers...");
              itsocipher1.init(Cipher.ENCRYPT_MODE, mykey);
              itsocipher2.init(Cipher.DECRYPT_MODE, mykey);
              // creating the encrypting cipher stream
              //System.out.println("Creating the encrypting cipher stream...");
              /*FileInputStream fis = new FileInputStream("Original.txt");
    FileOutputStream fos = new FileOutputStream("Encypt.txt");
              CipherInputStream cis1 = new CipherInputStream(fis, itsocipher1);
              // creating the decrypting cipher stream
              //System.out.println("Creating the decrypting cipher stream...");
              byte[] b1 = new byte[8];
    int i1 = cis1.read(b1);
              while (i1 != -1)
                   fos.write(b1, 0, i1);
                   i1 = cis1.read(b1);
    fis.close();
    fos.close();*/
    // writing the decrypted data to output file
    FileInputStream fis1 = new FileInputStream("Encypt.txt");
    FileOutputStream fos1 = new FileOutputStream(Decypt.txt");
    CipherInputStream cis2 = new CipherInputStream(fis1, itsocipher2);
              byte[] b2 = new byte[8];
              int i2 = cis2.read(b2);
              while (i2 != -1)
                   fos1.write(b2, 0, i2);
                   i2 = cis2.read(b2);
    fis1.close();
              fos1.close();
    //cis1.close();
              cis2.close();
              catch (Exception e)
              System.out.println("Caught exception: " + e);
    With regards
    Pavankumar.

    here is the solution you wanted it
    uses password based encryption
    but your requirements are for very badly
    designed code
    This is the encryption part
    it converts the inputfile original.txt
    into the outputfile encrypt.txt which
    contains the original encrypted
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import javax.crypto.Cipher;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.PBEParameterSpec;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    public class PWBEncryption {
        // Salt
        static byte[] salt = {
            (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
            (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
        // Iteration count
        static int count = 20;
        public PWBEncryption() {
        // params:
        // password   -> the pasword used to create the key
        // inputfile  -> the file containing the stuff to be encrypted
        // i.e. original.txt
        // outputfile -> the file that will contain the encrypted stuff
        // i.e. encrypt.txt
        public static boolean doIt(char[] password,String inputfile,String outputfile){
            try{
                // Create PBE parameter set
                PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
                PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
                // create secretkey
                SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
                SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                // create cipher
                Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
                pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
                // read input
                FileInputStream fis = new FileInputStream(inputfile);
                byte[] input = new byte[fis.available()];
                fis.read(input);
                // encrypt
                byte[] output = pbeCipher.doFinal(input);
                // write encrypted output
                FileOutputStream fos = new FileOutputStream(outputfile);
                fos.write(output);
                return true;
            catch(Exception e){
                System.out.println(e.toString());
                return false;
    }This is the decrypt part
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import javax.crypto.Cipher;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.PBEParameterSpec;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    public class PWBDecryption {
        // Salt
        static byte[] salt = {
            (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
            (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
        // Iteration count
        static int count = 20;
        public PWBDecryption() {
        // params:
        // password   -> the pasword used to create the key
        // inputfile  -> the file containing the decrypted data
        // i.e. encrypt.txt
        // outputfile -> the file that will contain the decrypted data
        // i.e. decrypt.txt
        public static boolean doIt(char[] password,String inputfile,String outputfile){
            try{
                // Create PBE parameter set
                PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
                PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
                // create secretkey
                SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
                SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                // create cipher
                Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
                pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
                // read input
                FileInputStream fis = new FileInputStream(inputfile);
                byte[] input = new byte[fis.available()];
                fis.read(input);
                // encrypt
                byte[] output = pbeCipher.doFinal(input);
                // write encrypted output
                FileOutputStream fos = new FileOutputStream(outputfile);
                fos.write(output);
                return true;
            catch(Exception e){
                return false;
    }runner
    public class RunRun {
        public RunRun() {
        public static void main(String args[]){
            char password[] = {'q','w','e','r','t','y'};       
            boolean enc = PWBEncryption.doIt(password,"C:\\original.txt","c:\\encrypt.txt");
            System.out.println("Encryption status == "+enc);
            boolean dec = PWBDecryption.doIt(password,"c:\\encrypt.txt","c:\\decrypt.txt");
            System.out.println("Decryption status == "+dec);
    }

  • Find object Names in a file and print all those objects Names

    Hi All,
    I am new to this forum.
    I want to know how to read only objects names in txt file. In the text file i have sql queries, package names, Function Name. I need to read all the objects and display out put. The file contains around 20000 Lines.
    Please suggest me.
    Thanks & Regards
    Suresh.

    Gurram wrote:
    want to read .rex File. The file contains combination of SQL code with table Names, Packages,Functions,There are three basic ways to read an external file.
    You can use UTL_FILE and use standard/basic file I/O calls like fread() and fwrite() - common amongst most (if not all) programming languages.
    You can define an external table for the file, and SQL*Load the contents of the file dynamically via a SQL SELECT statement.
    You can load the file into a CLOB using DBMS_LOB and then process it - quite useful if the text file is XML as the XMLTYPE supports parsing a a CLOB containing XML.
    I want to pick Each object name put in a separate file line by line.That in turn will need to use UTL_FILE to create an external file.
    Keep in mind though that your in a database environment with PL/SQL. The very best place for data is inside the database in SQL tables. Not outside as external files. Thus you need to ask yourself whether dealing this way with external files is the best solution, and a robust and scalable one.
    Granted, many times from the database side we need to deal with external files. The optimal method usually is to load that file's data into a database table as structured data - data that can be accessed via SQL and sorted, filtered, aggregated and analysed.
    To provide a "file" as output - this should ideally be done directly from structured data (SQL tables). And can be done using HTTP (via a web enabled PL/SQL procedure that supplies the file content as a http Mime stream), using FTP (via <i>UTL_TCP</i>) or as a CLOB via a PL/SQL call interface. Using UTL_FILE is not necessarily the only option.

  • Facebook and streaming audio issues

    I like using Facebook and stream audio from my favorite radio stations!  However, I am running into adobe flash upgrade issues!!!!  I can bring up Facebook but I can't run certain programs within it.  I can bring up my favorite radio stations but won't let me stream audio!!!!  Any solutions?

    What exactly are your issues?
    I had an issue where every image found on the blog template was showing up instead of the actual image that represented the blog post. My fix was to make sure of the following:
    1. Blog image needs to be small in file size. Many bloggers post images that came straight off their camera and I found that the share tools will grab the most accessbile and light-weight files first. If the image is too big then it won't grab it at all. The share tool grabs the smallest and fastest loading, top-most in the code image first, which means the images found on the template of the blog.
    This issue occurs at WordPress too, so it is not restricted to BC but rather the tools provided to share.
    2. Try to avoid putting the image inbetween <p></p>'s, when I pulled mine out of the the paragraph format, they were found quicker.
    3. Avoid having the image lead off the blog post list before the bodypreview, if you can at all just show the image on within post detail page if you can. I know that having an image in the list helps, but then just put the whole blog in the list, like WP does. Problem here is that most share tools on the list have a problem diciphering what to share, so it shares the whole page, giving everthing a share count. WP does this better. They isolate the independent listings and provide isolated share tools for each list.
    Wait a week and the technology will change again.
    Good news is that the element that Facebook offers to share a page on the web will be featuring the option to upload an image to accompanying the sharing of the post. You can see this happening at Facebook already when you drop in the link of the post into a news feed.
    I hope this helps.

  • I have a Sony radio in my car.   With IOS  4 on my IPhone I could use the docking plug to the usb input on the radio and stream ESPN radio or pandora to the radio.  After upgrading to IOS 5 on the phone the Sony radio will not recognize the phone .  Any t

    I have a Sony radio in my car.   With IOS  4 on my IPhone I could use the docking plug to the usb input on the radio and stream ESPN radio or pandora to the radio.  After upgrading to IOS 5 on the phone the Sony radio will not recognize the phone .  Any thoughts.

    I am reading on this site about the error I am getting and it wants me to change some files that I am not comfortable messing with. Mainly because it is like a foreign language. Will the store do this for me or tell me if it is neccessary?

Maybe you are looking for

  • Digital Signatures and Certificates

    I use Adobe Profession 8, I installed a certifcate on my computer (certnew.cer) which has my informations and stuff on it.. ok so far. We have our own certificate server. When i try to apply a signature on a pdf i created, my name is not on the list

  • IWork '09 crashes opening in Lion

    Hello. I have Lion installed (10.7.2). I purchased the iwork package for my MBair and upon install I receive notice that the application has been successfull installed (from my iwork intall dvd). However, when I attempt to open any of the apps in iwo

  • IMovies 3.0.3, Can't 'text edit'.  Only 'titles' available.

    Can't do a different title for each photo?   I'm trying to do a simple slideshow of still photos.  I can enter a 'title', but it applies it to all the photos.  For an individual photo in 'Title' mode, 'Update' button is gray. Should I update iMovies?

  • Scenario mapping in QM module

    Dear Expert, As i am going to implement QM module . As i have one scenarion like below. Kindly suggecst how to map this scenario. Scenario IV: While producing finished materials some by products or waste materials are created such as water. These mat

  • NW8000 NC8000 2nd hard disk caddy (multibay)

    Hi, I'm unable to run the 2nd hard drive to Ultra DMA5 (like the main unit) The disk is UDMA5 capable but the interface work only au UDMA2. Any idea? Thank, Matteo