Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.0-JSR-5
-
Fix Version/s: 1.0-JSR-6
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
This means that writing a Writable object to a file using << or append() does not work on Writable objects
Here is a patch that implements the functionality for objects, and differentiates between Writables (calling the writeTo()-method) and others (calling the toString()-method if necessary) ...
Only DefaultGroovyMethods.java is involved.
Cheers, Joe
5273c5273
< public static File leftShift(File file, String text) throws IOException {
—
> public static File leftShift(File file, Object text) throws IOException {
5299,5302c5299,5305
< public static void append(File file, String text) throws IOException {
< BufferedWriter writer = newWriter(file, true);
< writer.write(text);
< writer.close();
—
> public static void append(File file, Object text) throws IOException {
> BufferedWriter writer = newWriter(file, true);
> if(text instanceof Writable)
> ((Writable)text).writeTo(writer);
> else
> writer.write(text.toString());
> writer.close();
5304d5306
<