Skip to content

Commit 6063322

Browse files
committed
Internal refactoring
1 parent f3bd909 commit 6063322

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public Builder() {
9494
// empty
9595
}
9696

97+
private File checkOriginFile() {
98+
return checkOrigin().getFile();
99+
}
100+
97101
/**
98102
* Builds a new {@link FileWriterWithEncoding}.
99103
* <p>
@@ -117,11 +121,15 @@ public Builder() {
117121
*/
118122
@Override
119123
public FileWriterWithEncoding get() throws IOException {
124+
return new FileWriterWithEncoding(this);
125+
}
126+
127+
private Object getEncoder() {
120128
if (charsetEncoder != null && getCharset() != null && !charsetEncoder.charset().equals(getCharset())) {
121129
throw new IllegalStateException(String.format("Mismatched Charset(%s) and CharsetEncoder(%s)", getCharset(), charsetEncoder.charset()));
122130
}
123131
final Object encoder = charsetEncoder != null ? charsetEncoder : getCharset();
124-
return new FileWriterWithEncoding(initWriter(checkOrigin().getFile(), encoder, append));
132+
return encoder;
125133
}
126134

127135
/**
@@ -193,6 +201,11 @@ private static OutputStreamWriter initWriter(final File file, final Object encod
193201
}
194202
}
195203

204+
@SuppressWarnings("resource") // caller closes
205+
private FileWriterWithEncoding(final Builder builder) throws IOException {
206+
super(initWriter(builder.checkOriginFile(), builder.getEncoder(), builder.append));
207+
}
208+
196209
/**
197210
* Constructs a FileWriterWithEncoding with a file encoding.
198211
*

0 commit comments

Comments
 (0)