001    /*
002     * Copyright (c) 2013 by Oli B.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     *
016     * (c)reated 14.09.2013 by Oli B. (boehm@javatux.de)
017     */
018    
019    package patterntesting.runtime.io;
020    
021    import java.io.*;
022    
023    /**
024     * Whenever you need a {@link FileInputStream} and want a better toString
025     * implementation you can use the class BetterFileInputStream. "Better" means
026     * that you see the name if the input file in the log which is much more helpful
027     * than the default implementation of {@link Object#toString()}, especially for
028     * logging and debugging.
029     *
030     * @author oliver (boehm@javatux.de)
031     * @since 1.3.1 (14.09.2013)
032     * @see FileInputStream
033     */
034    public final class BetterFileInputStream extends FileInputStream {
035    
036        private final File file;
037    
038        /**
039         * Instantiates a new better file input stream.
040         *
041         * @param name the name
042         * @throws FileNotFoundException the file not found exception
043         * @see FileInputStream#FileInputStream(String)
044         */
045        public BetterFileInputStream(final String name) throws FileNotFoundException {
046             super(name);
047             this.file = new File(name);
048        }
049    
050        /**
051         * Instantiates a new better file input stream.
052         *
053         * @param file the file
054         * @throws FileNotFoundException the file not found exception
055         * @see FileInputStream#FileInputStream(File)
056         */
057        public BetterFileInputStream(final File file) throws FileNotFoundException {
058             super(file);
059             this.file = file;
060        }
061    
062        /**
063         * This toString implementation reports the name of the input file which is
064         * much more helpful than the default implementation of
065         * {@link Object#toString()}, especially for logging and debugging.
066         *
067         * @return the string
068         * @see java.lang.Object#toString()
069         */
070        @Override
071        public String toString() {
072            return "input stream for file \"" + this.file + '"';
073        }
074    
075    }
076