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.remote;
018
019 import java.io.OutputStream;
020 import java.util.Map;
021
022 import org.apache.camel.impl.DefaultMessage;
023
024 public class RemoteFileMessage extends DefaultMessage {
025 private OutputStream outputStream;
026 private String fullFileName;
027 private String fileName;
028 private String hostname;
029 private long fileLength;
030
031 public RemoteFileMessage() {
032 }
033
034 public RemoteFileMessage(String hostname, String fullFileName, String fileName, long fileLength, OutputStream outputStream) {
035 this.hostname = hostname;
036 this.fullFileName = fullFileName;
037 this.fileName = fileName;
038 this.fileLength = fileLength;
039 this.outputStream = outputStream;
040 }
041
042 public String getHostname() {
043 return hostname;
044 }
045
046 public void setHostname(String hostname) {
047 this.hostname = hostname;
048 }
049
050 public String getFullFileName() {
051 return fullFileName;
052 }
053
054 public void setFullFileName(String fullFileName) {
055 this.fullFileName = fullFileName;
056 }
057
058 public OutputStream getOutputStream() {
059 return outputStream;
060 }
061
062 public void setOutputStream(OutputStream outputStream) {
063 this.outputStream = outputStream;
064 }
065
066 @Override
067 public RemoteFileExchange getExchange() {
068 return (RemoteFileExchange) super.getExchange();
069 }
070
071 @Override
072 protected Object createBody() {
073 if (outputStream != null) {
074 return getExchange().getBinding().extractBodyFromOutputStream(getExchange(), outputStream);
075 }
076 return null;
077 }
078
079 @Override
080 public RemoteFileMessage newInstance() {
081 return new RemoteFileMessage();
082 }
083
084 @Override
085 protected void populateInitialHeaders(Map<String, Object> map) {
086 super.populateInitialHeaders(map);
087 map.put("file.remote.host", hostname);
088 map.put("file.remote.fullName", fullFileName);
089 map.put("file.remote.name", fileName);
090
091 map.put("CamelFileName", fileName);
092 map.put("CamelFilePath", fullFileName);
093 // set the parent if there is a parent folder
094 if (fullFileName != null && fullFileName.indexOf("/") != -1) {
095 String parent = fullFileName.substring(0, fullFileName.lastIndexOf("/"));
096 map.put("CamelFileParent", parent);
097 }
098 if (fileLength > 0) {
099 map.put("CamelFileLength", new Long(fileLength));
100 }
101 }
102 }