Skip to content

Commit 279e5a9

Browse files
committed
Applying patch #17677. Remove the Writer API in favour of the PrintWriter API it is using elsewhere anyway - with the advantage that the IOException throws go away
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@384140 13f79535-47bb-0310-9956-ffa450edef68
1 parent e2e9472 commit 279e5a9

2 files changed

Lines changed: 12 additions & 29 deletions

File tree

src/java/org/apache/commons/cli2/util/HelpFormatter.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package org.apache.commons.cli2.util;
1717

18-
import java.io.IOException;
1918
import java.io.PrintWriter;
20-
import java.io.Writer;
2119

2220
import java.util.ArrayList;
2321
import java.util.Collections;
@@ -156,10 +154,8 @@ public HelpFormatter(final String gutterLeft,
156154

157155
/**
158156
* Prints the Option help.
159-
* @throws IOException if an error occurs
160157
*/
161-
public void print()
162-
throws IOException {
158+
public void print() {
163159
printHeader();
164160
printException();
165161
printUsage();
@@ -170,10 +166,8 @@ public void print()
170166

171167
/**
172168
* Prints any error message.
173-
* @throws IOException if an error occurs
174169
*/
175-
public void printException()
176-
throws IOException {
170+
public void printException() {
177171
if (exception != null) {
178172
printDivider();
179173
printWrapped(exception.getMessage());
@@ -182,10 +176,8 @@ public void printException()
182176

183177
/**
184178
* Prints detailed help per option.
185-
* @throws IOException if an error occurs
186179
*/
187-
public void printHelp()
188-
throws IOException {
180+
public void printHelp() {
189181
printDivider();
190182

191183
final Option option;
@@ -253,10 +245,8 @@ public void printHelp()
253245

254246
/**
255247
* Prints a single line of usage information (wrapping if necessary)
256-
* @throws IOException if an error occurs
257248
*/
258-
public void printUsage()
259-
throws IOException {
249+
public void printUsage() {
260250
printDivider();
261251

262252
final StringBuffer buffer = new StringBuffer("Usage:\n");
@@ -267,10 +257,8 @@ public void printUsage()
267257

268258
/**
269259
* Prints a header string if necessary
270-
* @throws IOException if an error occurs
271260
*/
272-
public void printHeader()
273-
throws IOException {
261+
public void printHeader() {
274262
if (header != null) {
275263
printDivider();
276264
printWrapped(header);
@@ -279,10 +267,8 @@ public void printHeader()
279267

280268
/**
281269
* Prints a footer string if necessary
282-
* @throws IOException if an error occurs
283270
*/
284-
public void printFooter()
285-
throws IOException {
271+
public void printFooter() {
286272
if (footer != null) {
287273
printWrapped(footer);
288274
printDivider();
@@ -292,10 +278,8 @@ public void printFooter()
292278
/**
293279
* Prints a string wrapped if necessary
294280
* @param text the string to wrap
295-
* @throws IOException if an error occurs
296281
*/
297-
protected void printWrapped(final String text)
298-
throws IOException {
282+
protected void printWrapped(final String text) {
299283
for (final Iterator i = wrap(text, pageWidth).iterator(); i.hasNext();) {
300284
printGutterLeft();
301285
pad((String) i.next(), pageWidth, out);
@@ -333,8 +317,7 @@ public void printDivider() {
333317

334318
protected static void pad(final String text,
335319
final int width,
336-
final Writer writer)
337-
throws IOException {
320+
final PrintWriter writer) {
338321
final int left;
339322

340323
// write the text and record how many characters written

src/test/org/apache/commons/cli2/util/HelpFormatterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,28 +414,28 @@ public void testWrap_Below1Length() {
414414
public void testPad()
415415
throws IOException {
416416
final StringWriter writer = new StringWriter();
417-
HelpFormatter.pad("hello", 10, writer);
417+
HelpFormatter.pad("hello", 10, new PrintWriter(writer));
418418
assertEquals("hello ", writer.toString());
419419
}
420420

421421
public void testPad_Null()
422422
throws IOException {
423423
final StringWriter writer = new StringWriter();
424-
HelpFormatter.pad(null, 10, writer);
424+
HelpFormatter.pad(null, 10, new PrintWriter(writer));
425425
assertEquals(" ", writer.toString());
426426
}
427427

428428
public void testPad_TooLong()
429429
throws IOException {
430430
final StringWriter writer = new StringWriter();
431-
HelpFormatter.pad("hello world", 10, writer);
431+
HelpFormatter.pad("hello world", 10, new PrintWriter(writer));
432432
assertEquals("hello world", writer.toString());
433433
}
434434

435435
public void testPad_TooShort()
436436
throws IOException {
437437
final StringWriter writer = new StringWriter();
438-
HelpFormatter.pad("hello world", -5, writer);
438+
HelpFormatter.pad("hello world", -5, new PrintWriter(writer));
439439
assertEquals("hello world", writer.toString());
440440
}
441441

0 commit comments

Comments
 (0)