public FTPFile parseFTPEntry()

in src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java [286:379]


    public FTPFile parseFTPEntry(final String entry) {

        final FTPFile file = new FTPFile();
        file.setRawListing(entry);
        final int type;

        if (matches(entry)) {
            final String usr = group(1);
            final String filesize = group(2);
            String datestr = "";
            if (!isNullOrEmpty(group(3)) || !isNullOrEmpty(group(4))) {
                datestr = group(3) + " " + group(4);
            }
            final String typeStr = group(5);
            String name = group(6);

            boolean mustScanForPathSeparator = true;

            try {
                file.setTimestamp(super.parseTimestamp(datestr));
            } catch (final ParseException e) {
                // intentionally do nothing
            }

            if (typeStr.equalsIgnoreCase("*STMF")) {
                type = FTPFile.FILE_TYPE;
                if (isNullOrEmpty(filesize) || isNullOrEmpty(name)) {
                    return null;
                }
            } else if (typeStr.equalsIgnoreCase("*DIR")) {
                type = FTPFile.DIRECTORY_TYPE;
                if (isNullOrEmpty(filesize) || isNullOrEmpty(name)) {
                    return null;
                }
            } else if (typeStr.equalsIgnoreCase("*FILE")) {
                // File, defines the structure of the data (columns of a row)
                // but the data is stored in one or more members. Typically, a
                // source file contains multiple members whereas it is
                // recommended (but not enforced) to use one member per data
                // file.
                // Save files are a special type of files which are used
                // to save objects, e.g. for backups.
                if ((name == null) || !name.toUpperCase(Locale.ROOT).endsWith(".SAVF")) {
                    return null;
                }
                mustScanForPathSeparator = false;
                type = FTPFile.FILE_TYPE;
            } else if (typeStr.equalsIgnoreCase("*MEM")) {
                mustScanForPathSeparator = false;
                type = FTPFile.FILE_TYPE;

                if (isNullOrEmpty(name)) {
                    return null;
                }
                if (!(isNullOrEmpty(filesize) && isNullOrEmpty(datestr))) {
                    return null;
                }

                // Quick and dirty bug fix to make SelectorUtils work.
                // Class SelectorUtils uses 'File.separator' to splitt
                // a given path into pieces. But actually it had to
                // use the separator of the FTP server, which is a forward
                // slash in case of an AS/400.
                name = name.replace('/', File.separatorChar);
            } else {
                type = FTPFile.UNKNOWN_TYPE;
            }

            file.setType(type);

            file.setUser(usr);

            try {
                file.setSize(Long.parseLong(filesize));
            } catch (final NumberFormatException e) {
                // intentionally do nothing
            }

            if (name.endsWith("/")) {
                name = name.substring(0, name.length() - 1);
            }
            if (mustScanForPathSeparator) {
                final int pos = name.lastIndexOf('/');
                if (pos > -1) {
                    name = name.substring(pos + 1);
                }
            }

            file.setName(name);

            return file;
        }
        return null;
    }