001 package de.mospace.lang;
002
003 /* Mp3dings - manage mp3 meta-information
004 * Copyright (C) 2006 Moritz Ringler
005 * $Id: NullStream.java 12 2007-07-27 09:48:53Z ringler $
006 *
007 * This program is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU General Public License
009 * as published by the Free Software Foundation; either version 2
010 * of the License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020 */
021
022 import java.io.IOException;
023 import java.io.OutputStream;
024
025 /** A Singleton OutputStream that serves as a '/dev/null'-like
026 * data sink.
027 **/
028 public final class NullStream extends OutputStream{
029 /** The sole instance of this class, which is lazily initialized. */
030 private static NullStream instance;
031
032 private NullStream(){
033 }
034
035 /** Returns the sole instance of this class.
036 * @return an output stream whose write methods do nothing.
037 */
038 public static synchronized OutputStream getInstance(){
039 if (instance == null){
040 instance = new NullStream();
041 }
042 return instance;
043 }
044
045 /** Throws a CloneNotSupportedException. This is a Singleton, therefore
046 * clone is not supported.
047 * @throws CloneNotSupportedException This method always throws a CloneNotSupportedException.
048 */
049 public Object clone() throws CloneNotSupportedException{
050 throw new CloneNotSupportedException();
051 }
052
053 /** Does nothing.
054 *@throws IOException This method will not throw an Exception.
055 */
056 public void write(int b) throws IOException{
057 //Does nothing.
058 }
059
060 /** Does nothing.
061 *@throws IOException This method will not throw an Exception.
062 */
063 public void write(byte[] b) throws IOException{
064 //Does nothing.
065 }
066
067 /** Does nothing.
068 *@throws IOException This method will not throw an Exception.
069 */
070 public void write(byte[] b, int off, int len) throws IOException{
071 //Does nothing.
072 }
073 }