001/*
002 * Copyright 2007-2018 The jdeb developers.
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 or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.vafer.jdeb.producers;
017
018import org.vafer.jdeb.DataConsumer;
019import org.vafer.jdeb.mapping.Mapper;
020import org.vafer.jdeb.utils.Utils;
021
022import java.io.File;
023import java.io.IOException;
024
025/**
026 * Data producer that places multiple files into a single
027 * destination directory.
028 */
029public class DataProducerFiles extends AbstractDataProducer {
030
031    private final String[] files;
032    private final String destDir;
033
034    public DataProducerFiles( final String[] files,
035                              final String destDir,
036                              final Mapper[] mappers ) {
037        super(null, null, mappers);
038        this.files = files;
039        this.destDir = destDir;
040    }
041
042    public void produce( DataConsumer receiver ) throws IOException {
043        boolean hasDestDir = !Utils.isNullOrEmpty(destDir);
044
045        for (String fileName : files) {
046            File f = new File(fileName);
047
048            if (hasDestDir) {
049                fileName = Utils.movePath(fileName, destDir);
050            }
051
052            produceFile(receiver, f, fileName);
053        }
054    }
055}