You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2006/10/09 03:12:44 UTC

svn commit: r454247 - in /jakarta/commons/proper/io/trunk/src: java/org/apache/commons/io/output/NullWriter.java test/org/apache/commons/io/output/NullWriterTest.java

Author: niallp
Date: Sun Oct  8 18:12:43 2006
New Revision: 454247

URL: http://svn.apache.org/viewvc?view=rev&rev=454247
Log:
IO-95 Add NullWriter implementation

Added:
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java   (with props)
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java   (with props)

Added: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java?view=auto&rev=454247
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java (added)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java Sun Oct  8 18:12:43 2006
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.io.output;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * This {@link Writer} writes all data to the famous <b>/dev/null</b>.
+ * <p>
+ * This {@link Writer} has no destination (file/socket etc.) and all
+ * characters written to it are ignored and lost.
+ * 
+ * @version $Id$
+ */
+public class NullWriter extends Writer {
+
+    /**
+     * Constructs a new NullWriter.
+     */
+    public NullWriter() {
+    }
+
+    /** @see java.io.Writer#write(int) */
+    public void write(int idx) throws IOException {
+        //to /dev/null
+    }
+
+    /** @see java.io.Writer#write(char[]) */
+    public void write(char[] chr) throws IOException {
+        //to /dev/null
+    }
+
+    /** @see java.io.Writer#write(char[], int, int) */
+    public void write(char[] chr, int st, int end) throws IOException {
+        //to /dev/null
+    }
+
+    /** @see java.io.Writer#write(String) */
+    public void write(String str) throws IOException {
+        //to /dev/null
+    }
+
+    /** @see java.io.Writer#write(String, int, int) */
+    public void write(String str, int st, int end) throws IOException {
+        //to /dev/null
+    }
+
+    /** @see java.io.Writer#flush() */
+    public void flush() throws IOException {
+        //to /dev/null
+    }
+
+    /** @see java.io.Writer#close() */
+    public void close() throws IOException {
+        //to /dev/null
+    }
+
+}

Propchange: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/output/NullWriter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java?view=auto&rev=454247
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java (added)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java Sun Oct  8 18:12:43 2006
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.commons.io.output;
+
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Really not a lot to do here, but checking that no 
+ * Exceptions are thrown. 
+ *
+ * @version $Revision$
+ */
+
+public class NullWriterTest extends TestCase {
+
+    public NullWriterTest(String name) {
+        super(name);
+    }
+
+    public void testNull() throws IOException {
+        char[] chars = new char[] {'A', 'B', 'C'};
+        NullWriter writer = new NullWriter();
+        writer.write(1);
+        writer.write(chars);
+        writer.write(chars, 1, 1);
+        writer.write("some string");
+        writer.write("some string", 2, 2);
+        writer.flush();
+        writer.close();
+    }
+
+}

Propchange: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/output/NullWriterTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org