Skip to content

Commit 9e96bbf

Browse files
Bugfix for a bug introducd in 0.6.3
1 parent 80bf73f commit 9e96bbf

File tree

5 files changed

+47
-20
lines changed

5 files changed

+47
-20
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.frictionlessdata</groupId>
55
<artifactId>tableschema-java</artifactId>
6-
<version>0.6.2-SNAPSHOT</version>
6+
<version>0.6.4-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<issueManagement>
99
<url>https://github.com/frictionlessdata/tableschema-java/issues</url>

src/main/java/io/frictionlessdata/tableschema/tabledatasource/TableDataSource.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,13 @@ public interface TableDataSource {
6868
* @return DataSource created from input String
6969
*/
7070
static TableDataSource fromSource(String input) {
71-
String cleanedInput = input;
72-
try {
73-
byte[] bytes = new byte[input.length()];
74-
input.getBytes(0, input.length(), bytes, 0);
75-
ByteOrderMarkStrippingInputStream is
76-
= new ByteOrderMarkStrippingInputStream(new ByteArrayInputStream(bytes));
77-
is.skipBOM();
78-
79-
InputStreamReader rdr = new InputStreamReader(is);
80-
BufferedReader bfr = new BufferedReader(rdr);
81-
cleanedInput = bfr.lines().collect(Collectors.joining("\n"));
82-
is.close();
83-
rdr.close();
84-
bfr.close();
85-
} catch (Exception ex) {
86-
throw new TableIOException(ex);
87-
}
8871
try {
8972
// JSON array generation. If an exception is thrown -> probably CSV data
90-
ArrayNode json = JsonUtil.getInstance().createArrayNode(cleanedInput);
73+
ArrayNode json = JsonUtil.getInstance().createArrayNode(input);
9174
return new JsonArrayTableDataSource(input);
9275
} catch (Exception ex) {
9376
// JSON parsing failed, treat it as a CSV
94-
return new CsvTableDataSource(cleanedInput);
77+
return new CsvTableDataSource(input);
9578
}
9679
}
9780

src/test/java/io/frictionlessdata/tableschema/table_tests/TableEncodingTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.frictionlessdata.tableschema.table_tests;
22

33
import io.frictionlessdata.tableschema.Table;
4+
import io.frictionlessdata.tableschema.schema.Schema;
45
import org.junit.jupiter.api.Assertions;
56
import org.junit.jupiter.api.Disabled;
67
import org.junit.jupiter.api.DisplayName;
@@ -9,6 +10,7 @@
910
import java.io.File;
1011
import java.util.Iterator;
1112

13+
import static io.frictionlessdata.tableschema.TestHelper.getTestDataDirectory;
1214
import static io.frictionlessdata.tableschema.TestHelper.getTestsuiteDataDirectory;
1315

1416
public class TableEncodingTests {
@@ -28,4 +30,23 @@ void createTableFromIso8859() throws Exception{
2830
Object[] row = iter.next();
2931
Assertions.assertEquals("Réunion", row[0]);
3032
}
33+
34+
@Test
35+
@DisplayName("Create a Table from a UTF-8 encoded file with non-ASCII chars")
36+
@Disabled
37+
void createTableFromUTF8() throws Exception{
38+
File testDataDir = getTestDataDirectory();
39+
Schema schema = Schema.fromJson(new File(testDataDir, "schema/units_schema.json"), true);
40+
41+
Table table
42+
= Table.fromSource(new File("data/units.csv"), testDataDir, schema, null);
43+
44+
Iterator<Object[]> iter = table.iterator();
45+
Object[] row = iter.next();
46+
Assertions.assertEquals("°C", row[1]);
47+
row = iter.next();
48+
Assertions.assertEquals("μS/cm", row[1]);
49+
row = iter.next();
50+
Assertions.assertEquals("°F", row[1]);
51+
}
3152
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
id,unit
2+
1,°C
3+
2,μS/cm
4+
2,°F
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"fields": [
3+
{
4+
"name": "id",
5+
"format": "default",
6+
"description": "primary key",
7+
"type": "integer",
8+
"title": "id"
9+
},
10+
{
11+
"name": "unit",
12+
"format": "default",
13+
"description": "The unit.",
14+
"type": "string",
15+
"title": "The unit."
16+
}
17+
],
18+
"primaryKey": "id"
19+
}

0 commit comments

Comments
 (0)