public FTPFile parseFTPEntry()

in src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java [166:271]


    public FTPFile parseFTPEntry(final String entry) {
        final FTPFile file = new FTPFile();
        file.setRawListing(entry);
        final int type;
        boolean isDevice = false;

        if (matches(entry)) {
            final String typeStr = group(1);
            final String hardLinkCount = group(15);
            final String usr = group(16);
            final String grp = group(17);
            final String filesize = group(18);
            final String datestr = group(19) + " " + group(20);
            String name = group(21);
            if (trimLeadingSpaces) {
                name = name.replaceFirst("^\\s+", "");
            }

            try {
                if (group(19).contains(JA_MONTH)) { // special processing for Japanese format
                    final FTPTimestampParserImpl jaParser = new FTPTimestampParserImpl();
                    jaParser.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX, DEFAULT_DATE_FORMAT_JA, DEFAULT_RECENT_DATE_FORMAT_JA));
                    file.setTimestamp(jaParser.parseTimestamp(datestr));
                } else {
                    file.setTimestamp(super.parseTimestamp(datestr));
                }
            } catch (final ParseException e) {
                // intentionally do nothing
            }

            // A 'whiteout' file is an ARTIFICIAL entry in any of several types of
            // 'translucent' filesystems, of which a 'union' filesystem is one.

            // bcdelfmpSs-
            switch (typeStr.charAt(0)) {
            case 'd':
                type = FTPFile.DIRECTORY_TYPE;
                break;
            case 'e': // NET-39 => z/OS external link
                type = FTPFile.SYMBOLIC_LINK_TYPE;
                break;
            case 'l':
                type = FTPFile.SYMBOLIC_LINK_TYPE;
                break;
            case 'b':
            case 'c':
                isDevice = true;
                type = FTPFile.FILE_TYPE; // TODO change this if DEVICE_TYPE implemented
                break;
            case 'f':
            case '-':
                type = FTPFile.FILE_TYPE;
                break;
            default: // e.g. ? and w = whiteout
                type = FTPFile.UNKNOWN_TYPE;
            }

            file.setType(type);

            int g = 4;
            for (int access = 0; access < 3; access++, g += 4) {
                // Use != '-' to avoid having to check for suid and sticky bits
                file.setPermission(access, FTPFile.READ_PERMISSION, !group(g).equals("-"));
                file.setPermission(access, FTPFile.WRITE_PERMISSION, !group(g + 1).equals("-"));

                final String execPerm = group(g + 2);
                file.setPermission(access, FTPFile.EXECUTE_PERMISSION, !execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0)));
            }

            if (!isDevice) {
                try {
                    file.setHardLinkCount(Integer.parseInt(hardLinkCount));
                } catch (final NumberFormatException e) {
                    // intentionally do nothing
                }
            }

            file.setUser(usr);
            file.setGroup(grp);

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

            // oddball cases like symbolic links, file names
            // with spaces in them.
            if (type == FTPFile.SYMBOLIC_LINK_TYPE) {

                final int end = name.indexOf(" -> ");
                // Give up if no link indicator is present
                if (end == -1) {
                    file.setName(name);
                } else {
                    file.setName(name.substring(0, end));
                    file.setLink(name.substring(end + 4));
                }

            } else {
                file.setName(name);
            }
            return file;
        }
        return null;
    }