All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datacleaner.repository.RepositoryFile Maven / Gradle / Ivy

/**
 * DataCleaner (community edition)
 * Copyright (C) 2014 Neopost - Customer Information Management
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.datacleaner.repository;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.function.Function;

import org.apache.metamodel.util.Action;
import org.apache.metamodel.util.Resource;

/**
 * Represents a file in the {@link Repository}.
 */
public interface RepositoryFile extends RepositoryNode {

    /**
     * Represents the main file types in the repository.
     */
    enum Type {
        ANALYSIS_JOB, ANALYSIS_RESULT, TIMELINE_SPEC, OTHER
    }

    /**
     * Opens up an {@link InputStream} to read from the file.
     *
     * @return an {@link InputStream} to read from the file.
     * @deprecated prefer to use {@link #readFile(Action)} or
     *             {@link #readFile(Function)} instead.
     */
    @Deprecated
    InputStream readFile();

    /**
     * Opens up an {@link OutputStream} to write to the file.
     *
     * @param append
     *            whether or not to append to the existing contents of the file.
     * @return prefer to use {@link #writeFile(Action)} or
     *         {@link #writeFile(Action, boolean)} instead.
     */
    @Deprecated
    OutputStream writeFile(boolean append);

    /**
     * Gets the size (in number of bytes) of this file's data. An approximated
     * number is allowed.
     *
     * If the size is not determinable without actually reading through the
     * whole contents of the resource, -1 is returned.
     *
     * @return
     */
    long getSize();

    /**
     * Opens up an {@link OutputStream} to write to the file, and allows a
     * callback to perform writing actions on it.
     *
     * @param writeCallback
     *            a callback which should define what to write to the file.
     */
    void writeFile(Action writeCallback);

    /**
     * Opens up an {@link OutputStream} to write to the file, and allows a
     * callback to perform writing actions on it.
     *
     * @param writeCallback
     * @param append
     *            whether or not to append to the existing content (if any) of
     *            the file.
     */
    void writeFile(Action writeCallback, boolean append);

    /**
     * Opens up an {@link InputStream} to read from the file, and allows a
     * callback to perform writing actions on it.
     *
     * @param readCallback
     */
    void readFile(Action readCallback);

    /**
     * Opens up an {@link InputStream} to read from the file, and allows a
     * callback function to perform writing actions on it and return the
     * function's result.
     *
     * @param readCallback
     * @return the result of the function
     */
     E readFile(Function readCallback);

    /**
     * Gets the type of the file.
     *
     * @return the type of the file.
     */
    Type getType();

    /**
     * Gets the last modified timestamp, specified as the number of milliseconds
     * since the standard base time known as "the epoch", namely January 1,
     * 1970, 00:00:00 GMT.
     *
     * @return the last modified timestamp, or -1 if there was an error reading
     *         the timestamp
     */
    long getLastModified();

    /**
     * Gets a {@link Resource} representation of the {@link RepositoryFile}.
     *
     * @return
     */
    Resource toResource();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy