harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r396703 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ test/java/tests/api/java/io/
Date Mon, 24 Apr 2006 22:24:24 GMT
Author: gharley
Date: Mon Apr 24 15:24:07 2006
New Revision: 396703

URL: http://svn.apache.org/viewcvs?rev=396703&view=rev
Log:
HARMONY-230 : Some classes in java.io need to implement Appendable interface

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/WriterTest.java   (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringWriter.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Writer.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/AllTests.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StringWriterTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
  * 
  */
 public class CharArrayWriter extends Writer {
+	
 	/**
 	 * Buffer for characters
 	 */
@@ -227,5 +228,73 @@
 		synchronized (lock) {
 			out.write(buf, 0, count);
 		}
+	}
+    
+	/**
+	 * Append a char <code>c</code>to the CharArrayWriter. The
+	 * CharArrayWriter.append(<code>c</code>) works the same way as
+	 * CharArrayWriter.write(<code>c</code>).
+	 * 
+	 * @override Writer.append
+	 * @param c
+	 *            The character appended to the CharArrayWriter.
+	 * @return The CharArrayWriter.
+	 */
+	public CharArrayWriter append(char c) {
+	    write(c);
+	    return this;
+	}
+
+	/**
+	 * Append a CharSequence <code>csq</code> to the CharArrayWriter. The
+	 * CharArrayWriter.append(<code>csq</code>) works the same way as
+	 * CharArrayWriter.write(<code>csq</code>.toString()). If
+	 * <code>csq</code> is null, then then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @override Writer.append
+	 * @param csq
+	 *            The CharSequence appended to the CharArrayWriter.
+	 * @return The CharArrayWriter
+	 */
+	public CharArrayWriter append(CharSequence csq) {
+	    if (null == csq) {
+	        append(TOKEN_NULL, 0, TOKEN_NULL.length());
+	    } else {
+	        append(csq, 0, csq.length());
+	    }
+	    return this;
+	}
+
+	/**
+	 * Append a subsequence of a CharSequence <code>csq</code> to the
+	 * CharArrayWriter. The first char and the last char of the subsequnce is
+	 * specified by the parameter <code>start</code> and <code>end</code>.
+	 * The CharArrayWriter.append(<code>csq</code>) works the same way as
+	 * CharArrayWriter.write(<code>csq</code>.subSequence(<code>start</code>,<code>end</code>).toString).
+	 * If <code>csq</code> is null, then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @override Writer.append
+	 * @param csq
+	 *            The CharSequence appended to the CharArrayWriter.
+	 * @param start
+	 *            The index of the first char in the CharSequence appended to
+	 *            the CharArrayWriter.
+	 * @param end
+	 *            The index of the char after the last one in the CharSequence
+	 *            appended to the CharArrayWriter.
+	 * @return The CharArrayWriter.
+	 * @throws IndexOutOfBoundsException
+	 *             If start is less than end, end is greater than the length of
+	 *             the CharSequence, or start or end is negative.
+	 */
+	public CharArrayWriter append(CharSequence csq, int start, int end) {
+	    if (null == csq) {
+	        csq = TOKEN_NULL;
+	    }
+	    String output = csq.subSequence(start, end).toString();
+	    write(output, 0, output.length());
+	    return this;
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,7 +30,8 @@
  * a problem has been encountered in this Stream.
  * 
  */
-public class PrintStream extends FilterOutputStream {
+public class PrintStream extends FilterOutputStream implements Appendable,
+		Closeable {
 
 	/**
 	 * protect writes to the underlying stream.
@@ -53,6 +54,10 @@
 	private final String lineSeparator = (String) AccessController
 			.doPrivileged(new PriviAction("line.separator")); //$NON-NLS-1$
 
+	static final String TOKEN_NULL = "null"; //$NON-NLS-1$
+
+	// private Formatter formatter;
+
 	/**
 	 * Constructs a new PrintStream on the OutputStream <code>out</code>. All
 	 * writes to the target can now take place through this PrintStream. By
@@ -116,6 +121,95 @@
 	}
 
 	/**
+	 * Constructs a new PrintStream on the file <code>file</code>. All writes
+	 * to the target can now take place through this PrintStream. Its encoding
+	 * character set is the default charset in the VM.
+	 * 
+	 * @param file
+	 *            the file to provide convenience methods on.
+	 * @throws FileNotFoundException
+	 *             if the file does not exist or cannot be opened to write. Or the file cannot be created or any problem when open the file to write.
+	 * @throws SecurityException
+	 *             if the security manager exists and denies the write to the
+	 *             file.
+	 */
+	public PrintStream(File file) throws FileNotFoundException {
+		super(new FileOutputStream(file));
+	}
+
+	/**
+	 * Constructs a new PrintStream on the file <code>file</code>. All writes
+	 * to the target can now take place through this PrintStream. Its encoding
+	 * character set name is <code>csn</code>.
+	 * 
+	 * @param file
+	 *            the file to provide convenience methods on.
+	 * @param csn
+	 *            the character set name
+	 * @throws FileNotFoundException
+	 *             if the file does not exist or cannot be opened to write. Or
+	 *             the file cannot be created or any problem when open the file
+	 *             to write.
+	 * @throws SecurityException
+	 *             if the security manager exists and denies the write to the
+	 *             file.
+	 * @throws UnsupportedEncodingException
+	 *             if the chosen character set is not supported
+	 */
+	public PrintStream(File file, String csn) throws FileNotFoundException,
+			UnsupportedEncodingException {
+		super(new FileOutputStream(file));
+		if (csn == null)
+			throw new NullPointerException();
+		if (!Charset.isSupported(csn))
+			throw new UnsupportedEncodingException();
+		encoding = csn;
+	}
+
+	/**
+	 * Constructs a new PrintStream on the file the name of which is<code>fileName</code>.
+	 * All writes to the target can now take place through this PrintStream. Its
+	 * encoding character set is the default charset in the VM.
+	 * 
+	 * @param file
+	 *            the file to provide convenience methods on.
+	 * @throws FileNotFoundException
+	 *             if the file does not exist or cannot be opened to write. Or
+	 *             the file cannot be created or any problem when open the file
+	 *             to write.
+	 * @throws SecurityException
+	 *             if the security manager exists and denies the write to the
+	 *             file.
+	 */
+	public PrintStream(String fileName) throws FileNotFoundException {
+		this(new File(fileName));
+	}
+
+	/**
+	 * Constructs a new PrintStream on the file the name of which is<code>fileName</code>.
+	 * All writes to the target can now take place through this PrintStream. Its
+	 * encoding character set name is <code>csn</code>.
+	 * 
+	 * @param file
+	 *            the file to provide convenience methods on.
+	 * @param csn
+	 *            the character set name
+	 * @throws FileNotFoundException
+	 *             if the file does not exist or cannot be opened to write. Or
+	 *             the file cannot be created or any problem when open the file
+	 *             to write.
+	 * @throws SecurityException
+	 *             if the security manager exists and denies the write to the
+	 *             file.
+	 * @throws UnsupportedEncodingException
+	 *             if the chosen character set is not supported
+	 */
+	public PrintStream(String fileName, String csn)
+			throws FileNotFoundException, UnsupportedEncodingException {
+		this(new File(fileName), csn);
+	}
+
+	/**
 	 * Answers a boolean indicating whether or not this PrintStream has
 	 * encountered an error. If so, the receiver should probably be closed since
 	 * futher writes will not actually take place. A side effect of calling
@@ -482,5 +576,70 @@
 				setError();
 			}
 		}
+	}
+
+	/**
+	 * Append a char <code>c</code> to the PrintStream. The
+	 * PrintStream.append(<code>c</code>) works the same way as
+	 * PrintStream.print(<code>c</code>).
+	 * 
+	 * @param c
+	 *            The character appended to the PrintStream.
+	 * @return The PrintStream.
+	 */
+	public PrintStream append(char c) {
+		print(c);
+		return this;
+	}
+
+	/**
+	 * Append a CharSequence <code>csq</code> to the PrintStream. The
+	 * PrintStream.append(<code>csq</code>) works the same way as
+	 * PrintStream.print(<code>csq</code>.toString()). If <code>csq</code>
+	 * is null, then a CharSequence just contains then "null" will be
+	 * substituted for <code>csq</code>.
+	 * 
+	 * @param csq
+	 *            The CharSequence appended to the PrintStream.
+	 * @return The PrintStream.
+	 */
+	public PrintStream append(CharSequence csq) {
+		if (null == csq) {
+			print(TOKEN_NULL);
+		} else {
+			print(csq.toString());
+		}
+		return this;
+	}
+
+	/**
+	 * Append a subsequence of a CharSequence <code>csq</code> to the
+	 * PrintStream. The first char and the last char of the subsequnce is
+	 * specified by the parameter <code>start</code> and <code>end</code>.
+	 * The PrintStream.append(<code>csq</code>) works the same way as
+	 * PrintStream.print (<code>csq</code>csq.subSequence(<code>start</code>,<code>end</code>).toString).If
+	 * <code>csq</code> is null, then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @param csq
+	 *            The CharSequence appended to the PrintStream.
+	 * @param start
+	 *            The index of the first char in the CharSequence appended to
+	 *            the PrintStream.
+	 * @param end
+	 *            The index of the char after the last one in the CharSequence
+	 *            appended to the PrintStream.
+	 * @return The PrintStream.
+	 * @throws IndexOutOfBoundsException
+	 *             If start is less than end, end is greater than the length of
+	 *             the CharSequence, or start or end is negative.
+	 */
+	public PrintStream append(CharSequence csq, int start, int end) {
+		if (null == csq) {
+			print(TOKEN_NULL.substring(start, end));
+		} else {
+			print(csq.subSequence(start, end).toString());
+		}
+		return this;
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -473,5 +473,72 @@
 	 */
 	public void write(String str, int offset, int count) {
 		write(str.substring(offset, offset + count).toCharArray());
+	}
+
+	/**
+	 * Append a char <code>c</code>to the PrintWriter. The
+	 * PrintWriter.append(<code>c</code>) works the same way as
+	 * PrintWriter.write(<code>c</code>).
+	 * 
+	 * @override Writer.append
+	 * @param c
+	 *            The character appended to the PrintWriter.
+	 * @return The PrintWriter.
+	 */
+	public PrintWriter append(char c) {
+		write(c);
+		return this;
+	}
+
+	/**
+	 * Append a CharSequence <code>csq</code> to the PrintWriter. The
+	 * PrintWriter.append(<code>csq</code>) works the same way as
+	 * PrintWriter.write(<code>csq</code>.toString()). If <code>csq</code>
+	 * is null, then "null" will be subsituted for <code>csq</code>
+	 * 
+	 * @override Writer.append
+	 * @param csq
+	 *            The CharSequence appended to the PrintWriter.
+	 * @return The PrintWriter
+	 */
+	public PrintWriter append(CharSequence csq) {
+		if (null == csq) {
+			append(TOKEN_NULL, 0, TOKEN_NULL.length());
+		} else {
+			append(csq, 0, csq.length());
+		}
+		return this;
+	}
+
+	/**
+	 * Append a subsequence of a CharSequence <code>csq</code> to the
+	 * PrintWriter. The first char and the last char of the subsequnce is
+	 * specified by the parameter <code>start</code> and <code>end</code>.
+	 * The PrintWriter.append(<code>csq</code>) works the same way as
+	 * PrintWriter.write(<code>csq</code>.subSequence(<code>start</code>,<code>end</code>).toString).If
+	 * <code>csq</code> is null, then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @override Writer.append
+	 * @param csq
+	 *            The CharSequence appended to the PrintWriter.
+	 * @param start
+	 *            The index of the first char in the CharSequence appended to
+	 *            the PrintWriter.
+	 * @param end
+	 *            The index of the char after the last one in the CharSequence
+	 *            appended to the PrintWriter.
+	 * @return The PrintWriter.
+	 * @throws IndexOutOfBoundsException
+	 *             If start is less than end, end is greater than the length of
+	 *             the CharSequence, or start or end is negative.
+	 */
+	public PrintWriter append(CharSequence csq, int start, int end) {
+		if (null == csq) {
+			csq = TOKEN_NULL;
+		}
+		String output = csq.subSequence(start, end).toString();
+		write(output, 0, output.length());
+		return this;
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringWriter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringWriter.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringWriter.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringWriter.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -173,5 +173,72 @@
 		synchronized (lock) {
 			buf.append(sub);
 		}
+	}
+	
+	/**
+	 * Append a char <code>c</code>to the StringWriter. The
+	 * StringWriter.append(<code>c</code>) works the same way as
+	 * StringWriter.write(<code>c</code>).
+	 * 
+	 * @override Writer.append
+	 * @param c
+	 *            The character appended to the StringWriter.
+	 * @return The StringWriter.
+	 */
+	public StringWriter append(char c) {
+		write(c);
+		return this;
+	}
+
+	/**
+	 * Append a CharSequence <code>csq</code> to the StringWriter. The
+	 * StringWriter.append(<code>csq</code>) works the same way as
+	 * StringWriter.write(<code>csq</code>.toString()). If <code>csq</code>
+	 * is null, then "null" will be substituted for <code>csq</code>.
+	 * 
+	 * @override Writer.append
+	 * @param csq
+	 *            The CharSequence appended to the StringWriter.
+	 * @return The StringWriter
+	 */
+	public StringWriter append(CharSequence csq) {
+		if (null == csq) {
+			append(TOKEN_NULL, 0, TOKEN_NULL.length());
+		} else {
+			append(csq, 0, csq.length());
+		}
+		return this;
+	}
+
+	/**
+	 * Append a subsequence of a CharSequence <code>csq</code> to the
+	 * StringWriter. The first char and the last char of the subsequnce is
+	 * specified by the parameter <code>start</code> and <code>end</code>.
+	 * The StringWriter.append(<code>csq</code>) works the same way as
+	 * StringWriter.write(<code>csq</code>.subSequence(<code>start</code>,<code>end</code>).toString).If
+	 * <code>csq</code> is null, then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @override Writer.append
+	 * @param csq
+	 *            The CharSequence appended to the StringWriter.
+	 * @param start
+	 *            The index of the first char in the CharSequence appended to
+	 *            the StringWriter.
+	 * @param end
+	 *            The index of the char after the last one in the CharSequence
+	 *            appended to the StringWriter.
+	 * @return The StringWriter.
+	 * @throws IndexOutOfBoundsException
+	 *             If start is less than end, end is greater than the length of
+	 *             the CharSequence, or start or end is negative.
+	 */
+	public StringWriter append(CharSequence csq, int start, int end) {
+		if (null == csq) {
+			csq = TOKEN_NULL;
+		}
+		String output = csq.subSequence(start, end).toString();
+		write(output, 0, output.length());
+		return this;
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Writer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Writer.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Writer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Writer.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,10 @@
  * 
  * @see Reader
  */
-public abstract class Writer {
+public abstract class Writer implements Appendable, Closeable, Flushable {
+    
+    static final String TOKEN_NULL = "null";
+    
 	/** The object used to synchronize access to the writer. */
 	protected Object lock;
 
@@ -164,4 +167,74 @@
 		} else
 			throw new StringIndexOutOfBoundsException();
 	}
+
+	/**
+	 * Append a char <code>c</code>to the Writer. The Writer.append(<code>c</code>)
+	 * works the same as Writer.write(<code>c</code>).
+	 * 
+	 * @param c
+	 *            The character appended to the Writer.
+	 * @return The Writer.
+	 * @throws IOException
+	 *             If any IOException raises during the procedure.
+	 */
+	public Writer append(char c) throws IOException {
+		write(c);
+		return this;
+	}
+
+	/**
+	 * Append a CharSequence <code>csq</code> to the Writer. The
+	 * Writer.append(<code>csq</code>) works the same way as Writer.write(<code>csq</code>.toString()).
+	 * If <code>csq</code> is null, then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @param csq
+	 *            The CharSequence appended to the Writer.
+	 * @return The Writer.
+	 * @throws IOException
+	 *             If any IOException raises during the procedure.
+	 */
+	public Writer append(CharSequence csq) throws IOException {
+		if (null == csq) {
+			write(TOKEN_NULL);
+		} else {
+			write(csq.toString());
+		}
+		return this;
+	}
+
+	/**
+	 * Append a subsequence of a CharSequence <code>csq</code> to the Writer.
+	 * The first char and the last char of the subsequnce is specified by the
+	 * parameter <code>start</code> and <code>end</code>. The
+	 * Writer.append(<code>csq</code>) works the same way as Writer.write (<code>csq</code>csq.subSequence(<code>start</code>,<code>end</code>).toString).
+	 * If <code>csq</code> is null, then "null" will be substituted for
+	 * <code>csq</code>.
+	 * 
+	 * @param csq
+	 *            The CharSequence appended to the Writaer.
+	 * @param start
+	 *            The index of the first char in the CharSequence appended to
+	 *            the Writer.
+	 * @param end
+	 *            The index of the char after the last one in the CharSequence
+	 *            appended to the Writer.
+	 * @return The Writer.
+	 * @throws IndexOutOfBoundsException
+	 *             If start is less than end, end is greater than the length of
+	 *             the CharSequence, or start or end is negative.
+	 * @throws IOException
+	 *             If any IOException raises during the procedure.
+	 */
+	public Writer append(CharSequence csq, int start, int end)
+			throws IOException {
+		if (null == csq) {
+			write(TOKEN_NULL.substring(start, end));
+		} else {
+			write(csq.subSequence(start, end).toString());
+		}
+		return this;
+	}
+
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/AllTests.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/AllTests.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -84,6 +84,7 @@
 		suite.addTestSuite(UTFDataFormatExceptionTest.class);
 		suite.addTestSuite(WriteAbortedExceptionTest.class);
 		suite.addTestSuite(SerializationStressTest.class);
+		suite.addTestSuite(WriterTest.class);
 		// $JUnit-END$
 
 		return suite;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,118 +22,118 @@
 
 public class CharArrayWriterTest extends junit.framework.TestCase {
 
-	char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
+    char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
 
-	CharArrayWriter cw;
+    CharArrayWriter cw;
 
-	CharArrayReader cr;
+    CharArrayReader cr;
 
-	/**
-	 * @tests java.io.CharArrayWriter#CharArrayWriter()
-	 */
-	public void test_Constructor() {
-		// Test for method java.io.CharArrayWriter()
-		cw = new CharArrayWriter(90);
-		assertTrue("Created incorrect writer", cw.size() == 0);
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#CharArrayWriter(int)
-	 */
-	public void test_ConstructorI() {
-		// Test for method java.io.CharArrayWriter(int)
-		cw = new CharArrayWriter();
-		assertTrue("Created incorrect writer", cw.size() == 0);
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#close()
-	 */
-	public void test_close() {
-		// Test for method void java.io.CharArrayWriter.close()
-		cw.close();
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#flush()
-	 */
-	public void test_flush() {
-		// Test for method void java.io.CharArrayWriter.flush()
-		cw.flush();
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#reset()
-	 */
-	public void test_reset() {
-		// Test for method void java.io.CharArrayWriter.reset()
-		cw.write("HelloWorld", 5, 5);
-		cw.reset();
-		cw.write("HelloWorld", 0, 5);
-		cr = new CharArrayReader(cw.toCharArray());
-		try {
-			char[] c = new char[100];
-			cr.read(c, 0, 5);
-			assertTrue("Reset failed to reset buffer", "Hello"
-					.equals(new String(c, 0, 5)));
-		} catch (IOException e) {
-			fail("Exception during reset test : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#size()
-	 */
-	public void test_size() {
-		// Test for method int java.io.CharArrayWriter.size()
-		assertTrue("Returned incorrect size", cw.size() == 0);
-		cw.write(hw, 5, 5);
-		assertTrue("Returned incorrect size", cw.size() == 5);
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#toCharArray()
-	 */
-	public void test_toCharArray() {
-		// Test for method char [] java.io.CharArrayWriter.toCharArray()
-		cw.write("HelloWorld", 0, 10);
-		cr = new CharArrayReader(cw.toCharArray());
-		try {
-			char[] c = new char[100];
-			cr.read(c, 0, 10);
-			assertTrue("toCharArray failed to return correct array",
-					"HelloWorld".equals(new String(c, 0, 10)));
-		} catch (IOException e) {
-			fail("Exception during toCharArray test : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#toString()
-	 */
-	public void test_toString() {
-		// Test for method java.lang.String java.io.CharArrayWriter.toString()
-		cw.write("HelloWorld", 5, 5);
-		cr = new CharArrayReader(cw.toCharArray());
-		assertTrue("Returned incorrect string", "World".equals(cw.toString()));
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#write(char[], int, int)
-	 */
-	public void test_write$CII() {
-		// Test for method void java.io.CharArrayWriter.write(char [], int, int)
-		cw.write(hw, 5, 5);
-		cr = new CharArrayReader(cw.toCharArray());
-		try {
-			char[] c = new char[100];
-			cr.read(c, 0, 5);
-			assertTrue("Writer failed to write correct chars", "World"
-					.equals(new String(c, 0, 5)));
-		} catch (IOException e) {
-			fail("Exception during write test : " + e.getMessage());
-		}
-	}
+    /**
+     * @tests java.io.CharArrayWriter#CharArrayWriter()
+     */
+    public void test_Constructor() {
+        // Test for method java.io.CharArrayWriter()
+        cw = new CharArrayWriter(90);
+        assertTrue("Created incorrect writer", cw.size() == 0);
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#CharArrayWriter(int)
+     */
+    public void test_ConstructorI() {
+        // Test for method java.io.CharArrayWriter(int)
+        cw = new CharArrayWriter();
+        assertTrue("Created incorrect writer", cw.size() == 0);
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#close()
+     */
+    public void test_close() {
+        // Test for method void java.io.CharArrayWriter.close()
+        cw.close();
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#flush()
+     */
+    public void test_flush() {
+        // Test for method void java.io.CharArrayWriter.flush()
+        cw.flush();
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#reset()
+     */
+    public void test_reset() {
+        // Test for method void java.io.CharArrayWriter.reset()
+        cw.write("HelloWorld", 5, 5);
+        cw.reset();
+        cw.write("HelloWorld", 0, 5);
+        cr = new CharArrayReader(cw.toCharArray());
+        try {
+            char[] c = new char[100];
+            cr.read(c, 0, 5);
+            assertTrue("Reset failed to reset buffer", "Hello"
+                    .equals(new String(c, 0, 5)));
+        } catch (IOException e) {
+            fail("Exception during reset test : " + e.getMessage());
+        }
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#size()
+     */
+    public void test_size() {
+        // Test for method int java.io.CharArrayWriter.size()
+        assertTrue("Returned incorrect size", cw.size() == 0);
+        cw.write(hw, 5, 5);
+        assertTrue("Returned incorrect size", cw.size() == 5);
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#toCharArray()
+     */
+    public void test_toCharArray() {
+        // Test for method char [] java.io.CharArrayWriter.toCharArray()
+        cw.write("HelloWorld", 0, 10);
+        cr = new CharArrayReader(cw.toCharArray());
+        try {
+            char[] c = new char[100];
+            cr.read(c, 0, 10);
+            assertTrue("toCharArray failed to return correct array",
+                    "HelloWorld".equals(new String(c, 0, 10)));
+        } catch (IOException e) {
+            fail("Exception during toCharArray test : " + e.getMessage());
+        }
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#toString()
+     */
+    public void test_toString() {
+        // Test for method java.lang.String java.io.CharArrayWriter.toString()
+        cw.write("HelloWorld", 5, 5);
+        cr = new CharArrayReader(cw.toCharArray());
+        assertTrue("Returned incorrect string", "World".equals(cw.toString()));
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#write(char[], int, int)
+     */
+    public void test_write$CII() {
+        // Test for method void java.io.CharArrayWriter.write(char [], int, int)
+        cw.write(hw, 5, 5);
+        cr = new CharArrayReader(cw.toCharArray());
+        try {
+            char[] c = new char[100];
+            cr.read(c, 0, 5);
+            assertTrue("Writer failed to write correct chars", "World"
+                    .equals(new String(c, 0, 5)));
+        } catch (IOException e) {
+            fail("Exception during write test : " + e.getMessage());
+        }
+    }
 
     /**
      * @tests java.io.CharArrayWriter#write(char[], int, int)
@@ -151,37 +151,37 @@
         }
     }
 
-	/**
-	 * @tests java.io.CharArrayWriter#write(int)
-	 */
-	public void test_writeI() {
-		// Test for method void java.io.CharArrayWriter.write(int)
-		cw.write('T');
-		cr = new CharArrayReader(cw.toCharArray());
-		try {
-			assertTrue("Writer failed to write char", cr.read() == 'T');
-		} catch (IOException e) {
-			fail("Exception during write test : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
-	 */
-	public void test_writeLjava_lang_StringII() {
-		// Test for method void java.io.CharArrayWriter.write(java.lang.String,
-		// int, int)
-		cw.write("HelloWorld", 5, 5);
-		cr = new CharArrayReader(cw.toCharArray());
-		try {
-			char[] c = new char[100];
-			cr.read(c, 0, 5);
-			assertTrue("Writer failed to write correct chars", "World"
-					.equals(new String(c, 0, 5)));
-		} catch (IOException e) {
-			fail("Exception during write test : " + e.getMessage());
-		}
-	}
+    /**
+     * @tests java.io.CharArrayWriter#write(int)
+     */
+    public void test_writeI() {
+        // Test for method void java.io.CharArrayWriter.write(int)
+        cw.write('T');
+        cr = new CharArrayReader(cw.toCharArray());
+        try {
+            assertTrue("Writer failed to write char", cr.read() == 'T');
+        } catch (IOException e) {
+            fail("Exception during write test : " + e.getMessage());
+        }
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
+     */
+    public void test_writeLjava_lang_StringII() {
+        // Test for method void java.io.CharArrayWriter.write(java.lang.String,
+        // int, int)
+        cw.write("HelloWorld", 5, 5);
+        cr = new CharArrayReader(cw.toCharArray());
+        try {
+            char[] c = new char[100];
+            cr.read(c, 0, 5);
+            assertTrue("Writer failed to write correct chars", "World"
+                    .equals(new String(c, 0, 5)));
+        } catch (IOException e) {
+            fail("Exception during write test : " + e.getMessage());
+        }
+    }
 
     /**
      * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
@@ -196,37 +196,76 @@
         }
     }
 
-	/**
-	 * @tests java.io.CharArrayWriter#writeTo(java.io.Writer)
-	 */
-	public void test_writeToLjava_io_Writer() {
-		// Test for method void java.io.CharArrayWriter.writeTo(java.io.Writer)
-		cw.write("HelloWorld", 0, 10);
-		StringWriter sw = new StringWriter();
-		try {
-			cw.writeTo(sw);
-			assertTrue("Writer failed to write correct chars", "HelloWorld"
-					.equals(sw.toString()));
-		} catch (IOException e) {
-			fail("Exception during writeTo test : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-		cw = new CharArrayWriter();
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-		if (cr != null)
-			cr.close();
-		cw.close();
-	}
+    /**
+     * @tests java.io.CharArrayWriter#writeTo(java.io.Writer)
+     */
+    public void test_writeToLjava_io_Writer() {
+        // Test for method void java.io.CharArrayWriter.writeTo(java.io.Writer)
+        cw.write("HelloWorld", 0, 10);
+        StringWriter sw = new StringWriter();
+        try {
+            cw.writeTo(sw);
+            assertTrue("Writer failed to write correct chars", "HelloWorld"
+                    .equals(sw.toString()));
+        } catch (IOException e) {
+            fail("Exception during writeTo test : " + e.getMessage());
+        }
+    }
+
+    /**
+     * Sets up the fixture, for example, open a network connection. This method
+     * is called before a test is executed.
+     */
+    protected void setUp() {
+        cw = new CharArrayWriter();
+    }
+
+    /**
+     * Tears down the fixture, for example, close a network connection. This
+     * method is called after a test is executed.
+     */
+    protected void tearDown() {
+        if (cr != null)
+            cr.close();
+        cw.close();
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#append(char)
+     */
+    public void test_appendChar() throws IOException {
+        char testChar = ' ';
+        CharArrayWriter writer = new CharArrayWriter(10);
+        writer.append(testChar);
+        writer.flush();
+        assertEquals(String.valueOf(testChar), writer.toString());
+        writer.close();
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#append(CharSequence)
+     */
+    public void test_appendCharSequence() {
+
+        String testString = "My Test String";
+        CharArrayWriter writer = new CharArrayWriter(10);
+        writer.append(testString);
+        writer.flush();
+        assertEquals(testString, writer.toString());
+        writer.close();
+    }
+
+    /**
+     * @tests java.io.CharArrayWriter#append(CharSequence, int, int)
+     */
+    public void test_appendCharSequenceIntInt() {
+        String testString = "My Test String";
+        CharArrayWriter writer = new CharArrayWriter(10);
+        writer.append(testString, 1, 3);
+        writer.flush();
+        assertEquals(testString.substring(1, 3), writer.toString());
+        writer.close();
+
+    }
+
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,8 +15,10 @@
 
 package tests.api.java.io;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.PrintStream;
 
 public class PrintStreamTest extends junit.framework.TestCase {
 
@@ -500,6 +502,47 @@
 		os.write('t');
 		bis = new java.io.ByteArrayInputStream(bos.toByteArray());
 		assertTrue("Incorrect char written", bis.read() == 't');
+	}
+	
+	
+	/**
+	 * @tests java.io.PrintStream#append(char)
+	 */
+	public void test_appendChar() throws IOException{
+	char testChar = ' ';
+	ByteArrayOutputStream out = new ByteArrayOutputStream();
+	PrintStream printStream = new PrintStream(out);
+	printStream.append(testChar);
+	printStream.flush();
+	assertEquals(String.valueOf(testChar),out.toString());
+	printStream.close();
+	}
+	/**
+	 * @tests java.io.PrintStream#append(CharSequence)
+	 */
+	public void test_appendCharSequence() {
+		
+		String testString = "My Test String";
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		PrintStream printStream = new PrintStream(out);
+		printStream.append(testString);
+		printStream.flush();
+		assertEquals(testString, out.toString());
+		printStream.close();
+	}
+
+	/**
+	 *  @tests java.io.PrintStream#append(CharSequence, int, int)
+	 */
+	public void test_appendCharSequenceIntInt() {
+		String testString = "My Test String";
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		PrintStream printStream = new PrintStream(out);
+		printStream.append(testString, 1, 3);
+		printStream.flush();
+		assertEquals(testString.substring(1, 3), out.toString());
+		printStream.close();
+
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -582,6 +582,47 @@
 			fail("IOException during test : " + e.getMessage());
 		}
 		assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
+	}
+	
+	/**
+	 * @tests java.io.PrintWriter#append(char)
+	 */
+	public void test_appendChar() {
+	char testChar = ' ';
+	ByteArrayOutputStream out = new ByteArrayOutputStream();
+	PrintWriter printWriter = new PrintWriter(out);
+	printWriter.append(testChar);
+	printWriter.flush();
+	assertEquals(String.valueOf(testChar),out.toString());
+	printWriter.close();
+	}
+	/**
+	 * @tests java.io.PrintWriter#append(CharSequence)
+	 */
+	public void test_appendCharSequence() {
+		
+		String testString = "My Test String";
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		PrintWriter printWriter = new PrintWriter(out);
+		printWriter.append(testString);
+		printWriter.flush();
+		assertEquals(testString, out.toString());
+		printWriter.close();	
+
+	}
+
+	/**
+	 *  @tests java.io.PrintWriter#append(CharSequence, int, int)
+	 */
+	public void test_appendCharSequenceIntInt() {
+		String testString = "My Test String";
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		PrintWriter printWriter = new PrintWriter(out);
+		printWriter.append(testString, 1, 3);
+		printWriter.flush();
+		assertEquals(testString.substring(1, 3), out.toString());
+		printWriter.close();
+
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StringWriterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StringWriterTest.java?rev=396703&r1=396702&r2=396703&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StringWriterTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StringWriterTest.java Mon Apr 24 15:24:07 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -162,11 +162,46 @@
 		sw.write("This is a test string", 2, 2);
 		assertTrue("String not written properly", sw.toString().equals("is"));
 	}
+    
+	/**
+	 * @tests java.io.StringWriter#append(char)
+	 */
+	public void test_appendChar() throws IOException {
+	    char testChar = ' ';
+	    StringWriter stringWriter = new StringWriter(20);
+	    stringWriter.append(testChar);
+	    assertEquals(String.valueOf(testChar), stringWriter.toString());
+	    stringWriter.close();
+	}
+
+	/**
+	 * @tests java.io.PrintWriter#append(CharSequence)
+	 */
+	public void test_appendCharSequence() throws IOException {
+
+	    String testString = "My Test String";
+	    StringWriter stringWriter = new StringWriter(20);
+	    stringWriter.append(testString);
+	    assertEquals(String.valueOf(testString), stringWriter.toString());
+	    stringWriter.close();
+	}
 
 	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
+	 * @tests java.io.PrintWriter#append(CharSequence, int, int)
 	 */
+	public void test_appendCharSequenceIntInt() throws IOException {
+	    String testString = "My Test String";
+	    StringWriter stringWriter = new StringWriter(20);
+	    stringWriter.append(testString, 1, 3);
+	    assertEquals(testString.substring(1, 3), stringWriter.toString());
+	    stringWriter.close();
+
+	}
+    
+	/**
+     * Sets up the fixture, for example, open a network connection. This method
+     * is called before a test is executed.
+     */
 	protected void setUp() {
 
 		sw = new StringWriter();

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/WriterTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/WriterTest.java?rev=396703&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/WriterTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/WriterTest.java Mon Apr 24 15:24:07 2006
@@ -0,0 +1,109 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.io;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import junit.framework.TestCase;
+
+public class WriterTest extends TestCase {
+
+    /**
+     * @tests java.io.Writer#append(char)
+     */
+    public void test_appendChar() throws IOException {
+        char testChar = ' ';
+        MockWriter writer = new MockWriter(20);
+        writer.append(testChar);
+        assertEquals(String.valueOf(testChar), String.valueOf(writer
+                .getContents()));
+        writer.close();
+    }
+
+    /**
+     * @tests java.io.Writer#append(CharSequence)
+     */
+    public void test_appendCharSequence() throws IOException {
+        String testString = "My Test String";
+        MockWriter writer = new MockWriter(20);
+        writer.append(testString);
+        assertEquals(testString, String.valueOf(writer.getContents()));
+        writer.close();
+
+    }
+
+    /**
+     * @tests java.io.Writer#append(CharSequence, int, int)
+     */
+    public void test_appendCharSequenceIntInt() throws IOException {
+        String testString = "My Test String";
+        MockWriter writer = new MockWriter(20);
+        writer.append(testString, 1, 3);
+        assertEquals(testString.substring(1, 3), String.valueOf(writer
+                .getContents()));
+        writer.close();
+
+    }
+
+    class MockWriter extends Writer {
+        private char[] contents;
+
+        private int length;
+
+        private int offset;
+
+        MockWriter(int capacity) {
+            contents = new char[capacity];
+            length = capacity;
+            offset = 0;
+        }
+
+        public synchronized void close() throws IOException {
+            flush();
+            contents = null;
+        }
+
+        public synchronized void flush() throws IOException {
+            // do nothing
+        }
+
+        public void write(char[] buffer, int offset, int count)
+                throws IOException {
+            if (null == contents) {
+                throw new IOException();
+            }
+            if (offset < 0 || count < 0 || offset >= buffer.length) {
+                throw new IndexOutOfBoundsException();
+            }
+            count = Math.min(count, buffer.length - offset);
+            count = Math.min(count, this.length - this.offset);
+            for (int i = 0; i < count; i++) {
+                contents[this.offset + i] = buffer[offset + i];
+            }
+            this.offset += count;
+
+        }
+
+        public char[] getContents() {
+            char[] result = new char[offset];
+            for (int i = 0; i < offset; i++) {
+                result[i] = contents[i];
+            }
+            return result;
+        }
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/WriterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message