Revision 41643 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/simplereaders/FixedLenReader.java

View differences:

FixedLenReader.java
15 15
    CSVStoreParameters.FieldDefinition fieldsDefinition[] = null;
16 16
    List fields = null;
17 17
    private final int fieldCount;
18
    private final CSVStoreParameters parameters;
19
    private String commentStartMarker;
18
//    private final CSVStoreParameters parameters;
19
    private final String commentStartMarker;
20
    private int currentLine =1;
20 21

  
21 22
    public FixedLenReader(FileReader reader, CSVStoreParameters parameters) {
22
        this.parameters = parameters;
23
//        this.parameters = parameters;
23 24
        this.reader = new BufferedReader(reader);
24 25
        this.fieldsDefinition = CSVStoreParameters.getFieldsDefinition(parameters);
25 26
        this.fieldCount = this.fieldsDefinition.length;
......
40 41

  
41 42
    public List<String> read() throws IOException {
42 43
        String line = this.reader.readLine();
43
        while( line!=null && line.startsWith(this.commentStartMarker) ) {
44
        this.currentLine++;
45
        while( line!=null && this.commentStartMarker!=null && line.startsWith(this.commentStartMarker) ) {
44 46
            line = this.reader.readLine();
47
            this.currentLine++;
45 48
        }
46 49
        return this.parse(line);
47 50
    }
......
52 55
        }
53 56
        for ( int i = 0; i < this.fieldCount; i++ ) {
54 57
            CSVStoreParameters.FieldDefinition fieldDefinition = this.fieldsDefinition[i];
55
            String value;
56
            if ( fieldDefinition.getToEndOfLine() ) {
57
                value = line.substring(fieldDefinition.getStart());
58
            } else {
59
                value = line.substring(
60
                        fieldDefinition.getStart(),
61
                        fieldDefinition.getEnd()
62
                );
58
            String value = null;
59
            try {
60
                if ( fieldDefinition.getToEndOfLine() ) {
61
                    value = line.substring(fieldDefinition.getStart());
62
                } else {
63
                    value = line.substring(
64
                            fieldDefinition.getStart(),
65
                            fieldDefinition.getEnd()
66
                    );
67
                }
68
            } catch(Exception ex) {
69
                // Ignore errors
70
                // Probablemente por que las lineas no tienen tantos caracteres como
71
                // se han indicado en la definicion.
63 72
            }
64 73
            this.fields.set(i, value);
65 74
        }
......
75 84
        String line = null;
76 85
        for ( int i = 0; i < lines; i++ ) {
77 86
            line = this.reader.readLine();
78
            while( line!=null && line.startsWith(this.commentStartMarker) ) {
87
            this.currentLine++;
88
            while( line!=null && this.commentStartMarker!=null && line.startsWith(this.commentStartMarker) ) {
79 89
                line = this.reader.readLine();
90
                this.currentLine++;
80 91
            }
81 92
        }
82 93
        return this.parse(line);
83 94
    }
84 95

  
96
    public int getLine() {
97
        return this.currentLine;
98
    }
85 99
}

Also available in: Unified diff