You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/06/02 10:28:50 UTC
svn commit: r411086 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/io/ main/java/org/apache/harmony/luni/util/
test/java/tests/api/java/io/
Author: mloenko
Date: Fri Jun 2 01:28:50 2006
New Revision: 411086
URL: http://svn.apache.org/viewvc?rev=411086&view=rev
Log:
fixes for HARMONY-515
[classlib][luni] java.io: missing 8 methods and 4 constructors in PrintWriter and PrintStream
Modified:
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/org/apache/harmony/luni/util/ExternalMessages.properties
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
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintStream.java?rev=411086&r1=411085&r2=411086&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 Fri Jun 2 01:28:50 2006
@@ -18,7 +18,11 @@
import java.nio.charset.Charset;
import java.security.AccessController;
+import java.util.Formatter;
+import java.util.IllegalFormatException;
+import java.util.Locale;
+import org.apache.harmony.luni.util.Msg;
import org.apache.harmony.luni.util.PriviAction;
/**
@@ -262,6 +266,112 @@
}
setError();
}
+
+ /**
+ * Writes a string formatted by an intermediate <code>Formatter</code>
+ * to this stream using the given format string and arguments.
+ * <p>
+ * The method uses the default for the current JVM instance locale, as if
+ * it is specified by the <code>Locale.getDefault()</code> call.
+ *
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This stream.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintStream format(String format, Object... args) {
+ return format(Locale.getDefault(), format, args);
+ }
+
+ /**
+ * Writes a string formatted by an intermediate <code>Formatter</code>
+ * to this stream using the given format string and arguments.
+ *
+ * @param l
+ * The locale used in the method. If locale is null, then no
+ * localization will be applied.
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This stream.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintStream format(Locale l, String format, Object... args) {
+ if (format == null) {
+ throw new NullPointerException(Msg.getString("K0351")); //$NON-NLS-1$
+ }
+ new Formatter(this, l).format(format, args);
+ return this;
+ }
+
+ /**
+ * Prints a formatted string. The behavior of this method is the same
+ * as this stream's <code>format(String format, Object... args)</code>
+ * method.
+ * <p>
+ * The method uses the default for the current JVM instance locale, as if
+ * it is specified by the <code>Locale.getDefault()</code> call.
+ *
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This stream.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintStream printf(String format, Object... args) {
+ return format(format, args);
+ }
+
+ /**
+ * Prints a formatted string. The behavior of this method is the same
+ * as this writer's
+ * <code>format(Locale l, String format, Object... args)</code> method.
+ *
+ * @param l
+ * The locale used in the method. If locale is null, then no
+ * localization will be applied.
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This stream.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintStream printf(Locale l, String format, Object... args) {
+ return format(l, format, args);
+ }
private void newline() {
print(lineSeparator);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PrintWriter.java?rev=411086&r1=411085&r2=411086&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 Fri Jun 2 01:28:50 2006
@@ -17,7 +17,11 @@
import java.security.AccessController;
+import java.util.Formatter;
+import java.util.IllegalFormatException;
+import java.util.Locale;
+import org.apache.harmony.luni.util.Msg;
import org.apache.harmony.luni.util.PriviAction;
/**
@@ -107,7 +111,91 @@
out = wr;
}
- /**
+ /**
+ * Constructs a new PrintWriter on the File <code>file</code>. The
+ * automatic flushing is set to <code>false</code>. An intermediate
+ * <code>OutputStreamWriter</code> will use the default for the current JVM
+ * instance charset to encode characters.
+ *
+ * @param file
+ * This writer's buffered destination.
+ * @throws FileNotFoundException
+ * If there is no such a file or some other error occurs
+ * due to the given file opening.
+ */
+ public PrintWriter(File file) throws FileNotFoundException {
+ this(new OutputStreamWriter(
+ new BufferedOutputStream(new FileOutputStream(file))),
+ false);
+ }
+
+ /**
+ * Constructs a new PrintWriter on the File <code>file</code>. The
+ * automatic flushing is set to <code>false</code>. An intermediate
+ * <code>OutputStreamWriter</code> will use a charset with the
+ * given name <code>csn</code> to encode characters.
+ *
+ * @param file
+ * This writer's buffered destination.
+ * @param csn
+ * A charset name.
+ * @throws FileNotFoundException
+ * If there is no such a file or some other error occurs
+ * due to the given file opening.
+ * @throws UnsupportedEncodingException
+ * If a charset with the given name is not supported.
+ */
+ public PrintWriter(File file, String csn)
+ throws FileNotFoundException, UnsupportedEncodingException {
+ this(new OutputStreamWriter(
+ new BufferedOutputStream(new FileOutputStream(file)), csn),
+ false);
+ }
+
+ /**
+ * Constructs a new PrintWriter on a file with the given file name
+ * <code>fileName</code>. The automatic flushing is set to
+ * <code>false</code>. An intermediate <code>OutputStreamWriter</code>
+ * will use the default for the current JVM instance charset to
+ * encode characters.
+ *
+ * @param fileName
+ * The name of file which is this writer's buffered destination.
+ * @throws FileNotFoundException
+ * If there is no such a file or some other error occurs
+ * due to the given file opening.
+ */
+ public PrintWriter(String fileName) throws FileNotFoundException {
+ this(new OutputStreamWriter(
+ new BufferedOutputStream(new FileOutputStream(fileName))),
+ false);
+ }
+
+ /**
+ * Constructs a new PrintWriter on a file with the given file name
+ * <code>fileName</code>. The automatic flushing is set to
+ * <code>false</code>. An intermediate <code>OutputStreamWriter</code>
+ * will use a charset with the given name <code>csn</code> to
+ * encode characters.
+ *
+ * @param fileName
+ * The name of file which is this writer's buffered destination.
+ * @param csn
+ * A charset name.
+ * @throws FileNotFoundException
+ * If there is no such a file or some other error occurs
+ * due to the given file opening.
+ * @throws UnsupportedEncodingException
+ * If a charset with the given name is not supported.
+ */
+ public PrintWriter(String fileName, String csn)
+ throws FileNotFoundException, UnsupportedEncodingException {
+ this(new OutputStreamWriter(
+ new BufferedOutputStream(new FileOutputStream(fileName)), csn),
+ false);
+ }
+
+ /**
* Answers a boolean indicating whether or not this PrintWriter 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
@@ -158,6 +246,119 @@
}
}
}
+
+ /**
+ * Writes a string formatted by an intermediate <code>Formatter</code>
+ * to this writer using the given format string and arguments. A call to
+ * this method flushes the buffered output, if the automatic flushing
+ * is enabled.
+ * <p>
+ * The method uses the default for the current JVM instance locale, as if
+ * it is specified by the <code>Locale.getDefault()</code> call.
+ *
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This writer.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintWriter format(String format, Object... args) {
+ return format(Locale.getDefault(), format, args);
+ }
+
+ /**
+ * Writes a string formatted by an intermediate <code>Formatter</code>
+ * to this writer using the given format string and arguments. A call to
+ * this method flushes the buffered output, if the automatic flushing
+ * is enabled.
+ *
+ * @param l
+ * The locale used in the method. If locale is null, then no
+ * localization will be applied.
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This writer.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintWriter format(Locale l, String format, Object... args) {
+ if (format == null) {
+ throw new NullPointerException(Msg.getString("K0351")); //$NON-NLS-1$
+ }
+ new Formatter(this, l).format(format, args);
+ if (autoflush) {
+ flush();
+ }
+ return this;
+ }
+
+ /**
+ * Prints a formatted string. The behavior of this method is the same
+ * as this writer's <code>format(String format, Object... args)</code>
+ * method.
+ * <p>
+ * The method uses the default for the current JVM instance locale, as if
+ * it is specified by the <code>Locale.getDefault()</code> call.
+ *
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return This writer.
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintWriter printf(String format, Object... args) {
+ return format(format, args);
+ }
+
+ /**
+ * Prints a formatted string. The behavior of this method is the same
+ * as this writer's
+ * <code>format(Locale l, String format, Object... args)</code> method.
+ *
+ * @param l
+ * The locale used in the method. If locale is null, then no
+ * localization will be applied.
+ * @param format
+ * A format string.
+ * @param args
+ * The arguments list. If there are more arguments than those
+ * specified by the format string, then the additional
+ * arguments are ignored.
+ * @return
+ * @throws IllegalFormatException
+ * If the format string is illegal or incompatible with the
+ * arguments or the arguments are less than those required by
+ * the format string or any other illegal situation.
+ * @throws NullPointerException
+ * If the given format is null.
+ */
+ public PrintWriter printf(Locale l, String format, Object... args) {
+ return format(l, format, args);
+ }
private void newline() {
print(lineSeparator);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties?rev=411086&r1=411085&r2=411086&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties Fri Jun 2 01:28:50 2006
@@ -284,6 +284,7 @@
K034c=proxy should not be null
K034d=method has not been implemented yet
K034e=Build rules empty
+K0351=format is null
KA000=Line too long
KA001=Argument must not be null
KA002=Unshared read of back reference
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintStreamTest.java?rev=411086&r1=411085&r2=411086&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 Fri Jun 2 01:28:50 2006
@@ -15,10 +15,12 @@
package tests.api.java.io;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.util.Locale;
public class PrintStreamTest extends junit.framework.TestCase {
@@ -543,6 +545,62 @@
printStream.close();
}
+
+ /**
+ * @tests java.io.PrintStream#format(java.lang.String, java.lang.Object...)
+ */
+ public void test_formatLjava_lang_String$Ljava_lang_Object() {
+ os = new PrintStream(bos, false);
+ os.format("%s %s", "Hello", "World");
+ os.flush();
+ bis = new ByteArrayInputStream(bos.toByteArray());
+ byte[] rbytes = new byte[11];
+ bis.read(rbytes, 0, rbytes.length);
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(rbytes));
+ }
+
+ /**
+ * @tests java.io.PrintStream#format(java.util.Locale, java.lang.String, java.lang.Object...)
+ */
+ public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
+ os = new PrintStream(bos, false);
+ os.format(Locale.US, "%s %s", "Hello", "World");
+ os.flush();
+ bis = new ByteArrayInputStream(bos.toByteArray());
+ byte[] rbytes = new byte[11];
+ bis.read(rbytes, 0, rbytes.length);
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(rbytes));
+ }
+
+ /**
+ * @tests java.io.PrintStream#printf(java.lang.String, java.lang.Object...)
+ */
+ public void test_printfLjava_lang_String$Ljava_lang_Object() {
+ os = new PrintStream(bos, false);
+ os.printf("%s %s", "Hello", "World");
+ os.flush();
+ bis = new ByteArrayInputStream(bos.toByteArray());
+ byte[] rbytes = new byte[11];
+ bis.read(rbytes, 0, rbytes.length);
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(rbytes));
+ }
+
+ /**
+ * @tests java.io.PrintStream#printf(java.util.Locale, java.lang.String, java.lang.Object...)
+ */
+ public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
+ os = new PrintStream(bos, false);
+ os.printf(Locale.US, "%s %s", "Hello", "World");
+ os.flush();
+ bis = new ByteArrayInputStream(bos.toByteArray());
+ byte[] rbytes = new byte[11];
+ bis.read(rbytes, 0, rbytes.length);
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(rbytes));
+ }
/**
* Sets up the fixture, for example, open a network connection. This method
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PrintWriterTest.java?rev=411086&r1=411085&r2=411086&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 Fri Jun 2 01:28:50 2006
@@ -18,8 +18,11 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
+import java.nio.charset.Charset;
+import java.util.Locale;
import tests.support.Support_StringReader;
import tests.support.Support_StringWriter;
@@ -115,6 +118,60 @@
"Hello", sw.toString());
}
+ /**
+ * @tests java.io.PrintWriter#PrintWriter(java.io.File)
+ */
+ public void test_ConstructorLjava_io_File() throws Exception {
+ File file = File.createTempFile(getClass().getName(), null);
+ try {
+ PrintWriter writer = new PrintWriter(file);
+ writer.close();
+ } finally {
+ file.delete();
+ }
+ }
+
+ /**
+ * @tests java.io.PrintWriter#PrintWriter(java.io.File, java.lang.String)
+ */
+ public void test_ConstructorLjava_io_File_Ljava_lang_String() throws Exception {
+ File file = File.createTempFile(getClass().getName(), null);
+ try {
+ PrintWriter writer = new PrintWriter(file,
+ Charset.defaultCharset().name());
+ writer.close();
+ } finally {
+ file.delete();
+ }
+ }
+
+ /**
+ * @tests java.io.PrintWriter#PrintWriter(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() throws Exception {
+ File file = File.createTempFile(getClass().getName(), null);
+ try {
+ PrintWriter writer = new PrintWriter(file.getPath());
+ writer.close();
+ } finally {
+ file.delete();
+ }
+ }
+
+ /**
+ * @tests java.io.PrintWriter#PrintWriter(java.lang.String, java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String_Ljava_lang_String() throws Exception {
+ File file = File.createTempFile(getClass().getName(), null);
+ try {
+ PrintWriter writer = new PrintWriter(file.getPath(),
+ Charset.defaultCharset().name());
+ writer.close();
+ } finally {
+ file.delete();
+ }
+ }
+
/**
* @tests java.io.PrintWriter#checkError()
*/
@@ -623,6 +680,46 @@
printWriter.close();
}
+
+ /**
+ * @tests java.io.PrintWriter#format(java.lang.String, java.lang.Object...)
+ */
+ public void test_formatLjava_lang_String$Ljava_lang_Object() {
+ pw.format("%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
+ }
+
+ /**
+ * @tests java.io.PrintWriter#format(java.util.Locale, java.lang.String, java.lang.Object...)
+ */
+ public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
+ pw.format(Locale.US, "%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
+ }
+
+ /**
+ * @tests java.io.PrintWriter#printf(java.lang.String, java.lang.Object...)
+ */
+ public void test_printfLjava_lang_String$Ljava_lang_Object() {
+ pw.printf("%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
+ }
+
+ /**
+ * @tests java.io.PrintWriter#printf(java.util.Locale, java.lang.String, java.lang.Object...)
+ */
+ public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
+ pw.printf(Locale.US, "%s %s", "Hello", "World");
+ pw.flush();
+ assertEquals("Wrote incorrect string", "Hello World",
+ new String(bao.toByteArray()));
+ }
/**
* Sets up the fixture, for example, open a network connection. This method