// Path: app/src/main/java/be/ppareit/swiftp/Util.java
// abstract public class Util {
//     final static String TAG = Util.class.getSimpleName();
// 
//     public static byte byteOfInt(int value, int which) {
//         int shift = which * 8;
//         return (byte) (value >> shift);
//     }
// 
//     public static String ipToString(int address, String sep) {
//         if (address > 0) {
//             StringBuffer buf = new StringBuffer();
//             buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1))
//                     .append(sep).append(byteOfInt(address, 2)).append(sep)
//                     .append(byteOfInt(address, 3));
//             Log.d(TAG, "ipToString returning: " + buf.toString());
//             return buf.toString();
//         } else {
//             return null;
//         }
//     }
// 
//     public static InetAddress intToInet(int value) {
//         byte[] bytes = new byte[4];
//         for (int i = 0; i < 4; i++) {
//             bytes[i] = byteOfInt(value, i);
//         }
//         try {
//             return InetAddress.getByAddress(bytes);
//         } catch (UnknownHostException e) {
//             // This only happens if the byte array has a bad length
//             return null;
//         }
//     }
// 
//     public static String ipToString(int address) {
//         if (address == 0) {
//             // This can only occur due to an error, we shouldn't blindly
//             // convert 0 to string.
//             Log.e(TAG, "ipToString won't convert value 0");
//             return null;
//         }
//         return ipToString(address, ".");
//     }
// 
//     public static String[] concatStrArrays(String[] a1, String[] a2) {
//         String[] retArr = new String[a1.length + a2.length];
//         System.arraycopy(a1, 0, retArr, 0, a1.length);
//         System.arraycopy(a2, 0, retArr, a1.length, a2.length);
//         return retArr;
//     }
// 
//     public static void sleepIgnoreInterrupt(long millis) {
//         try {
//             Thread.sleep(millis);
//         } catch (InterruptedException ignored) {
//         }
//     }
// 
//     /**
//      * Creates a SimpleDateFormat in the formatting used by ftp sever/client.
//      */
//     private static SimpleDateFormat createSimpleDateFormat() {
//         SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
//         df.setTimeZone(TimeZone.getTimeZone("UTC"));
//         return df;
//     }
// 
//     public static String getFtpDate(long time) {
//         SimpleDateFormat df = createSimpleDateFormat();
//         return df.format(new Date(time));
//     }
// 
//     public static Date parseDate(String time) throws ParseException {
//         SimpleDateFormat df = createSimpleDateFormat();
//         return df.parse(time);
//     }
// }


import net.vrallev.android.cat.Cat;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import be.ppareit.swiftp.Util;
import android.util.Log;
/*
Copyright 2014 Pieter Pareit

This file is part of SwiFTP.

SwiFTP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SwiFTP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SwiFTP.  If not, see <http://www.gnu.org/licenses/>.
 */

package be.ppareit.swiftp.server;





/**
 * CmdMFMT implements File Modification Time. See draft-somers-ftp-mfxx-04 in documentation.
 */
public class CmdMFMT extends FtpCmd implements Runnable {

    private String mInput;

    public CmdMFMT(SessionThread sessionThread, String input) {
        super(sessionThread);
        mInput = input;
    }

    @Override
    public void run() {
        Cat.d("run: MFMT executing, input: " + mInput);

        //Syntax: "MFMT" SP time-val SP pathname CRLF
        String parameter = getParameter(mInput);
        int splitPosition = parameter.indexOf(' ');
        if (splitPosition == -1) {
            sessionThread.writeString("500 wrong number of parameters\r\n");
            Cat.d("run: MFMT failed, wrong number of parameters");
            return;
        }

        String timeString = parameter.substring(0, splitPosition);
        String pathName = parameter.substring(splitPosition + 1);

        // Format of time-val: YYYYMMDDHHMMSS.ss, see rfc3659, p6
        // BUG: The milliseconds part get's ignored
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss", Locale.US);
        df.setTimeZone(TimeZone.getTimeZone("UTC"));

        Date timeVal;
        try {
// Path: app/src/main/java/be/ppareit/swiftp/Util.java
// abstract public class Util {
//     final static String TAG = Util.class.getSimpleName();
// 
//     public static byte byteOfInt(int value, int which) {
//         int shift = which * 8;
//         return (byte) (value >> shift);
//     }
// 
//     public static String ipToString(int address, String sep) {
//         if (address > 0) {
//             StringBuffer buf = new StringBuffer();
//             buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1))
//                     .append(sep).append(byteOfInt(address, 2)).append(sep)
//                     .append(byteOfInt(address, 3));
//             Log.d(TAG, "ipToString returning: " + buf.toString());
//             return buf.toString();
//         } else {
//             return null;
//         }
//     }
// 
//     public static InetAddress intToInet(int value) {
//         byte[] bytes = new byte[4];
//         for (int i = 0; i < 4; i++) {
//             bytes[i] = byteOfInt(value, i);
//         }
//         try {
//             return InetAddress.getByAddress(bytes);
//         } catch (UnknownHostException e) {
//             // This only happens if the byte array has a bad length
//             return null;
//         }
//     }
// 
//     public static String ipToString(int address) {
//         if (address == 0) {
//             // This can only occur due to an error, we shouldn't blindly
//             // convert 0 to string.
//             Log.e(TAG, "ipToString won't convert value 0");
//             return null;
//         }
//         return ipToString(address, ".");
//     }
// 
//     public static String[] concatStrArrays(String[] a1, String[] a2) {
//         String[] retArr = new String[a1.length + a2.length];
//         System.arraycopy(a1, 0, retArr, 0, a1.length);
//         System.arraycopy(a2, 0, retArr, a1.length, a2.length);
//         return retArr;
//     }
// 
//     public static void sleepIgnoreInterrupt(long millis) {
//         try {
//             Thread.sleep(millis);
//         } catch (InterruptedException ignored) {
//         }
//     }
// 
//     /**
//      * Creates a SimpleDateFormat in the formatting used by ftp sever/client.
//      */
//     private static SimpleDateFormat createSimpleDateFormat() {
//         SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
//         df.setTimeZone(TimeZone.getTimeZone("UTC"));
//         return df;
//     }
// 
//     public static String getFtpDate(long time) {
//         SimpleDateFormat df = createSimpleDateFormat();
//         return df.format(new Date(time));
//     }
// 
//     public static Date parseDate(String time) throws ParseException {
//         SimpleDateFormat df = createSimpleDateFormat();
//         return df.parse(time);
//     }
// }


// Path: app/src/main/java/be/ppareit/swiftp/server/CmdMFMT.java
import net.vrallev.android.cat.Cat;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import be.ppareit.swiftp.Util;
import android.util.Log;

/*
Copyright 2014 Pieter Pareit

This file is part of SwiFTP.

SwiFTP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SwiFTP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SwiFTP.  If not, see <http://www.gnu.org/licenses/>.
 */

package be.ppareit.swiftp.server;





/**
 * CmdMFMT implements File Modification Time. See draft-somers-ftp-mfxx-04 in documentation.
 */
public class CmdMFMT extends FtpCmd implements Runnable {

    private String mInput;

    public CmdMFMT(SessionThread sessionThread, String input) {
        super(sessionThread);
        mInput = input;
    }

    @Override
    public void run() {
        Cat.d("run: MFMT executing, input: " + mInput);

        //Syntax: "MFMT" SP time-val SP pathname CRLF
        String parameter = getParameter(mInput);
        int splitPosition = parameter.indexOf(' ');
        if (splitPosition == -1) {
            sessionThread.writeString("500 wrong number of parameters\r\n");
            Cat.d("run: MFMT failed, wrong number of parameters");
            return;
        }

        String timeString = parameter.substring(0, splitPosition);
        String pathName = parameter.substring(splitPosition + 1);

        // Format of time-val: YYYYMMDDHHMMSS.ss, see rfc3659, p6
        // BUG: The milliseconds part get's ignored
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss", Locale.US);
        df.setTimeZone(TimeZone.getTimeZone("UTC"));

        Date timeVal;
        try {
            timeVal = Util.parseDate(timeString);