StouCommandHandler.java revision 2a0a3f946dba517a01cc26278f905156857c9c91
1/*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.fake.command;
17
18import org.mockftpserver.core.command.Command;
19
20/**
21 * CommandHandler for the STOU command. Handler logic:
22 * <ol>
23 * <li>If the user has not logged in, then reply with 530 and terminate</li>
24 * <li>Create a new file within the current directory with a unique name</li>
25 * <li>Send an initial reply of 150</li>
26 * <li>Read all available bytes from the data connection and write out to the unique file in the server file system</li>
27 * <li>If file write/store fails, then reply with 553 and terminate</li>
28 * <li>Send a final reply with 226, along with the new unique filename</li>
29 * </ol>
30 *
31 * @author Chris Mair
32 * @version $Revision$ - $Date$
33 */
34public class StouCommandHandler extends AbstractStoreFileCommandHandler {
35
36    /**
37     * @return the message key for the reply message sent with the final (226) reply
38     */
39    protected String getMessageKey() {
40        return "stou";
41    }
42
43    /**
44     * Return the path (absolute or relative) for the output file.
45     */
46    protected String getOutputFile(Command command) {
47        String baseName = defaultIfNullOrEmpty(command.getOptionalString(0), "Temp");
48        String suffix = Long.toString(System.currentTimeMillis());
49        return baseName + suffix;
50    }
51
52}