/** * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by * applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.apache.camel.component.jsch; import java.util.List; import org.apache.camel.Processor; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.remote.RemoteFile; import org.apache.camel.component.file.remote.RemoteFileConfiguration; import org.apache.camel.component.file.remote.RemoteFileConsumer; import org.apache.camel.component.file.remote.RemoteFileEndpoint; import org.apache.camel.component.file.remote.RemoteFileOperations; public class ScpConsumer extends RemoteFileConsumer<ScpFile> { protected String endpointPath; public ScpConsumer(RemoteFileEndpoint<ScpFile> endpoint, Processor processor, RemoteFileOperations<ScpFile> operations) { super(endpoint, processor, operations); this.endpointPath = endpoint.getConfiguration().getDirectory(); } @Override protected boolean pollDirectory(String fileName, List<GenericFile<ScpFile>> fileList, int depth) { List<ScpFile> files = getOperations().listFiles(fileName); for(ScpFile scpFile : files) { RemoteFile<ScpFile> remote = asRemoteFile(fileName, scpFile); if (isValidFile(remote, false, files)) { // matched file so add fileList.add(remote); } } return true; } private RemoteFile<ScpFile> asRemoteFile(String fileName, ScpFile scpFile) { RemoteFile<ScpFile> answer = new RemoteFile<ScpFile>(); answer.setEndpointPath(endpointPath); answer.setFile(scpFile); answer.setFileNameOnly(scpFile.getName()); answer.setFileLength(scpFile.getLength()); answer.setDirectory(scpFile.isDirectory()); answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost()); answer.setAbsoluteFilePath(scpFile.getParent() + "/" + scpFile.getName()); answer.setRelativeFilePath(scpFile.getName()); answer.setFileName(scpFile.getName()); return answer; } @Override protected boolean isMatched(GenericFile<ScpFile> file, String doneFileName, List<ScpFile> files) { //noop return true; } }