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 */
017 package org.apache.camel.component.file;
018
019 import java.util.List;
020
021 import org.apache.camel.Exchange;
022
023 public 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 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 wether the directory is an absolute or relative path
066 * @return true if build or already exists, false if not possbile (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 * @return true if file has been retrieved, false if not
077 * @throws GenericFileOperationFailedException can be thrown
078 */
079 boolean retrieveFile(String name, Exchange exchange) throws GenericFileOperationFailedException;
080
081 /**
082 * Stores the content as a new remote file (upload)
083 *
084 * @param name name of new file
085 * @param exchange with the content content of the file
086 * @return true if the file was stored, false if not
087 * @throws GenericFileOperationFailedException can be thrown
088 */
089 boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException;
090
091 /**
092 * Gets the current remote directory
093 *
094 * @return the current directory path
095 * @throws GenericFileOperationFailedException can be thrown
096 */
097 String getCurrentDirectory() throws GenericFileOperationFailedException;
098
099 /**
100 * Change the current remote directory
101 *
102 * @param path the path to change to
103 * @throws GenericFileOperationFailedException can be thrown
104 */
105 void changeCurrentDirectory(String path) throws GenericFileOperationFailedException;
106
107 /**
108 * List the files in the current directory
109 *
110 * @return a list of backing objects representing the files
111 * @throws GenericFileOperationFailedException can be thrown
112 */
113 List<T> listFiles() throws GenericFileOperationFailedException;
114
115 /**
116 * List the files in the given remote directory
117 *
118 * @param path the remote directory
119 * @return a list of backing objects representing the files
120 * @throws GenericFileOperationFailedException can be thrown
121 */
122 List<T> listFiles(String path) throws GenericFileOperationFailedException;
123 }