001/*
002 * Syncany, www.syncany.org
003 * Copyright (C) 2011-2016 Philipp C. Heckel <philipp.heckel@gmail.com> 
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program 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
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package org.syncany.chunk;
019
020import java.io.IOException;
021import java.io.InputStream;
022import java.io.OutputStream;
023import java.util.Map;
024
025/**
026 * Implements an empty {@link Transformer}. Used if no compression/encryption
027 * is necessary.
028 * 
029 * @author Philipp C. Heckel (philipp.heckel@gmail.com)
030 */
031public class NoTransformer extends Transformer {
032        /**
033         * The no-transformer does not take any parameters and therefore must
034         * not be initialized. This method does nothing.
035         */
036        @Override
037        public void init(Map<String, String> settings) throws Exception {
038                // Nothing here
039        }
040        
041    @Override
042    public OutputStream createOutputStream(OutputStream out) throws IOException {
043        if (nextTransformer == null) {
044            return out;
045        }
046        else {
047            return nextTransformer.createOutputStream(out);
048        }
049    }
050
051    @Override
052    public InputStream createInputStream(InputStream in) throws IOException {
053        if (nextTransformer == null) {
054            return in;
055        }
056        else {
057            return nextTransformer.createInputStream(in);
058        }
059    }
060
061    @Override
062    public String toString() {
063        return (nextTransformer == null) ? "None" : "None-"+nextTransformer;
064    }    
065}