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<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 wether 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 * @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 * Releases the resources consumed by a retrieved file 083 * 084 * @param exchange exchange with the content of the file 085 * @throws GenericFileOperationFailedException can be thrown 086 */ 087 void releaseRetreivedFileResources(Exchange exchange) throws GenericFileOperationFailedException; 088 089 /** 090 * Stores the content as a new remote file (upload) 091 * 092 * @param name name of new file 093 * @param exchange with the content content of the file 094 * @return true if the file was stored, false if not 095 * @throws GenericFileOperationFailedException can be thrown 096 */ 097 boolean storeFile(String name, Exchange exchange) throws GenericFileOperationFailedException; 098 099 /** 100 * Gets the current remote directory 101 * 102 * @return the current directory path 103 * @throws GenericFileOperationFailedException can be thrown 104 */ 105 String getCurrentDirectory() throws GenericFileOperationFailedException; 106 107 /** 108 * Change the current remote directory 109 * 110 * @param path the path to change to 111 * @throws GenericFileOperationFailedException can be thrown 112 */ 113 void changeCurrentDirectory(String path) throws GenericFileOperationFailedException; 114 115 /** 116 * Change the current remote directory to the parent 117 * 118 * @throws GenericFileOperationFailedException can be thrown 119 */ 120 void changeToParentDirectory() throws GenericFileOperationFailedException; 121 122 /** 123 * List the files in the current directory 124 * 125 * @return a list of backing objects representing the files 126 * @throws GenericFileOperationFailedException can be thrown 127 */ 128 List<T> listFiles() throws GenericFileOperationFailedException; 129 130 /** 131 * List the files in the given remote directory 132 * 133 * @param path the remote directory 134 * @return a list of backing objects representing the files 135 * @throws GenericFileOperationFailedException can be thrown 136 */ 137 List<T> listFiles(String path) throws GenericFileOperationFailedException; 138 }