001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.component.file;
018
019import java.util.List;
020
021import org.apache.camel.Exchange;
022
023public interface GenericFileOperations<T> {
024
025    /**
026     * Sets the endpoint as some implementations need access to the endpoint and how its configured.
027     *
028     * @param endpoint the endpoint
029     */
030    void setEndpoint(GenericFileEndpoint<T> endpoint);
031
032    /**
033     * Deletes the file name by name, relative to the current directory
034     *
035     * @param name name of the file
036     * @return true if deleted, false if not
037     * @throws GenericFileOperationFailedException can be thrown
038     */
039    boolean deleteFile(String name) throws GenericFileOperationFailedException;
040
041    /**
042     * Determines whether the files exists or not
043     *
044     * @param name name of the file
045     * @return true if exists, false if not
046     * @throws GenericFileOperationFailedException can be thrown
047     */
048    boolean existsFile(String name) throws GenericFileOperationFailedException;
049
050    /**
051     * Renames the file
052     *
053     * @param from original name
054     * @param to   the new name
055     * @return true if renamed, false if not
056     * @throws GenericFileOperationFailedException can be thrown
057     */
058    boolean renameFile(String from, String to) throws GenericFileOperationFailedException;
059
060    /**
061     * Builds the directory structure. Will test if the
062     * folder already exists.
063     *
064     * @param directory the directory path to build as a relative string name
065     * @param absolute whether the directory is an absolute or relative path
066     * @return true if build or already exists, false if not possible (could be lack of permissions)
067     * @throws GenericFileOperationFailedException can be thrown
068     */
069    boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException;
070
071    /**
072     * Retrieves the file
073     *
074     * @param name     name of the file
075     * @param exchange stream to write the content of the file into
076     * @param size     the total file size to retrieve, if possible to determine
077     * @return true if file has been retrieved, false if not
078     * @throws GenericFileOperationFailedException can be thrown
079     */
080    boolean retrieveFile(String name, Exchange exchange, long size) throws GenericFileOperationFailedException;
081    
082    /**
083     * Releases the resources consumed by a retrieved file
084     * 
085     * @param exchange exchange with the content of the file
086     * @throws GenericFileOperationFailedException can be thrown
087     */
088    void releaseRetrievedFileResources(Exchange exchange) throws GenericFileOperationFailedException;
089
090    /**
091     * Stores the content as a new remote file (upload)
092     *
093     * @param name     name of new file
094     * @param exchange with the content content of the file
095     * @param size     the total file size to store, if possible to determine
096     * @return true if the file was stored, false if not
097     * @throws GenericFileOperationFailedException can be thrown
098     */
099    boolean storeFile(String name, Exchange exchange, long size) throws GenericFileOperationFailedException;
100
101    /**
102     * Gets the current remote directory
103     *
104     * @return the current directory path
105     * @throws GenericFileOperationFailedException can be thrown
106     */
107    String getCurrentDirectory() throws GenericFileOperationFailedException;
108
109    /**
110     * Change the current remote directory
111     *
112     * @param path the path to change to
113     * @throws GenericFileOperationFailedException can be thrown
114     */
115    void changeCurrentDirectory(String path) throws GenericFileOperationFailedException;
116
117    /**
118     * Change the current remote directory to the parent
119     *
120     * @throws GenericFileOperationFailedException can be thrown
121     */
122    void changeToParentDirectory() throws GenericFileOperationFailedException;
123
124    /**
125     * List the files in the current directory
126     *
127     * @return a list of backing objects representing the files
128     * @throws GenericFileOperationFailedException can be thrown
129     */
130    List<T> listFiles() throws GenericFileOperationFailedException;
131
132    /**
133     * List the files in the given remote directory
134     *
135     * @param path the remote directory
136     * @return a list of backing objects representing the files
137     * @throws GenericFileOperationFailedException can be thrown
138     */
139    List<T> listFiles(String path) throws GenericFileOperationFailedException;
140}