alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Commons IO example source code file (ProxyReaderTest.java)

This example Commons IO source code file (ProxyReaderTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Commons IO tags/keywords

customnullreader, customnullreader, io, ioexception, nio, nullreader, override, proxyreader, proxyreaderimpl, proxyreaderimpl, proxyreadertest, string, string, testcase, writing, writing

The Commons IO ProxyReaderTest.java source code

/*
 * 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.input;

import java.io.IOException;
import java.io.Reader;
import java.nio.CharBuffer;

import junit.framework.TestCase;

/**
 * Test {@link ProxyReader}. 
 *
 * @version $Revision: 1003686 $
 */
public class ProxyReaderTest extends TestCase {

    public ProxyReaderTest(String name) {
        super(name);
    }

    /** Test writing Null Char Array */
    public void testNullCharArray() {

        ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0));

        try {
            proxy.read((char[])null);
        } catch(Exception e) {
            fail("Writing null String threw " + e);
        }

        try {
            proxy.read((char[])null, 0, 0);
        } catch(Exception e) {
            fail("Writing null String threw " + e);
        }
    }

    /** Test writing Null CharBuffer */
    public void testNullCharBuffer() {

        ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0));

        try {
            proxy.read((CharBuffer)null);
        } catch(Exception e) {
            fail("Writing null String threw " + e);
        }
    }

    /** ProxyReader implementation */
    private static class ProxyReaderImpl extends ProxyReader {
        ProxyReaderImpl(Reader proxy) {
            super(proxy);
        }
    }

    /** Custom NullReader implementation */
    private static class CustomNullReader extends NullReader {
        CustomNullReader(int len) {
            super(len);
        }
        @Override
        public int read(char[] chars) throws IOException {
            return chars == null ? 0 : super.read(chars);
        }
        @Override
        public int read(CharBuffer target) throws IOException {
            return target == null ? 0 : super.read(target);
        }
    }
}

Other Commons IO examples (source code examples)

Here is a short list of links related to this Commons IO ProxyReaderTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.