001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2016-2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero 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, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.io.events;
020
021import java.nio.file.OpenOption;
022import java.nio.file.Path;
023import java.util.Arrays;
024
025import org.jgrapes.core.Event;
026import org.jgrapes.io.FileStorage;
027
028/**
029 * Causes the {@link FileStorage} component to write the data from all
030 * {@link Output} events on the channel that this event is fired on to a file
031 * until an event with the end of record flag set is sent on the channel.
032 */
033public class SaveOutput extends Event<Void> {
034
035    private final Path path;
036    private final OpenOption[] options;
037
038    /**
039     * Creates a new instance.
040     * 
041     * @param path the file's path
042     * @param options open options
043     */
044    public SaveOutput(Path path, OpenOption... options) {
045        this.path = path;
046        this.options = Arrays.copyOf(options, options.length);
047    }
048
049    /**
050     * Return's the event's path. 
051     * 
052     * @return the path
053     */
054    public Path path() {
055        return path;
056    }
057
058    /**
059     * Returns the event's options.
060     * 
061     * @return the options
062     */
063    public OpenOption[] options() {
064        return Arrays.copyOf(options, options.length);
065    }
066
067}