Skip to content

Commit

Permalink
Final cleanup of new writers
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 12, 2019
1 parent 27c0be2 commit 2d52146
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
3 changes: 2 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
<groupId>com.github.haifengl</groupId>
<artifactId>smile-data</artifactId>
<version>1.5.2 </version>
<scope>provided</scope>
<optional>true</optional>
<scope>provided</scope> <!-- because the shade plugin doesn't exclude optional dependencies -->
</dependency>
<dependency>
<groupId>tech.tablesaw</groupId>
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/tech/tablesaw/io/html/HtmlWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package tech.tablesaw.io.html;

import java.io.IOException;
import java.io.StringWriter;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -37,7 +38,7 @@ public void setUp() throws Exception {
}

@Test
public void testWrite() {
public void testWrite() throws IOException {
StringColumn byColumn = table.stringColumn("who");
TableSliceGroup group = StandardTableSliceGroup.create(table, byColumn);
Table result = group.aggregate("approval", AggregateFunctions.mean);
Expand Down
2 changes: 1 addition & 1 deletion excel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-core</artifactId>
<version>0.32.1</version>
<version>0.32.2</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion html/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-core</artifactId>
<version>0.32.1</version>
<version>0.32.2</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
15 changes: 6 additions & 9 deletions html/src/main/java/tech/tablesaw/io/html/HtmlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void register(WriterRegistry registry) {
registry.registerOptions(HtmlWriteOptions.class, INSTANCE);
}

public void write(Table table, HtmlWriteOptions options) {
public void write(Table table, HtmlWriteOptions options) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("<table>").append(System.lineSeparator());
builder.append(header(table.columnNames()));
Expand All @@ -51,13 +51,10 @@ public void write(Table table, HtmlWriteOptions options) {
builder.append("</tbody>").append(System.lineSeparator());
builder.append("</table>");
String str = builder.toString();
try {
Writer writer = options.destination().createWriter();
writer.write(str);
writer.flush();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}

Writer writer = options.destination().createWriter();
writer.write(str);
writer.flush();
}

/**
Expand Down Expand Up @@ -100,7 +97,7 @@ private static String header(List<String> columnNames) {
}

@Override
public void write(Table table, Destination dest) {
public void write(Table table, Destination dest) throws IOException {
write(table, HtmlWriteOptions.build(dest).build());
}
}
2 changes: 1 addition & 1 deletion json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-core</artifactId>
<version>0.32.1</version>
<version>0.32.2</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
17 changes: 7 additions & 10 deletions json/src/main/java/tech/tablesaw/io/json/JsonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void register(WriterRegistry registry) {
registry.registerOptions(JsonWriteOptions.class, INSTANCE);
}

public void write(Table table, JsonWriteOptions options) {
public void write(Table table, JsonWriteOptions options) throws IOException {
ArrayNode output = mapper.createArrayNode();
if (options.asObjects()) {
for (int r = 0; r < table.rowCount(); r++) {
Expand All @@ -67,18 +67,15 @@ public void write(Table table, JsonWriteOptions options) {
output.add(row);
}
}
try {
String str = mapper.writeValueAsString(output);
Writer writer = options.destination().createWriter();
writer.write(str);
writer.flush();
} catch (IOException e) {
throw new IllegalStateException(e);
}

String str = mapper.writeValueAsString(output);
Writer writer = options.destination().createWriter();
writer.write(str);
writer.flush();
}

@Override
public void write(Table table, Destination dest) {
public void write(Table table, Destination dest) throws IOException {
write(table, JsonWriteOptions.builder(dest).build());
}

Expand Down

0 comments on commit 2d52146

Please sign in to comment.