Skip to content

Commit c645a2c

Browse files
Maintenance release, added spotbugs maven plugin
1 parent ecec578 commit c645a2c

File tree

7 files changed

+54
-8
lines changed

7 files changed

+54
-8
lines changed

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@
168168
</execution>
169169
</executions>
170170
</plugin>
171+
172+
<plugin>
173+
<groupId>com.github.spotbugs</groupId>
174+
<artifactId>spotbugs-maven-plugin</artifactId>
175+
<version>4.9.3.0</version>
176+
<configuration>
177+
<effort>Max</effort>
178+
<threshold>High</threshold>
179+
<xmlOutput>false</xmlOutput>
180+
</configuration>
181+
<executions>
182+
<execution>
183+
<goals>
184+
<goal>check</goal>
185+
</goals>
186+
</execution>
187+
</executions>
188+
</plugin>
171189
</plugins>
172190
</build>
173191

src/main/java/io/frictionlessdata/tableschema/Table.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import java.io.*;
2222
import java.net.URL;
23+
import java.nio.charset.Charset;
24+
import java.nio.charset.StandardCharsets;
2325
import java.util.*;
2426

2527
/**
@@ -54,6 +56,8 @@ public class Table{
5456
private Schema schema = null;
5557
private CSVFormat format = TableDataSource.getDefaultCsvFormat();
5658

59+
private Charset charset = StandardCharsets.UTF_8;
60+
5761
/**
5862
* Constructor for an empty Table. It contains neither data nor is it controlled by a Schema
5963
*/
@@ -327,6 +331,22 @@ public Iterator<Map<String, Object>> mappingIterator(boolean extended, boolean c
327331
return new TableIterator<>(this, true, extended, cast, relations);
328332
}
329333

334+
/**
335+
* returns the charset or encoding to use when writing CSV files.
336+
* @return the used charset
337+
*/
338+
public Charset getCharset() {
339+
return charset;
340+
}
341+
342+
/**
343+
* Sets the charset or encoding to use when writing CSV files.
344+
* @param charset the charset to use
345+
*/
346+
public void setCharset(Charset charset) {
347+
this.charset = charset;
348+
}
349+
330350
public Map<Integer, Integer> getSchemaHeaderMapping() {
331351
if (null == schema) {
332352
return TableSchemaUtil
@@ -562,7 +582,7 @@ public void writeCsv(Writer out, CSVFormat format) {
562582
* @param format the CSV format to use
563583
*/
564584
public void writeCsv(File outputFile, CSVFormat format){
565-
try (FileWriter fw = new FileWriter(outputFile)) {
585+
try (FileWriter fw = new FileWriter(outputFile, charset)) {
566586
writeCsv(fw, format);
567587
} catch (IOException ex) {
568588
throw new TableIOException(ex);

src/main/java/io/frictionlessdata/tableschema/field/Field.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,23 +570,23 @@ public String getTitle(){
570570
return this.title;
571571
}
572572

573-
public void setTitle(String title) {
573+
public void setTitle(String title) {
574574
this.title = title;
575575
}
576576

577577
public String getDescription(){
578578
return this.description;
579579
}
580580

581-
public void setDescription(String description) {
581+
public void setDescription(String description) {
582582
this.description = description;
583583
}
584584

585585
public Map<String, Object> getConstraints(){
586586
return this.constraints;
587587
}
588588

589-
public void setConstraints(Map<String, Object> constraints) {
589+
public void setConstraints(Map<String, Object> constraints) {
590590
this.constraints = constraints;
591591
}
592592

src/main/java/io/frictionlessdata/tableschema/field/StringField.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import java.net.URI;
99
import java.net.URISyntaxException;
10+
import java.nio.charset.Charset;
11+
import java.nio.charset.StandardCharsets;
1012
import java.util.Base64;
1113
import java.util.Map;
1214
import java.util.regex.Matcher;
@@ -61,7 +63,7 @@ public String formatValueAsString(String value, String format, Map<String, Objec
6163
String formatObjectValueAsString(Object value, String format, Map<String, Object> options) throws InvalidCastException, ConstraintsException {
6264
if (value instanceof byte[]) {
6365
byte[] encode = Base64.getEncoder().encode((byte[]) value);
64-
String retVal = new String(encode);
66+
String retVal = new String(encode, StandardCharsets.UTF_8);
6567
return retVal;
6668
}
6769
return value.toString();

src/main/java/io/frictionlessdata/tableschema/fk/ForeignKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ForeignKey {
2727

2828
public ForeignKey(){}
2929

30-
public ForeignKey(Object fields, Reference reference, boolean strict) throws ForeignKeyException{
30+
public ForeignKey(Object fields, Reference reference, boolean strict) {
3131
this.fields = fields;
3232
this.reference = reference;
3333
this.strictValidation = strict;

src/main/java/io/frictionlessdata/tableschema/fk/Reference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Reference {
3636

3737
public Reference(){}
3838

39-
public Reference(String resource, Object fields, boolean strict) throws ForeignKeyException{
39+
public Reference(String resource, Object fields, boolean strict) {
4040
this.resourceName = resource;
4141
this.fields = fields;
4242
this.strictValidation = strict;

src/main/java/io/frictionlessdata/tableschema/schema/Schema.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.*;
2222
import java.net.URL;
23+
import java.nio.charset.Charset;
2324
import java.nio.charset.StandardCharsets;
2425
import java.util.*;
2526
import java.util.stream.Collectors;
@@ -53,6 +54,11 @@ public class Schema implements SchemaInterface{
5354
public static final String JSON_KEY_PRIMARY_KEY = "primaryKey";
5455
public static final String JSON_KEY_FOREIGN_KEYS = "foreignKeys";
5556

57+
/**
58+
* The charset or encoding of the schema
59+
*/
60+
private Charset charset = StandardCharsets.UTF_8;
61+
5662
// the schema validator
5763
@JsonIgnore
5864
private FormalSchemaValidator tableFormalSchemaValidator = null;
@@ -244,7 +250,7 @@ public void writeJson(File outputFile) throws IOException {
244250
}
245251

246252
private void writeJson(OutputStream output) throws IOException {
247-
try (BufferedWriter file = new BufferedWriter(new OutputStreamWriter(output))) {
253+
try (BufferedWriter file = new BufferedWriter(new OutputStreamWriter(output, charset))) {
248254
file.write(this.asJson());
249255
}
250256
}

0 commit comments

Comments
 (0)