2222 * instead may target another system.
2323 *
2424 */
25- public interface SimpleWriter {
25+ public interface SimpleWriter extends Appendable {
2626
2727 /**
2828 * Write a newline according to the characteristics of the target platform.
@@ -40,6 +40,21 @@ public interface SimpleWriter {
4040 */
4141 void write (CharSequence seq ) throws IOException ;
4242
43+ @ Override
44+ default SimpleWriter append (CharSequence csq ) throws IOException {
45+ write (csq );
46+ return this ;
47+ }
48+
49+ @ Override
50+ default SimpleWriter append (CharSequence csq , int start , int end ) throws IOException {
51+ if (csq == null ) {
52+ csq = "null" ;
53+ }
54+ write (csq .subSequence (start , end ));
55+ return this ;
56+ }
57+
4358 /**
4459 * Write a sequence of characters from an array.
4560 *
@@ -64,6 +79,12 @@ public interface SimpleWriter {
6479 */
6580 void write (char c ) throws IOException ;
6681
82+ @ Override
83+ default SimpleWriter append (char c ) throws IOException {
84+ write (c );
85+ return this ;
86+ }
87+
6788 /**
6889 * Write an integer.
6990 *
@@ -72,6 +93,47 @@ public interface SimpleWriter {
7293 * @throws IOException
7394 * if an error happens when writing.
7495 */
75- void write (int num ) throws IOException ;
96+ default void write (int num ) throws IOException {
97+ write (Integer .toString (num ));
98+ }
99+
100+ /**
101+ * Remove the last character found in this buffer, if any.
102+ * <p>
103+ * Optional operation.
104+ * </p>
105+ *
106+ * @throws UnsupportedOperationException if the operation is not supported.
107+ */
108+ default void unwrite () throws UnsupportedOperationException {
109+ throw new UnsupportedOperationException ("Cannot unwrite." );
110+ }
111+
112+ /**
113+ * Remove the last <code>numChars</code> characters found in this buffer.
114+ * <p>
115+ * If <code>numChars</code> is larger than the length of this buffer, removes
116+ * all its contents.
117+ *
118+ * @param numChars the number of characters to remove.
119+ * @throws UnsupportedOperationException if the operation is not supported.
120+ */
121+ default void unwrite (int numChars ) throws UnsupportedOperationException {
122+ throw new UnsupportedOperationException ("Cannot unwrite." );
123+ }
124+
125+ /**
126+ * Get the last character processed.
127+ * <p>
128+ * Optional operation.
129+ * </p>
130+ *
131+ * @return the last character processed.
132+ * @throws UnsupportedOperationException if the operation is not supported.
133+ * @throws IllegalStateException if no character was processed yet.
134+ */
135+ default char getLastChar () throws UnsupportedOperationException , IllegalStateException {
136+ throw new UnsupportedOperationException ("Cannot retrieve the last character." );
137+ }
76138
77139}
0 commit comments