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 public interface GenericFileOperations<T> {
022
023 /**
024 * Sets the endpoint as some implementations need access to the endpoint and how its configured.
025 *
026 * @param endpoint the endpoint
027 */
028 void setEndpoint(GenericFileEndpoint endpoint);
029
030 /**
031 * Deletes the file name by name, relative to the current directory
032 *
033 * @param name name of the file
034 * @return true if deleted, false if not
035 * @throws GenericFileOperationFailedException can be thrown
036 */
037 boolean deleteFile(String name) throws GenericFileOperationFailedException;
038
039 /**
040 * Renames the file
041 *
042 * @param from original name
043 * @param to the new name
044 * @return true if renamed, false if not
045 * @throws GenericFileOperationFailedException can be thrown
046 */
047 boolean renameFile(String from, String to) throws GenericFileOperationFailedException;
048
049 /**
050 * Builds the directory structure. Will test if the
051 * folder already exists.
052 *
053 * @param directory the directory path to build as a relative string name
054 * @param absolute wether the directory is an absolute or relative path
055 * @return true if build or already exists, false if not possbile (could be lack of permissions)
056 * @throws GenericFileOperationFailedException can be thrown
057 */
058 boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException;
059
060 /**
061 * Retrieves the file
062 *
063 * @param name name of the file
064 * @param exchange stream to write the content of the file into
065 * @return true if file has been retrieved, false if not
066 * @throws GenericFileOperationFailedException can be thrown
067 */
068 boolean retrieveFile(String name, GenericFileExchange<T> exchange) throws GenericFileOperationFailedException;
069
070 /**
071 * Stores the content as a new remote file (upload)
072 *
073 * @param name name of new file
074 * @param exchange with the content content of the file
075 * @return true if the file was stored, false if not
076 * @throws GenericFileOperationFailedException can be thrown
077 */
078 boolean storeFile(String name, GenericFileExchange<T> exchange) throws GenericFileOperationFailedException;
079
080 /**
081 * Gets the current remote directory
082 *
083 * @return the current directory path
084 * @throws GenericFileOperationFailedException can be thrown
085 */
086 String getCurrentDirectory() throws GenericFileOperationFailedException;
087
088 /**
089 * Change the current remote directory
090 *
091 * @param path the path to change to
092 * @throws GenericFileOperationFailedException can be thrown
093 */
094 void changeCurrentDirectory(String path) throws GenericFileOperationFailedException;
095
096 /**
097 * List the files in the current directory
098 *
099 * @return a list of backing objects representing the files
100 * @throws GenericFileOperationFailedException can be thrown
101 */
102 List<T> listFiles() throws GenericFileOperationFailedException;
103
104 /**
105 * List the files in the given remote directory
106 *
107 * @param path the remote directory
108 * @return a list of backing objects representing the files
109 * @throws GenericFileOperationFailedException can be thrown
110 */
111 List<T> listFiles(String path) throws GenericFileOperationFailedException;
112
113 }