Skip to content

Commit 2039591

Browse files
committed
Merge branch 'v3.x.x'
2 parents 71bc537 + b727ac0 commit 2039591

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This library is available in [Maven Central](https://mvnrepository.com/artifact/
2222
<dependency>
2323
<groupId>io.github.millij</groupId>
2424
<artifactId>poi-object-mapper</artifactId>
25-
<version>3.2.0</version>
25+
<version>3.2.1</version>
2626
</dependency>
2727
```
2828

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sourceCompatibility = 1.8
1515
targetCompatibility = 1.8
1616

1717
group = 'io.github.millij'
18-
version = '3.2.0'
18+
version = '3.2.1'
1919

2020

2121
dependencies {

src/main/java/io/github/millij/poi/ss/writer/AbstractSpreadsheetWriter.java

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.github.millij.poi.ss.writer;
22

3-
import java.io.File;
4-
import java.io.FileOutputStream;
53
import java.io.IOException;
64
import java.io.OutputStream;
75
import java.util.ArrayList;
@@ -172,21 +170,9 @@ public void addSheet(final List<Map<String, Object>> rowsData, final String inSh
172170
// Write
173171

174172
@Override
175-
public void write(final File file) throws IOException {
176-
// Sanity checks
177-
if (Objects.isNull(file)) {
178-
throw new IllegalArgumentException("#write :: Input File object is NULL");
179-
}
180-
181-
try (final OutputStream outputStrem = new FileOutputStream(file)) {
182-
workbook.write(outputStrem);
183-
workbook.close();
184-
185-
} catch (Exception ex) {
186-
final String errMsg = String.format("Failed to write workbook data to file : %s", file.getPath());
187-
LOGGER.error(errMsg);
188-
throw ex;
189-
}
173+
public void write(final OutputStream outputStrem) throws IOException {
174+
workbook.write(outputStrem);
175+
workbook.close();
190176
}
191177

192178

src/main/java/io/github/millij/poi/ss/writer/SpreadsheetWriter.java

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package io.github.millij.poi.ss.writer;
22

33
import java.io.File;
4+
import java.io.FileOutputStream;
45
import java.io.IOException;
6+
import java.io.OutputStream;
57
import java.util.List;
68
import java.util.Map;
9+
import java.util.Objects;
710

811
import org.apache.logging.log4j.util.Strings;
912

@@ -109,6 +112,33 @@ default void addSheet(List<Map<String, Object>> rowsData, List<String> headers)
109112
//
110113
// Write
111114

115+
/**
116+
* Writes the current Spreadsheet workbook to an OutputStream
117+
*
118+
* @param outputStream output stream
119+
*
120+
* @throws IOException if the stream is not writable.
121+
*/
122+
void write(OutputStream outputStream) throws IOException;
123+
124+
/**
125+
* Writes the current Spreadsheet workbook to a file
126+
*
127+
* @param file output file
128+
*
129+
* @throws IOException if the file is not writable.
130+
*/
131+
default void write(final File file) throws IOException {
132+
// Sanity checks
133+
if (Objects.isNull(file)) {
134+
throw new IllegalArgumentException("#write :: Input File object is NULL");
135+
}
136+
137+
// OutputStream
138+
final OutputStream outputStream = new FileOutputStream(file);
139+
this.write(outputStream);
140+
}
141+
112142
/**
113143
* Writes the current Spreadsheet workbook to a file in the specified path.
114144
*
@@ -122,17 +152,10 @@ default void write(final String filepath) throws IOException {
122152
throw new IllegalArgumentException("#write :: Input File Path is BLANK");
123153
}
124154

125-
this.write(new File(filepath));
155+
// OutputStream
156+
final OutputStream outputStream = new FileOutputStream(filepath);
157+
this.write(outputStream);
126158
}
127159

128-
/**
129-
* Writes the current Spreadsheet workbook to a file
130-
*
131-
* @param file output file
132-
*
133-
* @throws IOException if the file is not writable.
134-
*/
135-
void write(File file) throws IOException;
136-
137160

138161
}

0 commit comments

Comments
 (0)