Skip to content

Commit 9b6ed6b

Browse files
authored
Merge pull request #20 from embulk/non-inner-class-Exceptions-from-CsvTokenizer
Replace CsvTokenizer's Exceptions not to be inner classes
2 parents 169cc10 + 0a83220 commit 9b6ed6b

File tree

9 files changed

+130
-39
lines changed

9 files changed

+130
-39
lines changed

embulk-guess-csv/src/main/java/org/embulk/guess/csv/CsvGuessPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.embulk.config.ConfigSource;
3232
import org.embulk.parser.csv.CsvParserPlugin;
3333
import org.embulk.parser.csv.CsvTokenizer;
34+
import org.embulk.parser.csv.InvalidValueException;
35+
import org.embulk.parser.csv.TooFewColumnsException;
3436
import org.embulk.spi.Buffer;
3537
import org.embulk.spi.BufferAllocator;
3638
import org.embulk.spi.Exec;
@@ -324,12 +326,12 @@ private static List<List<String>> splitLines(
324326
} else {
325327
columns.add(column);
326328
}
327-
} catch (final CsvTokenizer.TooFewColumnsException ex) {
329+
} catch (final TooFewColumnsException ex) {
328330
rows.add(Collections.unmodifiableList(columns));
329331
break;
330332
}
331333
}
332-
} catch (final CsvTokenizer.InvalidValueException ex) {
334+
} catch (final InvalidValueException ex) {
333335
// TODO warning
334336
tokenizer.skipCurrentLine();
335337
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/CsvParserPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ private String nextColumn() {
429429

430430
try {
431431
hasNextRecord = tokenizer.nextRecord();
432-
} catch (CsvTokenizer.TooManyColumnsException ex) {
432+
} catch (TooManyColumnsException ex) {
433433
if (allowExtraColumns) {
434434
String tooManyColumnsLine = tokenizer.skipCurrentLine();
435435
// TODO warning
@@ -441,7 +441,7 @@ private String nextColumn() {
441441
}
442442
pageBuilder.addRecord();
443443

444-
} catch (CsvTokenizer.InvalidFormatException | CsvTokenizer.InvalidValueException | CsvRecordValidateException e) {
444+
} catch (InvalidFormatException | InvalidValueException | CsvRecordValidateException e) {
445445
String skippedLine = tokenizer.skipCurrentLine();
446446
long lineNumber = tokenizer.getCurrentLineNumber();
447447
if (stopOnInvalidRecord) {

embulk-parser-csv/src/main/java/org/embulk/parser/csv/CsvTokenizer.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.List;
2323
import org.embulk.config.ConfigException;
2424
import org.embulk.parser.csv.CsvParserPlugin.QuotesInQuotedFields;
25-
import org.embulk.spi.DataException;
2625
import org.embulk.util.text.LineDecoder;
2726

2827
public class CsvTokenizer {
@@ -62,35 +61,6 @@ public CsvTokenizer(final LineDecoder input, final CsvParserPlugin.PluginTask ta
6261
this.wasQuotedColumn = false;
6362
}
6463

65-
public static class InvalidFormatException extends DataException {
66-
public InvalidFormatException(final String message) {
67-
super(message);
68-
}
69-
}
70-
71-
public static class InvalidValueException extends DataException {
72-
public InvalidValueException(final String message) {
73-
super(message);
74-
}
75-
}
76-
77-
public static class QuotedSizeLimitExceededException extends InvalidValueException {
78-
public QuotedSizeLimitExceededException(final String message) {
79-
super(message);
80-
}
81-
}
82-
83-
public class TooManyColumnsException extends InvalidFormatException {
84-
public TooManyColumnsException(final String message) {
85-
super(message);
86-
}
87-
}
88-
89-
public class TooFewColumnsException extends InvalidFormatException {
90-
public TooFewColumnsException(final String message) {
91-
super(message);
92-
}
93-
}
9464

9565
public long getCurrentLineNumber() {
9666
return this.lineNumber;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2014 The Embulk project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.embulk.parser.csv;
18+
19+
import org.embulk.spi.DataException;
20+
21+
public class InvalidFormatException extends DataException {
22+
public InvalidFormatException(final String message) {
23+
super(message);
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2014 The Embulk project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.embulk.parser.csv;
18+
19+
import org.embulk.spi.DataException;
20+
21+
public class InvalidValueException extends DataException {
22+
public InvalidValueException(final String message) {
23+
super(message);
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2014 The Embulk project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.embulk.parser.csv;
18+
19+
public class QuotedSizeLimitExceededException extends InvalidValueException {
20+
public QuotedSizeLimitExceededException(final String message) {
21+
super(message);
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2014 The Embulk project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.embulk.parser.csv;
18+
19+
public class TooFewColumnsException extends InvalidFormatException {
20+
public TooFewColumnsException(final String message) {
21+
super(message);
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2014 The Embulk project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.embulk.parser.csv;
18+
19+
public class TooManyColumnsException extends InvalidFormatException {
20+
public TooManyColumnsException(final String message) {
21+
super(message);
22+
}
23+
}

embulk-parser-csv/src/test/java/org/embulk/parser/csv/TestCsvTokenizer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public void throwWithDefaultQuotesInQuotedFields() throws Exception {
321321
parse(task, "\"foo\"bar\",\"hoge\"fuga\"");
322322
fail();
323323
} catch (Exception e) {
324-
assertTrue(e instanceof CsvTokenizer.InvalidValueException);
324+
assertTrue(e instanceof InvalidValueException);
325325
assertEquals("Unexpected extra character 'b' after a value quoted by '\"'", e.getMessage());
326326
return;
327327
}
@@ -336,7 +336,7 @@ public void throwWithQuotesInQuotedFields_ACCEPT_ONLY_RFC4180_ESCAPED() throws E
336336
parse(task, "\"foo\"bar\",\"hoge\"fuga\"");
337337
fail();
338338
} catch (Exception e) {
339-
assertTrue(e instanceof CsvTokenizer.InvalidValueException);
339+
assertTrue(e instanceof InvalidValueException);
340340
assertEquals("Unexpected extra character 'b' after a value quoted by '\"'", e.getMessage());
341341
return;
342342
}
@@ -370,7 +370,7 @@ public void throwQuotedSizeLimitExceededException() throws Exception {
370370
"v3,\"0123456789\"");
371371
fail();
372372
} catch (Exception e) {
373-
assertTrue(e instanceof CsvTokenizer.QuotedSizeLimitExceededException);
373+
assertTrue(e instanceof QuotedSizeLimitExceededException);
374374
}
375375

376376
// multi-line
@@ -380,7 +380,7 @@ public void throwQuotedSizeLimitExceededException() throws Exception {
380380
"\"012345\n6789\",v3");
381381
fail();
382382
} catch (Exception e) {
383-
assertTrue(e instanceof CsvTokenizer.QuotedSizeLimitExceededException);
383+
assertTrue(e instanceof QuotedSizeLimitExceededException);
384384
}
385385
}
386386

@@ -412,7 +412,7 @@ public void recoverFromQuotedSizeLimitExceededException() throws Exception {
412412
tokenizer.nextColumn();
413413
fail();
414414
} catch (Exception e) {
415-
assertTrue(e instanceof CsvTokenizer.QuotedSizeLimitExceededException);
415+
assertTrue(e instanceof QuotedSizeLimitExceededException);
416416
}
417417
assertEquals("v3,\"0123", tokenizer.skipCurrentLine());
418418

0 commit comments

Comments
 (0)