[email protected] wrote:
> Author: jleroux
> Date: Tue Mar 16 16:00:32 2010
> New Revision: 923828
> 
> URL: http://svn.apache.org/viewvc?rev=923828&view=rev
> Log:
> A patch from BJ Freeman "Datafile does not catch lack of delimiter if at end 
> of line." (https://issues.apache.org/jira/browse/OFBIZ-3026) - OFBIZ-3026
> 
> There was an issue if the datafile did not have the last delimiter before the 
> CRLF.  This fixes it when there are not data for a field and also fixes the 
> EOL.
> 
> Modified:
>     ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java
>     ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java
> 
> Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java?rev=923828&r1=923827&r2=923828&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java 
> (original)
> +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java Tue Mar 
> 16 16:00:32 2010
> @@ -561,18 +561,24 @@ public class Record implements Serializa
>                      strVal = (String)modelField.defaultValue;
>                  }
>              } else {
> -                try {
> -                    strVal = st.nextToken();
> -                    if (strVal.equals("" + delimiter)) {
> -                        strVal = null;
> -                    } else {
> -                        if (st.hasMoreTokens()) {
> -                            st.nextToken();
> +                //some input lines may be less than the header model.
> +                if (st.hasMoreTokens()) {
> +                    try {
> +                        strVal = st.nextToken();
> +                        if (strVal.equals("" + delimiter)) {
> +                            strVal = null;
> +                        } else {
> +                            if (st.hasMoreTokens()) {
> +                                st.nextToken();
> +                            }
>                          }
> -                    }
> -                } catch (NoSuchElementException nsee) {
> -                    throw new DataFileException("Field " + modelField.name + 
> " could not be read from a line (" + lineNum + ") with only " +
> -                            line.length() + " chars.", nsee);
> +                    } catch (NoSuchElementException nsee) {
> +                        throw new DataFileException("Field " + 
> modelField.name + " could not be read from a line (" + lineNum + ") with only 
> " +
> +                                line.length() + " chars.", nsee);
> +                    }                
> +                }
> +                else { //if input line is less than the header model then 
> pad with null
> +                    strVal = null;
>                  }

} else {

>              }
>              try {
> 
> Modified: 
> ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java?rev=923828&r1=923827&r2=923828&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java 
> (original)
> +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java 
> Tue Mar 16 16:00:32 2010
> @@ -26,6 +26,8 @@ import java.io.InputStreamReader;
>  import java.net.URL;
>  import java.util.Stack;
>  
> +import org.ofbiz.base.util.Debug;
> +

Extra blank line.

>  /**
>   *  Record Iterator for reading large files
> @@ -84,7 +86,6 @@ public class RecordIterator {
>          this.nextRecord = null;
>  
>          boolean isFixedRecord = 
> ModelDataFile.SEP_FIXED_RECORD.equals(modelDataFile.separatorStyle);
> -        boolean isFixedLength = 
> ModelDataFile.SEP_FIXED_LENGTH.equals(modelDataFile.separatorStyle);
>          boolean isDelimited = 
> ModelDataFile.SEP_DELIMITED.equals(modelDataFile.separatorStyle);
>          // if (Debug.infoOn()) Debug.logInfo("[DataFile.readDataFile] 
> separatorStyle is " + modelDataFile.separatorStyle + ", isFixedRecord: " + 
> isFixedRecord, module);
>  
> @@ -111,12 +112,14 @@ public class RecordIterator {
>          } else {
>              try {
>                  nextLine = br.readLine();
> -            } catch (IOException e) {
> +                Debug.logInfo("br.readLine()=\"" + nextLine + "\"", module);
> +                } catch (IOException e) {

Remove this logInfo.

The catch line has bad indentation.

>                  throw new DataFileException("Error reading line #" + 
> nextLineNum + " from location: " + locationInfo, e);
>              }
>          }
>  
> -        if (nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 1 
> == nextLine.length())) {
> +        //if (nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 1 
> == nextLine.length())) {
> +        if (nextLine != null && !((nextLine.contains(eof) ) )) {

Don't leave commented out lines like this; it is generally bad form,
esp. for simple lines.  That's what revision history is for.

Bad spacing around parentheses.

>              nextLineNum++;
>              ModelRecord modelRecord = findModelForLine(nextLine, 
> nextLineNum, modelDataFile);
>              if (isDelimited) {
> @@ -136,7 +139,8 @@ public class RecordIterator {
>      }
>  
>      public boolean hasNext() {
> -        return nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 
> 1 == nextLine.length());
> +        //return nextLine != null && !(eof.equals(nextLine.substring(0,1)) 
> && 1 == nextLine.length());
> +        return nextLine != null && !((nextLine.contains(eof) ) );

Same as last paragraph.


Reply via email to