• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read issue

 
arjun rampal
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i
have a java file which is reading from a txt file .
but it is not reading all data.it is reading some line then leaving ,then again reading ,then leaving any idea?

both files are below
1)
package com.dhl.auditdatamgr.utils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Pattern;

import com.dhl.auditdatamgr.business.DetailedFacilityAuditData;
import com.dhl.auditdatamgr.exceptions.ParserException;
import com.dhl.auditdatamgr.utils.db.DataUtil;

/**
* @author mahiseth
*
*/
public class AuditFileParser
{

/**
* Constructor
*/
protected AuditFileParser()
{
super();
}

public static List parseFile(String fileName, String regex)
throws IllegalArgumentException, FileNotFoundException, ParserException
{
DataUtil.enforceNotNullOrEmpty(fileName);
DataUtil.enforceNotNullOrEmpty(regex);

List rowList = new ArrayList();
BufferedReader br = null;
try
{
br = new BufferedReader(
new FileReader(new File(fileName)));

String line = null;
DetailedFacilityAuditData detailedAuditData = null;
Integer huExpected = null;
Integer huMissing = null;
Integer huExtra = null;
Integer shipmentExpected = null;
Integer shipmentMissing = null;
Integer shipmentExtra = null;
Integer pieceIdsExpected = null;
Integer pieceIdsMissing = null;
Integer pieceIdsExtra = null;
Pattern p = Pattern.compile(regex);

while((line = br.readLine()) != null)
{
//System.out.println("Line: " + line);
//Pattern p = Pattern.compile("[\\p{Punct}&&[|]]");

String [] lineItems = p.split(line);
if (lineItems.length != 18)
continue;
detailedAuditData = new DetailedFacilityAuditData();
System.out.println("regex="+regex);
System.out.println("line="+line);
System.out.println("lineItems.length="+lineItems.length);
DataUtil.enforceNotNullOrEmpty(lineItems[0]);
DataUtil.enforceNotNullOrEmpty(lineItems[5]);
DataUtil.enforceNotNullOrEmpty(lineItems[6]);
DataUtil.enforceNotNullOrEmpty(lineItems[3]);
detailedAuditData.setHuid(lineItems[0]);
System.out.println("Shipment gadexpected is: " + lineItems[0]);
detailedAuditData.setAuditAtServiceArea(lineItems[5]);
System.out.println("Shipment bcexpected is: " + lineItems[5]);
detailedAuditData.setAuditAtFacility(lineItems[6]);
System.out.println("Shipmentgexpected is: " + lineItems[6]);
detailedAuditData.setAuditTime(DataUtil.convertToTimestamp(lineItems[3]));
System.out.println("Shipment uexpected is: " + lineItems[3]);
detailedAuditData.setHuType(lineItems[4]);
System.out.println("Shipment expected is: " + lineItems[4]);
detailedAuditData.setBuiltAtServiceArea(lineItems[1]);
System.out.println("Shipment expected is: " + lineItems[1]);
detailedAuditData.setBuiltAtFacility(lineItems[2]);
System.out.println("Shipment expected is: " + lineItems[2]);

if(lineItems[9] != null && !lineItems[9].equals(""))
{ System.out.println("Shipment expected is: " + lineItems[9]);


huExpected = new Integer(Integer.parseInt(lineItems[9]));
detailedAuditData.setHuExpected(huExpected);
}
if(lineItems[12] != null && !lineItems[12].equals(""))
{System.out.println("Shipment expected is: " + lineItems[12]);

huMissing = new Integer(Integer.parseInt(lineItems[12]));
detailedAuditData.setHuMissing(huMissing);
}
if(lineItems[13] != null && !lineItems[13].equals(""))
{System.out.println("Shipment expected is: " + lineItems[13]);

huExtra = new Integer(Integer.parseInt(lineItems[13]));
detailedAuditData.setHuExtra(huExtra);
}
if(lineItems[7] != null && !lineItems[7].equals(""))
{
System.out.println("Shipment expected is: " + lineItems[7]);

shipmentExpected = new Integer(Integer.parseInt(lineItems[7]));
detailedAuditData.setShipmentExpected(shipmentExpected);
}
if(lineItems[10] != null && !lineItems[10].equals(""))
{System.out.println("Shipment expected is: " + lineItems[10]);

shipmentMissing = new Integer(Integer.parseInt(lineItems[10]));
detailedAuditData.setShipmentMissing(shipmentMissing);
}
if(lineItems[11] != null && !lineItems[11].equals(""))
{System.out.println("Shipment expected is: " + lineItems[11]);
shipmentExtra = new Integer(Integer.parseInt(lineItems[11]));
detailedAuditData.setShipmentExtra(shipmentExtra);
}
if(lineItems[8] != null && !lineItems[8].equals(""))
{System.out.println("Shipment expected is: " + lineItems[8]);
pieceIdsExpected = new Integer(Integer.parseInt(lineItems[8]));
detailedAuditData.setPieceIdsExpected(pieceIdsExpected);
}
if(lineItems[14] != null && !lineItems[14].equals(""))
{System.out.println("Shipment expected is: " + lineItems[14]);
pieceIdsMissing = new Integer(Integer.parseInt(lineItems[14]));
detailedAuditData.setPieceIdsMissing(pieceIdsMissing);
}
if(lineItems[15] != null && !lineItems[15].equals(""))
{System.out.println("Shipment expected is: " + lineItems[15]);
pieceIdsExtra = new Integer(Integer.parseInt(lineItems[15]));
detailedAuditData.setPieceIdsExtra(pieceIdsExtra);
}

detailedAuditData.setAuditor(lineItems[16]);
System.out.println("Shipment expected is: " + lineItems[16]);
detailedAuditData.setAuditDate(DataUtil.convertToDate(lineItems[17]));
System.out.println("Shipment zexpected is: " + lineItems[17]);

rowList.add(detailedAuditData);
}
}
catch (IOException e)
{
throw new ParserException("An error occurred while trying to read the audit data file. " ,e);
//e.printStackTrace();
} catch (ParseException e)
{
throw new ParserException("An error occurred while parsing the audit data file. " ,e);
//e.printStackTrace();
}

catch (ArrayIndexOutOfBoundsException ae)
{
throw new ParserException("A required field is missing. " ,ae);
}

finally
{
try
{
br.close();
} catch (IOException e1)
{
e1.printStackTrace();
}
}
return rowList;
}
/**
*
* @param fileName - File name or directory to be deleted
* @return true if and only if the file is successfully deleted, false otherwise
* @throws IllegalArgumentException
*/
public static boolean deleteFile(String fileName)
throws IllegalArgumentException
{
DataUtil.enforceNotNullOrEmpty(fileName);

File f = new File(fileName);
boolean deleteStatus = false;
deleteStatus = f.delete();
return deleteStatus;
}



}H543148480|VAA|VAA|2006-09-24 16:55:09|B|VAA|VAA|18|07|0|0|0|0|70|0|0|rfxml01|2006-09-24|
H543148362|AFA|AFA|2006-09-24 17:03:01|B|AFA|AFA|190|10|0|0|0|0|110|10|0|rfxml01|2006-09-24|
H480031440|AGA|AGA|2006-09-24 17:11:19|B|AGA|AGA|20|0|0|0|0|0|0|0|0|mstringa|2006-09-24|
H485077552|APA|APA|2006-09-24 17:21:33|B|APA|APA|58|0|0|0|0|0|0|0|0|lpadigli|2006-09-24|
H480995502|AQA|AQA|2006-09-24 17:22:19|B|AQA|AQA|13|0|0|10|10|0|10|01|0|mcannone|2006-09-24|
H480995476|AZA|AZA|2006-09-24 17:23:06|B|AZA|AZA|5|1|0|0|0|0|30|20|0|mcannone|2006-09-24|
H485076631|AAB|AAB|2006-09-24 17:24:29|B|AAB|AAB|38|0|0|0|0|0|0|0|0|lpadigli|2006-09-24|
H480987108|AAA|AAA|2006-09-23 06:21:30|B|AAA|AAA|0|0|0|0|0|0|0|0|0|mcannone|2006-09-23|
H480987109|AAA|AAA|2006-09-23 06:12:40|B|AAA|AAA|3|0|3|0|0|0|9|0|0|mcannone|2006-09-23|
H480987110|AAA|AAA|2006-09-23 06:23:50|B|AAA|AAA|1|0|0|0|0|0|10|0|0|mcannone|2006-09-23
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by arjun rampal:

but it is not reading all data.it is reading some line then leaving ,then again reading ,then leaving any idea?


Could you be a little more specific? For example, what exactly is the program doing and what do you expect it to do?
It is a bad idea to post a huge piece of code. We're all volunteers here and don't have time to read through long listings. As a matter of fact, one of the most basic debugging techniques is to try to pare your code down to as few lines as possible. Often you'll find an obvious problem hidden by all the other processing.
Have a look at our FAQ entries: Tell The Details and Use Code Tags
 
arjun rampal
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi joe extremely sorry

I got solution

String [] lineItems = p.split(line); to be replaced by
String [] lineItems = p.split(line.trim());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic