exception
Hi follwoing is the file.Now problem is this file is reading data from a text file which has contents as follows
Now even though I am able to print all values in file still it is giving exception .
1)exception
com.dhl.auditdatamgr.exceptions.ParserException: A required field is missing.
at com.dhl.auditdatamgr.utils.AuditFileParser.parseFile(AuditFileParser.java:161)
at com.dhl.auditdatamgr.process.AuditDataHandler.main(AuditDataHandler.java:94)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 5
at com.dhl.auditdatamgr.utils.AuditFileParser.parseFile(AuditFileParser.java:76)
... 1 more
2)file content H485061975|MIL|EPD|2005-07-01 18:29:36|B|MIL|EPD|30|0|0|0|0|0|0|0|0|fmelone|2005-07-01
3)publicclass AuditFileParser
{
/**
* Constructor
*/
protected AuditFileParser()
{
super();
}
publicstatic 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);
detailedAuditData =new DetailedFacilityAuditData();
//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 cexpected 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)
{
thrownew ParserException("An error occurred while trying to read the audit data file. " ,e);
//e.printStackTrace();
}catch (ParseException e)
{
thrownew ParserException("An error occurred while parsing the audit data file. " ,e);
//e.printStackTrace();
}
catch (ArrayIndexOutOfBoundsException ae)
{
thrownew 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
*/
publicstaticboolean deleteFile(String fileName)
throws IllegalArgumentException
{
DataUtil.enforceNotNullOrEmpty(fileName);
File f =new File(fileName);
boolean deleteStatus =false;
deleteStatus = f.delete();
return deleteStatus;
}
}
> Caused by: java.lang.ArrayIndexOutOfBoundsException:
> 5
> at
> t
> com.dhl.auditdatamgr.utils.AuditFileParser.parseFile(AuditFileParser.java:76)
Open AuditFileParser in an editor with line numbers turned on, go to line 76, and see why any array variable that you find might have an index problem.
Your split method must be returning fewer tokens in that line array than you think it should. I'd trace that through in a debugger.
I pasted your code into an editor and looked at line 76. I'm guessing that you ddidn't post the entire class, because line 76 doesn't try to access line[5].
Splitting at punctuation and | means that the line you posted will have 25 tokens, because the timestamp will be split at '-' and ':'. Is that what you intended?
%
Hi this is full class.Now there is one difference between this and previous post I have uncommented one line dataforce line{0}
so now exception also slightly chnaged to
java.lang.IllegalArgumentException: Required string is empty
at com.dhl.auditdatamgr.utils.db.DataUtil.enforceNotNullOrEmpty(DataUtil.java:81)
at com.dhl.auditdatamgr.utils.AuditFileParser.parseFile(AuditFileParser.java:75)
at com.dhl.auditdatamgr.process.AuditDataHandler.main(AuditDataHandler.java:94)
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;
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);
detailedAuditData = new DetailedFacilityAuditData();
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;
}
}
total token 18 sepearted by !
your code is telling you what's wrong. the exception looks pretty clear to me.%
but still newbie so not getting the thingsthat where things are wrong
according to me I am getting every value from file but still exception?as i am bale to print all values from file
ok duufy leaving for day.let me know where things are wrong as i am geting the values from file and able to print itregards
java.lang.IllegalArgumentException: Required string is empty
at com.dhl.auditdatamgr.utils.db.DataUtil.enforceNotNullOrEmpty(DataUtil.java:81)
at com.dhl.auditdatamgr.utils.AuditFileParser.parseFile(AuditFileParser.java:75)
at com.dhl.auditdatamgr.process.AuditDataHandler.main(AuditDataHandler.java:94)
Your own code is telling you: a required string is empty.
Line 75 of your AuditFileParser calls that DataUtil method to make sure that the value is not null or empty.
Either the input is null or empty OR the logic in the method is incorrect.
Print it out and see what the value is before you enter that method.
%
I didn't read the whole thread or your whole code, but the following code:
pieceIdsMissing = new Integer(Integer.parseInt(lineItems[14]));
would be better written as:
pieceIdsMissing = new Integer(lineItems[14]);
This goes for all such cases, obviously. There is no point in parsing the String to a primitive int, and then constructing Integer from that, when you can just pass the String directly to an Integer constructor.
MLRona at 2007-7-14 21:30:13 >

excellent point, Monica.%
> excellent point, Monica.
Thanks. This kind of stuff drove me nuts on the Java project I was on [the one I always complain about here ;-) ]. We had 'new String("literal")' everywhere, too. We even had things like 'new Integer(1).toString()' with (and without) the constant input. And 'Integer.parseInt("1")' with the literal String (as well as 'new Integer(someString).intValue()'. I'm on a C++ (yech!) project now, but haven't started coding yet.
MLRona at 2007-7-14 21:30:13 >

> > excellent point, Monica.
>
> Thanks. This kind of stuff drove me nuts on the Java
> project I was on [the one I always complain about
> here ;-) ].
They're lucky to have you to educate them.
> We had 'new String("literal")'
> everywhere, too. We even had things like 'new
> Integer(1).toString()' with (and without) the
> constant input. And 'Integer.parseInt("1")' with the
> literal String (as well as 'new
> Integer(someString).intValue()'.
Oh, my. Those must have been some fun code reviews.
I see a lot of folks write this:
ArrayList list = new ArrayList();
Instead of this:
List list = new ArrayList();
A peeve of mine. Prefer interfaces when you have a choice.
> I'm on a C++
> (yech!) project now, but haven't started coding yet.
What's wrong with C++? I used to like it. 8) Last time I wrote it was in 2001. I found that my Java had an influence on C++. I used CppUnit to good advantage and did more with exceptions than I had before I learned Java.
%
Hi those issues will be done in code review.plese let me know where things are wrongregards
See reply 8. Add some print statements so you can see what your code is doing and which of your assumptions about what it's doing are wrong.
jverda at 2007-7-14 21:30:13 >

Hi I have done my work fully but not getting at all.
i am able to print all file from the file but still error.
second thing If i commecnte lineitem0 exception changes to required filed missing caused by arrayindexoutof bounf:5
thats y i postes all files in link that post
regards
Hi I have done my work fully but not getting at all.
i am able to print all file from the file but still error.
second thing If i commecnte lineitem0 exception changes to required filed missing caused by arrayindexoutof bounf:5
thats y i postes all files in link that post
regards
smita_smita ,
You really need to learn how to do some basic problem solving on
your own. The answers to your problems are all in your error messages
and stack traces. Please put your brain to use and figure it out on your
own.
As mentioned printing out messages including sometimes variables
can help you see where things are going wrong and that assumptions
that you have made about your code are incorrect.
An array index out of bounds exception is relatively trivial problem to
solve. I feel you can solve it if you only actually tried.
I have tried and even i know that some stirng value is absent which is required but I dont know y .I am able to get the values from file and able to print all values then y this error
> not solved yetBecause you are lazy. You will have to correct the lazyness first.You have been given plenty of good advice in this thread already. Pleaseattempt to do a minimal amount of thinking for yourself.
> I have tried and even i know that some stirng value
> is absent which is required but I dont know y .I am
> able to get the values from file and able to print
> all values then y this error
Some of your assumptions are obviously incorrect!
So don't just wail and shake your fist at the sky and curse the gods. Use
the advice given previously and start printing out the values of some
of your variables. Then you will see where your assumptions are incorrect.
1- Create a data file with only ONE data line that causes the exception.
2- Modify your code with added printlns for debug:while((line = br.readLine()) != null)
{
...
String[] lineItems = p.split(line);
System.out.println("regex="+regex);
System.out.println("line="+line);
System.out.println("lineItems.length="+lineItems.length);
System.out.println("lineItems="+java.util.Arrays.toString(lineItems));
...
3- Execute your program with the one-line data file.
4- Look at the console printout.
Is it the expected results? What is different from it?
By the way simta-simta thanks for crossposting and multiposting thisexciting question across the forums like the cretin you are.
ok done here is the output except for regex=[\p{Punct}&&[|]]line=lineItems.length=1And here is the data in data text H485061976|MIL|EPD|2006-08-22 18:29:36|B|MIL|EPD|30|0|0|20|0|0|0|0|0|fmelone|2006-08-22|
Hmmm looks like the problem is... your assumptions were incorrect.What a shock.You have a second blank line in your file. Get rid of it.
I have only one line in the file which is H485061976|MIL|EPD|2006-08-22 8:29:36|B|MIL|EPD|30|0|0|20|0|0|0|0|0|fmelone|2006-08-22|
> I have only one line in the file which is > > H485061976|MIL|EPD|2006-08-22> 8:29:36|B|MIL|EPD|30|0|0|20|0|0|0|0|0|fmelone|2006-08-> 22|And it has a second blank line!Otherwise why would your line be empty? Hmmm?
i dont know whatever line my text file has I have pasted other than that nothing.
> i dont know whatever line my text file has I have
> pasted other than that nothing.
Why does the output from your own reply 24 not tell you anything?!?
Do you see that the line is blank there? What does that tell you? How can you get around this?
two ways
1) remove the blank line from your file
2) do some sort of check to see that you have enough bits after splitting the String
I understand that output for line is showing blankbut first I am able to print all the values from this file and second where is the blank line I really dont know I can post my data file on imageshak if required.its and simple text file with one line that I have pasted
I give up.
Smita-smita,
Find someone who can give you one on one in person help. You are too
inexperienced and too timid for getting help through a web forum. I don't think the language barrier is helping either.
Regardless, you can't be helped on here. Go find someone you can pay
for one on one in person help. It is the only way for you to complete this.
you are right that one empty line is coming.Because if there is only one line in data file value of line isline=H485061976|MIL|EPD|2006-08-22 18:29:36|B|MIL|EPD|30|0|0|20|0|0|0|0|0|fmelone|2006-08-22|and second time value of line =(nothing) so it is taking extra line but why
hold I got the point that it is taking extra line but why?
Go away cross-posting lazy and inept doofus.
> hold I got the point that it is taking extra line but why?
Maybe your file ends with 2 newline chars. Who knows.
You should really follow the advice (2) given in reply #29
and do some sort of validation with the line read or the split result
before processing the tokens.while ((line = br.readLine()) != null)
{
...
String[] lineItems = p.split(line);
if (lineItems.length != 18)
continue; // go to read the next line
...
Regards
hI jfbriere
Thanxs for your help.it worked finally.
I was checking with one line of data only so now no problem.
I hope there will be no problem with multiline of data also
thanxs once again.it was real great help.
and thanxs to cotton m also.
Thanxs and regards
revival of old issuewhile ((line = br.readLine()) != null){...String[] lineItems = p.split(line);if (lineItems.length != 18)continue; // go to read the next lineI am using propesed solution but it is not reading all lines
> revival of old issue
> while ((line = br.readLine()) != null)
> {
>...
> String[] lineItems = p.split(line);
>if (lineItems.length != 18)
> continue; // go to read the next line
> ropesed solution but it is not reading all lines
Then you're doing something incorectly. This will read all lines: while ((line = br.readLine()) != null) {
...
}
Without seeing more of your code or knowing how you're determining that all lines aren't being read, it's impossible to tell where the error is.
jverda at 2007-7-21 10:13:57 >

java.lang.IllegalArgumentException: Required string is empty
at com.dhl.auditdatamgr.utils.db.DataUtil.enforceNotNullOrEmpty(DataUtil.java:81)
at com.dhl.auditdatamgr.utils.AuditFileParser.parseFile(AuditFileParser.java:75)
at com.dhl.auditdatamgr.process.AuditDataHandler.main(AuditDataHandler.java:94)
The error message is telling you exactly what the problem is and where it's happening. I can't see your code or your data.
jverda at 2007-7-21 10:13:57 >

Hi here is the code for java and sample text file .
The issue is it is reading al lines but after reading fourth line it is givng this error.it is not able to understand that file has come to an end and try to read fifth line which is not there
1)
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}&&[|]]");
////if (lineItems.length != 18)
//continue;
String [] lineItems = p.split(line);
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]);
detailedAuditData.setAuditAtServiceArea(lineItems[5]);
detailedAuditData.setAuditAtFacility(lineItems[6]);
detailedAuditData.setAuditTime(DataUtil.convertToTimestamp(lineItems[3]));
detailedAuditData.setHuType(lineItems[4]);
detailedAuditData.setBuiltAtServiceArea(lineItems[1]);
detailedAuditData.setBuiltAtFacility(lineItems[2]);
if(lineItems[9] != null && !lineItems[9].equals(""))
{
huExpected = new Integer(Integer.parseInt(lineItems[9]));
detailedAuditData.setHuExpected(huExpected);
}
if(lineItems[12] != null && !lineItems[12].equals(""))
{
huMissing = new Integer(Integer.parseInt(lineItems[12]));
detailedAuditData.setHuMissing(huMissing);
}
if(lineItems[13] != null && !lineItems[13].equals(""))
{
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(""))
{
shipmentMissing = new Integer(Integer.parseInt(lineItems[10]));
detailedAuditData.setShipmentMissing(shipmentMissing);
}
if(lineItems[11] != null && !lineItems[11].equals(""))
{
shipmentExtra = new Integer(Integer.parseInt(lineItems[11]));
detailedAuditData.setShipmentExtra(shipmentExtra);
}
if(lineItems[8] != null && !lineItems[8].equals(""))
{
pieceIdsExpected = new Integer(Integer.parseInt(lineItems[8]));
detailedAuditData.setPieceIdsExpected(pieceIdsExpected);
}
if(lineItems[14] != null && !lineItems[14].equals(""))
{
pieceIdsMissing = new Integer(Integer.parseInt(lineItems[14]));
detailedAuditData.setPieceIdsMissing(pieceIdsMissing);
}
if(lineItems[15] != null && !lineItems[15].equals(""))
{
pieceIdsExtra = new Integer(Integer.parseInt(lineItems[15]));
detailedAuditData.setPieceIdsExtra(pieceIdsExtra);
}
detailedAuditData.setAuditor(lineItems[16]);
detailedAuditData.setAuditDate(DataUtil.convertToDate(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;
}
}
2)H480988672|AAA|AAA|2006-09-23 06:23:57|B|AAA|AAA|1|0|0|0|0|0|10|0|0|mcannone|2006-09-23|
H573193578|KAA|KAA|2006-09-23 06:23:58|B|KAA|KAA|21|0|2|0|0|0|0|0|0|pgarcia|2006-09-23|
H583114428|KAA|KAA|2006-09-23 06:23:59|B|KAA|KAA|2221|0|2|0|0|0|0|0|0|pgarcia|2006-09-23|
H480985619|AAA|AAA|2006-09-23 06:23:56|B|AAA|AAA|3|0|3|0|0|0|9|0|0|mcannone|2006-09-23|
You forgot code tags.What does this method do (or what do you *think* it does)? It will *not* change the String lineItems[0].DataUtil.enforceNotNullOrEmpty(lineItems[0]);
here is some output from cosole
upto fourth line it is reading .for fifth line is eqal to blank but functionally it should not try to read fifth line as there is no fifth line.
line=H480985619|AAA|AAA|2006-09-23 06:23:56|B|AAA|AAA|3|0|3|0|0|0|9|0|0|mcannone|2006-09-23|
lineItems.length=18
Shipment expected is: 3
regex=[\p{Punct}&&[|]]
line=
lineItems.length=1
it is just saying that this value can not be blank in line
public static void enforceNotNullOrEmpty(String arg)
throws IllegalArgumentException
{
if(arg == null)
{
throw new IllegalArgumentException("Required string is null");
}
else if(arg.equals(new String("")))
{
throw new IllegalArgumentException("Required string is empty");
}
}
Are you sure you don't have two newlines at the end of your file? It seems that you must (but you shouldn't).Why did you comment out the "length != 18" line? If you had that, you shouldn't get the error.
I have a text file which contains the sample That I have already pasted.using notepad.
I commented it becuase after using that complete data file is not readbale.some are left and some are read.this was the solution i got before the revival of this thread once again
> it is just saying that this value can not be blank in
> line
>
> public static void enforceNotNullOrEmpty(String arg)
> throws IllegalArgumentException
> {
> if(arg == null)
> {
> throw new IllegalArgumentException("Required string is null");
> }
> else if(arg.equals(new String(""))) // HERE!
> {
> throw new IllegalArgumentException("Required string is empty");
> }
> }
At the line I commented "HERE", use:
if (arg.length()==0)
or, at least,
if (arg.equals(""))
The new String is redundant, and new String("") is even *more* redundant.
MLRona at 2007-7-21 10:14:01 >

NO Ron not working .i changed it but no effect
doremifasollatido I am not sure but lets thnk file is ending with two balnk line .any way it can be checked.I am simply using notepad for text file
> NO Ron not working .i changed it but no effect
It's Monica, not Ron. It wasn't supposed to have an effect. It just a style issue (same as the others I posted earlier in this thread, which you haven't fixed yet).
If you go into Notepad with your file, and hit Ctrl-End, is there a blank line between the data and your cursor?
MLRona at 2007-7-21 10:14:02 >

> NO Ron not working .i changed it but no effectYeah RON! Be more helpful. Try and be like doremifasollatido, he's a helpful guy.
Hi monica I used that And there is gap between last line and cursor.space of almost one paragraph
> Hi monica I used that And there is gap between last> line and cursor.> space of almost one paragraphTab maybe?
no idea.why there is gap.
> Hi monica I used that And there is gap between last
> line and cursor.
> space of almost one paragraph
Can you delete the space so that Ctrl-End puts you just under the last line, with no characters on the same line as the cursor? Then resave the file and try your Java code again.
MLRona at 2007-7-21 10:14:02 >

unfortunately no idea how to do it.I am just clickin on last line then" Enter".cursore moves to next belankline.Then I saved file but again i am doing ctrl end cursor is again giving space.
ya but if I am using tab and saving the file the gap is increasing.
Try opening Notepad with an empty file. Then paste in your four lines of data. Then save and try the Java code again.
MLRona at 2007-7-21 10:14:06 >

> unfortunately no idea how to do it.
> I am just clickin on last line then" Enter".cursore
> moves to next belankline.Then I saved file but again
> i am doing ctrl end cursor is again giving space.
This is an incredibly pointless excercise. Your program shouldn't be this brittle whatever the problem with the file may or may not be.
I would stop screwing around with the file and go back and uncomment that mimimum length check. I know you said this didn't work... I suggest fixing that. Your comment about why it didn't work was less than clear.
OR
Just catch the exception, spit out that A record was invalid and why and carry on.
ok decreased the gap now checking code
> ok decreased the gap now checking code
I think you might want to focus on decreasing the gap between your ears next.
What do you not understand about why brittle code is not a good idea?
This isn't much of a solution if you basically have to retype the files for your program to work is it?
Hi monica code is working now I am able to read all those data
but still one issue I dont want touch the file manually.
one person suggested me folwoing code but when I am using that I am not able to read the data file completely.some data left then some read then again left then again read.any idea?
while((line = br.readLine()) != null){
if (lineItems.length != 18)continue;
Hi cotton I was to give give some ouptu till afternoon.with help of monica atleast I can give now.but your point is right.I am putting the code that you told me but it is not reading all data.
What do you mean by not reading all the data? What columns are you missing from what lines?
for example if the file has 100 records it is reading only 60
but one point is noted that after putting that code.if this is follwoing code it is reading only one line for AAA.THE similar line for AAA are not
readble.but If i do not put that code it is reading all lines
1)
H480987114|AAA|AAA|2006-09-21 13:21:30|B|AAA|AAA|0|0|0|0|0|0|0|0|110|mcannone|2006-09-21|
2)
H480987114|AAA|AAA|2006-09-21 13:21:30|B|AAA|AAA|0|0|0|0|0|0|0|0|110|mcannone|2006-09-22|
> for example if the file has 100 records it is reading
> only 60
It's a conspiracy. The runtime just can't stand your inept coding, so it punishes you. It's really trying to tell you to get out of the business of writing software, but it can't speak your language so you'll understand. So it does the only thing it can.
I am just debugging some one else code
Now theses are the sample lines.Now if i put code to check the lines limit it is reading first value and then directly goes to fourth value.
but if I dont put the code then it is reading all lines but i manually need to put cursor at the end of file which should not be
H480987102|AAA|AAA|2006-09-25 16:24:49|B|AAA|AAA|14|10|0|2|0|2|2|0|0|mcannone|2006-09-25|
H480987103|AAA|AAA|2006-09-25 16:26:50|B|AAA|AAA|1400|10|0|2|0|2|2|0|0|mcannone|2006-09-25|
H480987104|AAA|AAA|2006-09-25 16:29:51|B|AAA|AAA|14|0|0|0|0|0|0|0|0|mcannone|2006-09-25|
H480986936|BAA|BAA|2006-09-25 16:22:39|B|BAA|BAA|13|0|2|20|10|0|10|0|0|mcannone|2006-09-25|
Note that in lines like this:
if(lineItems[7] != null && !lineItems[7].equals(""))
lineItems[x] will never be null. String.split won't put null values in the array. So, you just need:
if(!lineItems[7].equals(""))
or
if(lineItems[7].length() != 0)
MLRona at 2007-7-21 10:14:07 >
