001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.commons.io;
020
021import java.io.IOException;
022import java.io.OutputStream;
023
024public final class ForkOutputStream extends OutputStream {
025
026        private final OutputStream os1;
027        private final OutputStream os2;
028
029        public ForkOutputStream(OutputStream os1,OutputStream os2) {
030                this.os1=os1;
031                this.os2=os2;
032        }
033        
034        @Override
035        public void close() throws IOException {
036                try {
037                        os1.close();
038                }
039                finally {
040                        os2.close();
041                }
042        }
043
044        @Override
045        public void flush() throws IOException {
046                try {
047                        os1.flush();
048                }
049                finally {
050                        os2.flush();
051                }
052        }
053
054        @Override
055        public void write(byte[] b, int off, int len) throws IOException {
056                os1.write(b, off, len);
057                os2.write(b, off, len);
058        }
059
060        @Override
061        public void write(byte[] b) throws IOException {
062                os1.write(b);
063                os2.write(b);
064        }
065
066        public void write(int b) throws IOException {
067                os1.write(b);
068                os2.write(b);
069        }
070
071}