Revision 42775 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/CSVReader.java

View differences:

CSVReader.java
20 20
    // http://supercsv.sourceforge.net/apidocs/index.html
21 21
    //
22 22
    private static final Logger logger = LoggerFactory.getLogger(CSVReader.class);
23
    CsvListReader reader;
24
    private CSVStoreParameters parameters;
25 23

  
24
    private CsvListReader reader;
25
    private final CSVStoreParameters parameters;
26
    private List<String>  nextLine;
27
    private int columns;
28

  
26 29
    public CSVReader(FileReader in, CSVStoreParameters parameters) {
27
        this.parameters = parameters;
28
        CsvPreference preferences = getCSVPreferences();
29
        this.reader = new CsvListReader(in, preferences);
30
        this(parameters);
31
        this.reader = new CsvListReader(in, getCSVPreferences());
30 32
    }    
31 33
    
32 34
    public CSVReader(CSVStoreParameters parameters) {
35
        this.reader = null;
33 36
        this.parameters = parameters;
34
        CsvPreference preferences = getCSVPreferences();
35 37
        this.reader = null;
38
        this.nextLine = null;
39
        this.columns = 0;
36 40
    }
37 41

  
38 42
    public CSVStoreParameters getParameters() {
39 43
        return this.parameters;
40 44
    }
41 45

  
46
    @Override
42 47
    public String[] getHeader() throws IOException {
43 48
        return this.reader.getHeader(true);
44 49
    }
50
    
51
    @Override
52
    public int getColumnsCount() throws IOException {
53
        if( this.columns <= 0 ) {
54
            this.columns = reader.length();
55
            if( this.columns <= 0 ) {
56
                this.nextLine = this.reader.read();
57
                this.columns = reader.length();
58
            }
59
        }
60
        return this.columns;
61
    }
45 62

  
63
    @Override
46 64
    public List<String> read() throws IOException {
47
        return reader.read();
65
        List<String> line;
66
        if( this.nextLine != null ) {
67
            line = this.nextLine;
68
            this.nextLine = null;
69
        } else {
70
            line = this.reader.read();
71
        }
72
        return line;
48 73
    }
49 74

  
75
    @Override
50 76
    public void close() throws IOException {
51 77
        this.reader.close();
52 78
    }
53 79

  
80
    @Override
54 81
    public List<String> skip(int lines) throws IOException {
82
        if( lines <= 0 ) {
83
            return null;
84
        }
85
        if( this.nextLine != null ) {
86
            this.nextLine = null;
87
            lines--;
88
        }
55 89
        List<String> row = null;
56 90
        for ( int i = 0; i < lines; i++ ) {
57 91
            row = reader.read();
......
61 95

  
62 96
    public CsvPreference getCSVPreferences() {
63 97
        try {
64
            String s = null;
98
            String s;
65 99
            char quoteChar;
66 100
            int delimiterChar;
67 101
            String endOfLineSymbols;
68 102

  
69 103
            DynObject params = this.getParameters();
70 104

  
71
            CsvPreference.Builder builder = null;
105
            CsvPreference.Builder builder;
72 106

  
73 107
            CsvPreference defaultPreference = CSVStoreParameters
74 108
                    .getPredefinedCSVPreferences(params);
......
118 152
    
119 153
    private String getFullFileName() {
120 154
        // Usar solo para mostrar mensajes en el logger.
121
        String s = "(unknow)";
155
        String s;
122 156
        try {
123 157
            s = getParameters().getFile().getAbsolutePath();
124 158
        } catch (Exception e2) {
......
127 161
        return s;        
128 162
    }
129 163

  
164
    @Override
130 165
    public int getLine() {
131 166
        if( this.reader==null ) {
132 167
            return 0;

Also available in: Unified diff