Loading large files in Java Swing GUI

Hello Everyone!
I am trying to load large files(more then 70 MB of xml text) in a Java Swing GUI. I tried several approaches,
1)Byte based loading whith a loop similar to
             InputStream file_reader = new BufferedInputStream(new FileInputStream
             int BUFFER_SIZE = 4096;
             byte[] buffer = new byte[BUFFER_SIZE];
             int bytesRead;
             String line;
             while ((bytesRead = file_reader.read(buffer, 0, BUFFER_SIZE)) != -1)
                  line = new String(buffer, 0, bytesRead);
             }But this is gives me unacceptable response times for large files and runs out of Java Heap memory.
2) I read in several places that I could load only small chunks of the file at a time and when the user scrolls upwards or downwards the next/previous chunk is loaded , to achieve this I am guessing extensive manipulation for the ScrollBar in the JScrollPane will be needed or adding an external JScrollBar perhaps? Can anyone provide sample code for that approach? (Putting in mind that I am writting code for an editor so I will be needing to interact via clicks and mouse wheel roatation and keyboard buttons and so on...)
If anyone can help me, post sample code or point me to useful links that deal with this issue or with writting code for editors in general I would be very grateful.
Thank you in advance.

I'm replying to your question from another thread.
To handle large files I used the new IO libary. I'm trying to remember off the top of my head but the classes involved were the RandomAccessFile, FileChannel and MappedByteBuffer. The MappedByteBuffer was the best way for me to read and write to the file.
When opening the file I had to scan through the contents of the file using a swing worker thread and progress monitor. Whilst doing this I indexed the file into managable chunks. I also created a cache to further optimise file access.
In all it worked really well and I was suprised by the performance of the new IO libraries. I remember loading 1GB files and whilst having to wait a few seconds to perform the indexing you wouldn't know that the data for the JList was being retrieved from a file whilst the application was running.
Good Luck,

Similar Messages

  • Viewing and printing a PDF file from Java Swing Application

    I need to view and print PDF files from Java Swing Application.How do I do that?I appreciate your help.
    Thank you
    Sumana Somareddy

    If you have a link to the URL pointing to the PDF file, you can allow the browser to open it. Then use the print function of the browser to print the PDF document.

  • How to convert oracle form fmb file to java swing file using Jdeveloper

    how to convert oracle form fmb file to java swing file using Jdeveloper.Please explain with detailes steps if possible or please give a link where it is available
    Message was edited by:

    There is no automatic way to do this in JDeveloper. I know there are some Oracle Partners offering forms to java conversion, I don't know how much of their tools are automated and done with JDeveloper. With JDeveloper+ADF you basically rewriting the Forms application from scratch (and using ADF is helpful during this process).

  • How to run Java Swing GUI on embedded ARM Linux platform?

    The object is:
    A touch panel, running Java Swing GUI, with a 25 fps 320x320 mono JPEG image animation and other control buttons.
    What I have now:
    A Developing Board with: ARM926 CPU at 266MHz, 128M RAM, 64M ROM, ported with arm-linux and MiniGUI.
    My plan is:
    1. installing a X-window system to the platform, discarding the MiniGUI.
    2. install j2re-1.3.1-RC1-linux-arm.tar.bz2 to the platform.
    3. run my program developed on a PC.
    My concerns are:
    1. Both X and Java is resource consuming, can a 266MHz ARM CPU meet my requirement?
    2. Is the X a must to run Java Swing GUI? If yes, how can I configure it to minimize the footprint, I mean, install only necessary modules.
    3. Can J2RE 1.3.1, the only port for arm linux, support Swing classes?
    4. Are there other options, such as CDC + PP(AGUI?), how to do it?
    Thanks alot!

    3. Can J2RE 1.3.1, the only port for arm linux, support Swing classes?I'm not entirely sure from your post: is this a J2SE port? If so it will support Swing, but probably needs Qt.

  • How to connect autocad file to java swing

    plz immediately tell me how to connect autocad file to java swing .
    plz help me
    it is very urgent

    Hi there
    See if the link below helps you out.
    Click here to view
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Java Swing GUI Button Image

    Hi, I really need help with this one, I have tried many things and looked at many pages for this but to no avail as of yet.
    I have a Swing GUI in which I want to display an image. The way I am displaying it at the moment is as a button icon as I do not need to be able to alter the images. I can also use the button functionality as displaying something when the image is clicked. So I have an array of image paths which are accesed to load an image into the button and a "Next" button to change the image as required.
    My problem is that when I load an image into the button it moves from it's original location. When there is no image displayed the button is where I want it to be, but when I load an image it moves, this cannot happen. Any ideas.
    Also, when I am trying to click thru the array of images, it starts at the 1st image in the array but then skips to the last image in the array. Here is the code for that.
    // Handle events that arise from the "Next" button being clicked
    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
    if (jComboBox1.getSelectedIndex() == 1)
         for (int i = 1; i < juniorImageIndex.length; i++)
         jButton8.setIcon(new javax.swing.ImageIcon(juniorImageIndex));
    else if (jComboBox1.getSelectedIndex() == 2)
         for (int i = 1; i < seniorImageIndex.length; i++)
         jButton8.setIcon(new javax.swing.ImageIcon(seniorImageIndex[i]));
    juniorImageIndex and seniorImageIndex are obviuosly the arrrays with the file paths for the images. The reason I start at index 1 is that I use the 0 index image as the starting image for each part.
    Any help gratefully appreciated, I really hope someone can help, Thanks.

    // Handle events that arise from the "Next" button
    being clicked
    private void
    jButton5MouseClicked(java.awt.event.MouseEvent evt) {
      myImageIndex =(myImageIndex + 1) % imageArray.size();
    private void resetButtonImage() {
    if (jComboBox1.getSelectedIndex() == 1)
    {//take this out
    //> for (int i = 1; i < juniorImageIndex.length; i++)
    //> {
    jButton8.setIcon(new//> javax.swing.ImageIcon(array[myImageIndex]));
    //> }
    else if (jComboBox1.getSelectedIndex() == 2)
    {//this too
    //> for (int i = 1; i < seniorImageIndex.length; i++)
    //> {
    javax.swing.ImageIcon(array2[myImageIndex]));//> }

  • How to play flash files in java swings

    Hi All ,
    I have a requirement in java swings , i want to play advertisements ( flash files in swings )
    can any one provide any example for the above requirement .
    Thank you all for sharing knowledge in this great forum .

    I have a java desktop application which is actually a
    kiosk application. I have to run some promotion
    videos in my application when no user is using the
    kiosk.Will the kiosks all be running the same OS?
    The reason I ask is that JMF is available in both
    standard and performance pack versions. The PP
    provides a wider variety of formats, but runs only
    on Win. and *nix.
    videos can be any avi or neother which can easily be
    played in java applications.That is handy. The JMF standard pack provides
    support for a number of flavors of AVI, but not all.
    What is the best way for me to play video files in a
    java application??I would suggest checking if the 'standard' version
    of the JMF can play* the current AVI's. If it can, use
    the standard JMF for the project, if not, look to
    converting the AVI's to something the JMF can
    deal with, this might involve storing the video or
    audio of the AVI's in a different format - you
    might have to experiment to get the right
    combination, but the JMF 'supported formats'
    is a good guide.
    * To check if JMF can play them, install it and
    try loading the AVI's in JMStudio - the default

  • How to convert a .jad file to .class file in JAVA Swings.

    Hi all,
    Sorry for the interruption.I am also facing the same problem.I am using DEJDecompiler.But my application is not J2ME But J2EE.( a Swing application).I opened .class file and made some changes but I dont know how to convert into a .class file again.
    I tried saving .jad file to .java file.Then it is showing lot of errors in Eclipse Platform.I doubt if there are any errors in the .class file already,then how could the program would run.I put all the programs in the respective platforms only and then testing.It fails.
    (2) one more question,is if I do not need to disturb any existing coding and need to create a seperate java file which will do my customisation,then what should I do.I could not get any interfaces in the program.
    Please help me as the matter is most urgent.
    Thanks in advance
    With regds

    I tried saving .jad file to .java file.Then it is
    showing lot of errors in Eclipse Platform.I doubt if
    there are any errors in the .class file already,then
    how could the program would run.I put all the programs
    in the respective platforms only and then testing.It
    fails.So who's Java program/library are you trying to steal?
    (2) one more question,is if I do not need to disturb
    any existing coding and need to create a seperate java
    file which will do my customisation,then what should I
    do.I could not get any interfaces in the program.
    Please help me as the matter is most urgent.Wow, you urgently need to steal someones program/library. The best person to give you advice urgently is the owner of the program/library you are trying to steal.
    Thanks in advancePlease don't thank me because I'm not going to help you!
    With regds

  • 4.2.3/.4 Data load wizard - slow when loading large files

    I am using the data load wizard to load csv files into an existing table. It works fine with small files up to a few thousand rows. When loading 20k rows or more the loading process becomes very slow. The table has a single numeric column for primary key.
    The primary key is declared at "shared components" -> logic -> "data load tables" and is recognized as "pk(number)" with "case sensitve" set to "No".
    While loading data, these configuration leads to the execution of the following query for each row:
    select 1 from "KLAUS"."PD_IF_CSV_ROW" where upper("PK") = upper(:uk_1)
    which can be found in the v$sql view while loading.
    It makes the loading process slow, because of the upper function no index can be used.
    It seems that the setting of "case sensitive" is not evaluated.
    Dropping the numeric index for the primary key and using a function based index does not help.
    Explain plan shows an implicit "to_char" conversion:
    This is missing in the query but maybe it is necessary for the function based index to work.
    Please provide a solution or workaround for the data load wizard to work with large files in an acceptable amount of time.
    Best regards

    Nevertheless, a bulk loading process is what I really like to have as part of the wizard.
    If all of the CSV files are identical:
    use the Excel2Collection plugin ( - Process Type Plugin - EXCEL2COLLECTIONS )
    create a VIEW on the collection (makes it easier elsewhere)
    create a procedure (in a Package) to bulk process it.
    The most important thing is to have, somewhere in the Package (ie your code that is not part of APEX), information that clearly states which columns in the Collection map to which columns in the table, view, and the variables (APEX_APPLICATION.g_fxx()) used for Tabular Forms.

  • How to Update existing XML File Using Java Swing

    I am reading XML file and getting keywords into JList. When i add some keywords into JList through textfield and remove keywords JList, then after click on save button it should update xml file. How can i do it ?
    Please provide me some code tips for updating xml file
    This is the code that i am using for reading XML File:
    import javax.swing.*;
    import java.awt.event.*;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    import java.io.IOException;
    import java.util.*;
    import java.text.Collator;
    import java.util.regex.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import com.cloudgarden.layout.AnchorConstraint;
    import com.cloudgarden.layout.AnchorLayout;
    public class getKeywords extends JFrame implements ActionListener
    static JPanel p;
    static JLabel lbl;
    static JButton btnSave,btnAdd,btnRemove;
    static String path;
    static Vector v;
    static JList lstCur;
    static JTextField txtKey;
    Document dom;
    static image imgval;
    NodeList nodelstImage;
    static AnchorLayout anchorLay;
    private DefaultListModel lstCurModel;
    public getKeywords()
         super("Current Keywords");
        v=new Vector();
        p=new JPanel();
        txtKey=new JTextField(10);
        btnAdd=new JButton("Add");
        btnRemove=new JButton("Remove");
        btnSave=new JButton("Save");
        lbl=new JLabel("Current Keywords");
        lstCurModel=new DefaultListModel();
            lstCur=new JList();
            JScrollPane scr=new JScrollPane(lstCur);
    public static void main(String arg[])
         getKeywords g=new getKeywords();
    public void actionPerformed(ActionEvent ae)
              //Code to Write
         public void runExample()
              //Parse the XML file and get the DOM object
              //Get the Detail of the Image Document
              //Get the Detail of the LML Document
         public void ParseXMLFile()
              //Get the Factory
              DocumentBuilderFactory builderFac = DocumentBuilderFactory.newInstance();
                   //Using factory get an instance of the Document Builder
                   DocumentBuilder builder = builderFac.newDocumentBuilder();
                   //parse using builder to get DOM representation of the XML file
                   dom = builder.parse("LML.xml");
              catch(ParserConfigurationException pce)
              catch(SAXException sax)
              catch(IOException ioex)
         public void parseImageDocument()
              //Get the root element
              Element docImgEle = dom.getDocumentElement();
              //Get a nodelist for <Image> Element
              nodelstImage =  docImgEle.getElementsByTagName("Image");
              if(nodelstImage != null && nodelstImage.getLength() > 0)
                   for(int i = 0; i < nodelstImage.getLength(); i++)
                        //Get the LML elements
                        Element el = (Element)nodelstImage.item(i);
                        //Get the LML object
                        getImage myImgval = new getImage();
                        imgval = myImgval.getimage(el);
                        v.addElement(new String(imgval.Thumb));
                        String[] x = Pattern.compile(",").split(imgval.Keys);
                        for (int s=0; s<x.length; s++)
    }     Thanks

    You should update your DOM document to represent the changes that you want made.
    Then, using the Transformation API you simply transform your document onto a stream representing your file. Something like this:
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    // TODO - set indentation amount!
    Source source = new DOMSource(dom);
    Result result = new StreamResult(file);
    transformer.transform(source, result);Hope this helps.

  • Flash media server taking forever to load large files

    We purchased FMIS and we are encoding large 15+ hour MP4 recordings using flash media encoder. When opening these large files for playback, which have not been opened recently  the player displays the loading indicator for up to 4 minutes! Once it has apparently been cached on the server it opens immediately from any browser even after clearing local browser cache. So a few questions for the experts
    1. Why is it taking so long to load the file. Is it because the MP4 metadata is in the wrong format and the file is so huge? I read somewhere that Media Encoder records with incorrect MP4 metadata is that still the case?
    2. Once its cached on the server, exactly how much of it is cached. Some of these files are larger than 500mb.
    3. What fms settings do you suggest I change. FMIS is running on windows server R2 64 bit, but FMIS itself is 32 bit. We have not upgraded to the 64 bit version. We have 8GB of ram. Is it OK to set FMS cache to 3GB. And would that only have enough room for 3-4 large files, because we have hundreds of them.
    Lead programmer, solid state logic inc

    Hi Tuviah,
    You may want to email me offline about more questions here as it can get a little specific but I'll hit the general problems here.
    MP4 is a fine format, and I won't speak ill of it, but it does have weaknesses.  In FMS implementation those weaknesses tend to manifest around the combination of recording and very large files, so some of these things are a known issue.
    The problem is that MP4 recording is achieved through what's called MP4 fragmentation.  It's a part of the MP4 spec that not every vendor supports, but has a very particular purpose, namely the ability to continually grow an MP4 style file efficiently.  Without fragments one has the problem that a large file must be constantly rewritten as a whole for updating the MOOV box (index of files) - fragments allow simple appending.  In other words it's tricky to make mp4 recording scalable (like for a server ) and still have the basic MP4 format - so fragments.
    There's a tradeoff to this however, in that the index of the file is broken up over the whole file.  Also likely these large files are tucked away on a NAS for you or something similar.  Normal as you likely can't store all of them locally.  However that has the bad combo of needing to index the file (touching parts of the whole thing) and doing network reads to do it.  This is likely the cause of the long delay you're facing - here are some things you can do to help.
    1. Post process the F4V/MP4 files into non fragmented format - this may help significantly in load time, though it could still be considered slow it should increase in speed.  Cheap to try it out on a few files. (F4V and MP4 are the same thing for this purpose - so don't worry about the tool naming)
    2. Alternatively this is why we created the raw: format.  For long recording mp4 is just unideal and raw format solves many of the problems involved in doing this kind of recording.  Check it out
    http://help.adobe.com/en_US/flashmediaserver/devguide/WSecdb3a64785bec8751534fae12a16ad027 7-8000.html
    3. You may also want to check out FMS HTTP Dynamic Streaming - it also solves this problem, along with others like content protection and DVR and it's our most recent offering in tech, so it has a lot of strengths the other areas don't.
    Hope that helps,

  • (urgent) SQL*Loader Large file support in O734

    hi there,
    i have the following sqlloader error when trying to upload data file(s),
    each has size 10G - 20G to Oracle 734 DB on SunOS 5.6 .
    SQL*Loader-500: Unable to open file (..... /tstt.dat)
    SVR4 Error: 79: Value too large for defined data type
    i know there's bug fix for large file support in Oracle 8 -
    Oracle supports files over 2GB for the oracle executable.
    Contact Worldwide Support for information about fixes for bug 508304,
    which will add large file support for imp, exp, and sqlldr
    however, really want to know if any fix for Oracle 734 ?

    Control file
    C:\DOCUME~1\MAMOHI~1>type dept.ctl
    load data
    infile dept.dat
    into table dept
    fields terminated by ',' optionally enclosed by '"'
    trailing nullcols
    (deptno integer external,
    dname char,
    loc char)
    Data file
    C:\DOCUME~1\MAMOHI~1>type dept.dat
    C:\DOCUME~1\MAMOHI~1>dir dept.*
    Volume in drive C has no label.
    Volume Serial Number is 9CCC-A1AF
    Directory of C:\DOCUME~1\MAMOHI~1
    09/21/2006  08:33 AM               177 dept.ctl
    04/05/2007  12:17 PM                41 dept.dat
                   2 File(s)          8,043 bytes
                   0 Dir(s)   1,165 bytes free
    Intelligent sqlldr command
    C:\DOCUME~1\MAMOHI~1>sqlldr userid=hary/hary control=dept.ctl
    SQL*Loader: Release - Production on Thu Apr 5 12:18:26 2007
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 2
    C:\DOCUME~1\MAMOHI~1>sqlplus hary/hary
    SQL*Plus: Release - Production on Thu Apr 5 12:18:37 2007
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release - Production
    With the Partitioning, OLAP and Data Mining options
    As I am appending I got two extra rows. One department in your district and another in my district :)
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
            50 IT             VIKARABAD
            60 INVENTORY      NIZAMABAD
    6 rows selected.

  • How to store grid points in a file using Java Swing?

    Please someone help me with any suggestions about how to store the grid points in a file using Java Swing

    Actually i have designed a gridlayout in Java Swing and have added some components to it such as buttons or images....My problem is when I click on any of the cell of the grid,the corresponding cell number should be stored in an external file....Do u have any suggestions on how to do it?

  • Problem unzipping larger files with Java

    When I extract small zip files with java it works fine. If I extract large zip files I get errors. Can anyone help me out please?
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import java.util.zip.*;
    public class  updategrabtest
         public static String filename = "";
         //public static String filesave = "";
        public static boolean DLtest = false, DBtest = false;
         // update
         public static void main(String[] args)
              System.out.println("Downloading small zip");
              download("small.zip"); // a few k
              System.out.println("Extracting small zip");
              System.out.println("Downloading large zip");
              download("large.zip"); // 1 meg
              System.out.println("Extracting large zip");
              // update database
              boolean maindb = false; //database wasnt updated
         // download
         public static void download (String filesave)
                   java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
                   java.net.URL("http://saveourmacs.com/update/" + filesave).openStream());
                   java.io.FileOutputStream fos = new java.io.FileOutputStream(filesave);
                   java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
                   byte data[] = new byte[1024];
              catch (Exception e)
                   System.out.println ("Error writing to file");
         // extract
         public static void extract(String filez)
              filename = filez;
                updategrab list = new updategrab( );
            catch (Exception e)
         // extract (part 2)
        public static void getZipFiles()
                //String destinationname = ".\\temp\\";
                String destinationname = ".\\";
                byte[] buf = new byte[1024]; //1k
                ZipInputStream zipinputstream = null;
                ZipEntry zipentry;
                zipinputstream = new ZipInputStream(
                    new FileInputStream(filename));
                zipentry = zipinputstream.getNextEntry();
                   while (zipentry != null)
                    //for each entry to be extracted
                    String entryName = zipentry.getName();
                    System.out.println("entryname "+entryName);
                    int n;
                    FileOutputStream fileoutputstream;
                    File newFile = new File(entryName);
                    String directory = newFile.getParent();
                    if(directory == null)
                    fileoutputstream = new FileOutputStream(
                    while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
                        fileoutputstream.write(buf, 0, n);
                    zipentry = zipinputstream.getNextEntry();
            catch (Exception e)

    In addition to the other advice, also change every instance of..
    kingryanj wrote:
              catch (Exception e)
                   System.out.println ("Error writing to file");
    catch (Exception e)
    }I am a big fan of the stacktrace.

  • When using  Vikas' program to load large files  getting error

    I am using Vikas' program to load large data files: http://htmldb.oracle.com/pls/otn/f?p=38131:1
    This works fine, except when I click on the button to create table, then I get a "not found" error--
    failed to parse SQL query:
    ORA-00942: table or view does not exist
    What might cause this? I've checked grants and such and reviewed the code, but haven't figured it out...

    I am using Vikas' program to load large data files: http://htmldb.oracle.com/pls/otn/f?p=38131:1
    This works fine, except when I click on the button to create table, then I get a "not found" error--
    failed to parse SQL query:
    ORA-00942: table or view does not exist
    What might cause this? I've checked grants and such and reviewed the code, but haven't figured it out...

Maybe you are looking for

  • Payables Open Interface Import error

    Hi all I have the following issue in EBS R12. RDBMS : Oracle Applications : 12.1.3 I'm inserting records into the AP_INVOICES_INTERFACE and AP_INVOICE_LINES_INTERFACE tables and then running the "Payables Open Interface Import" concurrent

  • Having trouble setting up right out of the box for ipad 3rd gen

    Hi, right out of he box cannot get past language set up pages will not take the defaulted english and cannot go forward, cannot continue with set up am I doing something wrong?

  • Flash 9 Key press Problem

    Using Flash 9, when running an application from the IDE, key presses of K which are supposed to do something in my app are being captured by the IDE and doing something there instead. Didn't happen in flash 8, is there a way to disable / fix this.

  • HT1222 How can you update 3.1.2 to 4.2.1 on iPhone 3g

    Want to upgrade my ios from 3.2.1 to 4.2.1 but iTunes didn't offer the upgrade. Is there something else I need to do?

  • Error message on Updates Tab

    Hi all In the app store I have a Update notifaction for Angry Birds, I do not recall downloading this App in fact I know I did not. So being curious I click to update Angry Bird and get this error message / notifaction "You have updates available for