Statistics
| Revision:

svn-gvsig-desktop / 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 / simplereader / virtualrows / LimitedReader.java @ 47643

History | View | Annotate | Download (2.02 KB)

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.fmap.dal.store.simplereader.virtualrows;
7

    
8
import java.io.IOException;
9
import java.io.Reader;
10

    
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
public class LimitedReader extends Reader {
16
    
17
    private final Reader delegated;
18
    private final int limit;
19
    private int count;
20

    
21
    public LimitedReader(Reader reader, int limit) {
22
        this.delegated = reader;
23
        this.limit = limit;
24
    }
25

    
26
    @Override
27
    public int read(char[] cbuf, int off, int len) throws IOException {
28
        if (count >= limit) {
29
            return -1;
30
        }
31
        if (count + len > limit) {
32
            len = limit - count;
33
        }
34
        if (len == 0) {
35
            return -1;
36
        }
37
        int n = this.delegated.read(cbuf, off, len);
38
        if (count + n <= limit) {
39
            count += n;
40
            return n;
41
        }
42
        return limit - count;
43
    }
44

    
45
    @Override
46
    public void close() throws IOException {
47
        //            this.delegated.close();
48
    }
49

    
50
    @Override
51
    public int read(java.nio.CharBuffer target) throws IOException {
52
        return this.delegated.read(target);
53
    }
54

    
55
    @Override
56
    public int read() throws IOException {
57
        return this.delegated.read();
58
    }
59

    
60
    @Override
61
    public int read(char[] cbuf) throws IOException {
62
        return this.delegated.read(cbuf);
63
    }
64

    
65
    @Override
66
    public long skip(long n) throws IOException {
67
        return this.delegated.skip(n);
68
    }
69

    
70
    @Override
71
    public boolean ready() throws IOException {
72
        return this.delegated.ready();
73
    }
74

    
75
    @Override
76
    public boolean markSupported() {
77
        return this.delegated.markSupported();
78
    }
79

    
80
    @Override
81
    public void mark(int readAheadLimit) throws IOException {
82
        this.delegated.mark(readAheadLimit);
83
    }
84

    
85
    @Override
86
    public void reset() throws IOException {
87
        this.delegated.reset();
88
    }
89
    
90
}