Out of Memory - Trying to build JTable with a .RPT file

Joined
Jun 9, 2009
Messages
2
Reaction score
0
Hi, I am trying to read data from a .RPT file, and then use that data to populate a JTable. The fields are fixed length, so I tried to read in substrings and add them to the vector data that way, but I got an out of memory exception. I also sometimes get out of bounds exceptions. The file has some empty string within it, so does anyone know how to account for those, too? Anyways, if someone notices something that can help, please let me know!

Thanks,
Shawna


Code:
import java.io.*;
import java.util.*;

import javax.swing.table.AbstractTableModel;

public class ImportOSTableModel extends AbstractTableModel
{
	protected Vector<String> data;
    protected Vector<String> columnNames;
    protected String datafile;
   
    public ImportOSTableModel(String f)
    {
        datafile = f;
        initVectors();
    }
   
    public void initVectors()
    {
        String aLine = null;
        data = new Vector<String>();
        columnNames = new Vector<String>();
        try
        {
            FileInputStream fin = new FileInputStream(datafile);
            BufferedReader br = new BufferedReader(new InputStreamReader(fin));
            //LineNumberReader lnr = new LineNumberReader(br);
            //extract column names (14 COLUMNS)
            columnNames.addElement("UPC");
            columnNames.addElement("PROD CODE");
            columnNames.addElement("SF");
            columnNames.addElement("PRODUCT DESCRIPTION");
            columnNames.addElement("CASE VEND PACK");
            columnNames.addElement("BEGINNING INVENTORY");
            columnNames.addElement("IND");
            columnNames.addElement("REPLENISH");
            columnNames.addElement("DEPLETE");
            columnNames.addElement("ENDING INVENTORY");
            columnNames.addElement("IND");
            columnNames.addElement("SHORT/(OVER)");
            columnNames.addElement("SDV-VALUE INV-VALUE");
            columnNames.addElement("COMBINED CODES");
            //get Data
            aLine = br.readLine();//to get empty line
            aLine = br.readLine();//to get empty line
            aLine = br.readLine();
            
            
            while(aLine = br.readLine() != null)
            {
            	data.addElement(aLine.substring(0,6).trim());//6 characters long
                data.addElement(aLine.substring(6,13).trim());//7 characters long
                data.addElement(aLine.substring(13,16).trim());// 3 characters long
                data.addElement(aLine.substring(16,48).trim());//32 characters long
                data.addElement(aLine.substring(48,54).trim());//6 characters long
                data.addElement(aLine.substring(54,59).trim());//5 characters
                data.addElement(aLine.substring(59,74).trim());//15 characters
                data.addElement(aLine.substring(74,78).trim());//4 characters
                data.addElement(aLine.substring(78,88).trim());//10 characters
                data.addElement(aLine.substring(88,97).trim());//9 characters
                data.addElement(aLine.substring(97,107).trim());//10 characters
                data.addElement(aLine.substring(107,110).trim());//3 characters
                data.addElement(aLine.substring(110,119).trim());//9 characters
                data.addElement(aLine.substring(119,129).trim());//10 characters
            }
            br.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
   
    public int getColumnCount()
    {
        return columnNames.size();
    }
   
    public int getRowCount()
    {
        return data.size()/getColumnCount();
    }

    public String getColumnName(int columnIndex)
    {
        String colName = "";
        if (columnIndex <= getColumnCount())
            colName = (String)columnNames.elementAt(columnIndex);
        return colName;
    }
   
    public Class getColumnClass(int columnIndex)
    {
        return String.class;
    }
   
    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
        return false;
    }
   
    public Object getValueAt(int rowIndex, int columnIndex)
    {
        return (String)data.elementAt((rowIndex*getColumnCount())+ columnIndex);
    }
   
    public void setValueAt(Object aValue, int rowIndex, int columnIndex)
    {
        return;
    }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top