1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv.manager;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.Reader;
23 import java.util.List;
24 import java.util.zip.ZipFile;
25 import java.util.zip.ZipInputStream;
26
27 import com.orangesignal.csv.Csv;
28 import com.orangesignal.csv.CsvConfig;
29 import com.orangesignal.csv.LhaEntryFilter;
30 import com.orangesignal.csv.ZipEntryFilter;
31 import com.orangesignal.csv.bean.AbstractCsvBeanTemplate;
32 import com.orangesignal.csv.filters.BeanFilter;
33 import com.orangesignal.csv.handlers.AbstractBeanListHandler;
34 import com.orangesignal.csv.handlers.BeanOrder;
35 import com.orangesignal.jlha.LhaFile;
36 import com.orangesignal.jlha.LhaInputStream;
37
38
39
40
41
42
43
44 public abstract class AbstractCsvLoader<T, O extends AbstractCsvBeanTemplate<T, O>, H extends AbstractBeanListHandler<T, O, H>, L extends AbstractCsvLoader<T, O, H, L>> implements CsvLoader<T> {
45
46
47
48
49 private final CsvConfig cfg;
50
51
52
53
54 private final H handler;
55
56
57
58
59
60
61
62
63
64 protected AbstractCsvLoader(final CsvConfig cfg, final H handler) {
65 if (cfg == null) {
66 throw new IllegalArgumentException("CsvConfig must not be null");
67 }
68 if (handler == null) {
69 throw new IllegalArgumentException("CsvListHandler must not be null");
70 }
71 this.cfg = cfg;
72 this.handler = handler;
73 }
74
75
76
77
78
79
80 protected H getCsvListHandler() { return handler; }
81
82 @SuppressWarnings("unchecked")
83 @Override
84 public L filter(final BeanFilter filter) {
85 getCsvListHandler().filter(filter);
86 return (L) this;
87 }
88
89 @SuppressWarnings("unchecked")
90 @Override
91 public L order(final BeanOrder... orders) {
92 getCsvListHandler().order(orders);
93 return (L) this;
94 }
95
96 @SuppressWarnings("unchecked")
97 @Override
98 public L offset(final int offset) {
99 getCsvListHandler().setOffset(offset);
100 return (L) this;
101 }
102
103 @SuppressWarnings("unchecked")
104 @Override
105 public L limit(final int limit) {
106 getCsvListHandler().setLimit(limit);
107 return (L) this;
108 }
109
110 @Override
111 public List<T> from(final Reader reader) throws IOException {
112 return Csv.load(reader, cfg, getCsvListHandler());
113 }
114
115 @Override
116 public List<T> from(final InputStream in, final String encoding) throws IOException {
117 return Csv.load(in, encoding, cfg, getCsvListHandler());
118 }
119
120 @Override
121 public List<T> from(final InputStream in) throws IOException {
122 return Csv.load(in, cfg, getCsvListHandler());
123 }
124
125 @Override
126 public List<T> from(final File file, final String encoding) throws IOException {
127 return Csv.load(file, encoding, cfg, getCsvListHandler());
128 }
129
130 @Override
131 public List<T> from(final File file) throws IOException {
132 return Csv.load(file, cfg, getCsvListHandler());
133 }
134
135 @Override
136 public List<T> from(final LhaInputStream in, final String encoding, final LhaEntryFilter filter) throws IOException {
137 return Csv.load(in, encoding, cfg, getCsvListHandler(), filter);
138 }
139
140 @Override
141 public List<T> from(final LhaInputStream in, final String encoding) throws IOException {
142 return Csv.load(in, encoding, cfg, getCsvListHandler());
143 }
144
145 @Override
146 public List<T> from(final LhaInputStream in, final LhaEntryFilter filter) throws IOException {
147 return Csv.load(in, cfg, getCsvListHandler(), filter);
148 }
149
150 @Override
151 public List<T> from(final LhaInputStream in) throws IOException {
152 return Csv.load(in, cfg, getCsvListHandler());
153 }
154
155 @Override
156 public List<T> from(final LhaFile lhaFile, final String encoding, final LhaEntryFilter filter) throws IOException {
157 return Csv.load(lhaFile, encoding, cfg, getCsvListHandler(), filter);
158 }
159
160 @Override
161 public List<T> from(final LhaFile lhaFile, final String encoding) throws IOException {
162 return Csv.load(lhaFile, encoding, cfg, getCsvListHandler());
163 }
164
165 @Override
166 public List<T> from(final LhaFile lhaFile, final LhaEntryFilter filter) throws IOException {
167 return Csv.load(lhaFile, cfg, getCsvListHandler(), filter);
168 }
169
170 @Override
171 public List<T> from(final LhaFile lhaFile) throws IOException {
172 return Csv.load(lhaFile, cfg, getCsvListHandler());
173 }
174
175 @Override
176 public List<T> from(final ZipInputStream in, final String encoding, final ZipEntryFilter filter) throws IOException {
177 return Csv.load(in, encoding, cfg, getCsvListHandler(), filter);
178 }
179
180 @Override
181 public List<T> from(final ZipInputStream in, final String encoding) throws IOException {
182 return Csv.load(in, encoding, cfg, getCsvListHandler());
183 }
184
185 @Override
186 public List<T> from(final ZipInputStream in, final ZipEntryFilter filter) throws IOException {
187 return Csv.load(in, cfg, getCsvListHandler(), filter);
188 }
189
190 @Override
191 public List<T> from(final ZipInputStream in) throws IOException {
192 return Csv.load(in, cfg, getCsvListHandler());
193 }
194
195 @Override
196 public List<T> from(final ZipFile zipFile, final String encoding, final ZipEntryFilter filter) throws IOException {
197 return Csv.load(zipFile, encoding, cfg, getCsvListHandler(), filter);
198 }
199
200 @Override
201 public List<T> from(final ZipFile zipFile, final String encoding) throws IOException {
202 return Csv.load(zipFile, encoding, cfg, getCsvListHandler());
203 }
204
205 @Override
206 public List<T> from(final ZipFile zipFile, final ZipEntryFilter filter) throws IOException {
207 return Csv.load(zipFile, cfg, getCsvListHandler(), filter);
208 }
209
210 @Override
211 public List<T> from(final ZipFile zipFile) throws IOException {
212 return Csv.load(zipFile, cfg, getCsvListHandler());
213 }
214
215 }