1dfb59d50631968ab1a13002ea5421ece93169851chrismair/* 2dfb59d50631968ab1a13002ea5421ece93169851chrismair * Copyright 2007 the original author or authors. 3dfb59d50631968ab1a13002ea5421ece93169851chrismair * 4dfb59d50631968ab1a13002ea5421ece93169851chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5dfb59d50631968ab1a13002ea5421ece93169851chrismair * you may not use this file except in compliance with the License. 6dfb59d50631968ab1a13002ea5421ece93169851chrismair * You may obtain a copy of the License at 7dfb59d50631968ab1a13002ea5421ece93169851chrismair * 8dfb59d50631968ab1a13002ea5421ece93169851chrismair * http://www.apache.org/licenses/LICENSE-2.0 9dfb59d50631968ab1a13002ea5421ece93169851chrismair * 10dfb59d50631968ab1a13002ea5421ece93169851chrismair * Unless required by applicable law or agreed to in writing, software 11dfb59d50631968ab1a13002ea5421ece93169851chrismair * distributed under the License is distributed on an "AS IS" BASIS, 12dfb59d50631968ab1a13002ea5421ece93169851chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13dfb59d50631968ab1a13002ea5421ece93169851chrismair * See the License for the specific language governing permissions and 14dfb59d50631968ab1a13002ea5421ece93169851chrismair * limitations under the License. 15dfb59d50631968ab1a13002ea5421ece93169851chrismair */ 16dfb59d50631968ab1a13002ea5421ece93169851chrismairpackage org.mockftpserver.stub.command; 17dfb59d50631968ab1a13002ea5421ece93169851chrismair 18dfb59d50631968ab1a13002ea5421ece93169851chrismairimport org.mockftpserver.core.command.ReplyCodes; 19dfb59d50631968ab1a13002ea5421ece93169851chrismairimport org.mockftpserver.core.session.Session; 20dfb59d50631968ab1a13002ea5421ece93169851chrismair 21dfb59d50631968ab1a13002ea5421ece93169851chrismair/** 22dfb59d50631968ab1a13002ea5421ece93169851chrismair * CommandHandler for the STOU (Store Unique) command. Send back two replies on the control connection: a 23dfb59d50631968ab1a13002ea5421ece93169851chrismair * reply code of 150 and another of 226. The text accompanying the final reply (226) is the 24dfb59d50631968ab1a13002ea5421ece93169851chrismair * unique filename, which is "" by default. You can customize the returned filename by setting 25dfb59d50631968ab1a13002ea5421ece93169851chrismair * the <code>filename</code> property. 26dfb59d50631968ab1a13002ea5421ece93169851chrismair * <p/> 27dfb59d50631968ab1a13002ea5421ece93169851chrismair * Each invocation record stored by this CommandHandler includes the following data element key/values: 28dfb59d50631968ab1a13002ea5421ece93169851chrismair * <ul> 29dfb59d50631968ab1a13002ea5421ece93169851chrismair * <li>{@link #FILE_CONTENTS_KEY} ("fileContents") - the file contents (<code>byte[]</code>) sent on the data connection 30dfb59d50631968ab1a13002ea5421ece93169851chrismair * </ul> 31dfb59d50631968ab1a13002ea5421ece93169851chrismair * 32dfb59d50631968ab1a13002ea5421ece93169851chrismair * @author Chris Mair 33dfb59d50631968ab1a13002ea5421ece93169851chrismair * @version $Revision$ - $Date$ 34dfb59d50631968ab1a13002ea5421ece93169851chrismair */ 35dfb59d50631968ab1a13002ea5421ece93169851chrismairpublic class StouCommandHandler extends AbstractStorCommandHandler { 36dfb59d50631968ab1a13002ea5421ece93169851chrismair 37dfb59d50631968ab1a13002ea5421ece93169851chrismair private static final String FINAL_REPLY_TEXT_KEY = "226.WithFilename"; 38dfb59d50631968ab1a13002ea5421ece93169851chrismair 39dfb59d50631968ab1a13002ea5421ece93169851chrismair private String filename = ""; 40dfb59d50631968ab1a13002ea5421ece93169851chrismair 41dfb59d50631968ab1a13002ea5421ece93169851chrismair /** 42dfb59d50631968ab1a13002ea5421ece93169851chrismair * Override the default implementation to send a custom reply text that includes the STOU response filename 43dfb59d50631968ab1a13002ea5421ece93169851chrismair * 44dfb59d50631968ab1a13002ea5421ece93169851chrismair * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#sendFinalReply(org.mockftpserver.core.session.Session) 45dfb59d50631968ab1a13002ea5421ece93169851chrismair */ 46dfb59d50631968ab1a13002ea5421ece93169851chrismair protected void sendFinalReply(Session session) { 47dfb59d50631968ab1a13002ea5421ece93169851chrismair final String[] ARGS = {filename}; 48dfb59d50631968ab1a13002ea5421ece93169851chrismair sendReply(session, ReplyCodes.TRANSFER_DATA_FINAL_OK, FINAL_REPLY_TEXT_KEY, null, ARGS); 49dfb59d50631968ab1a13002ea5421ece93169851chrismair } 50dfb59d50631968ab1a13002ea5421ece93169851chrismair 51dfb59d50631968ab1a13002ea5421ece93169851chrismair /** 52dfb59d50631968ab1a13002ea5421ece93169851chrismair * Set the filename returned with the final reply of the STOU command 53dfb59d50631968ab1a13002ea5421ece93169851chrismair * 54dfb59d50631968ab1a13002ea5421ece93169851chrismair * @param filename - the filename 55dfb59d50631968ab1a13002ea5421ece93169851chrismair */ 56dfb59d50631968ab1a13002ea5421ece93169851chrismair public void setFilename(String filename) { 57dfb59d50631968ab1a13002ea5421ece93169851chrismair this.filename = filename; 58dfb59d50631968ab1a13002ea5421ece93169851chrismair } 59dfb59d50631968ab1a13002ea5421ece93169851chrismair 60dfb59d50631968ab1a13002ea5421ece93169851chrismair} 61