Package it.sauronsoftware.ftp4j

Examples of it.sauronsoftware.ftp4j.FTPListParseException


      if (aux.length() > 0) {
        list.add(aux);
      }
    }
    if (list.size() == 0) {
      throw new FTPListParseException();
    }
    // Extracts the file name.
    String name = (String) list.remove(list.size() - 1);
    // Parses the facts.
    Properties facts = new Properties();
    for (Iterator i = list.iterator(); i.hasNext();) {
      String aux = (String) i.next();
      int sep = aux.indexOf('=');
      if (sep == -1) {
        throw new FTPListParseException();
      }
      String key = aux.substring(0, sep).trim();
      String value = aux.substring(sep + 1, aux.length()).trim();
      if (key.length() == 0 || value.length() == 0) {
        throw new FTPListParseException();
      }
      facts.setProperty(key, value);
    }
    // Type.
    int type;
    String typeString = facts.getProperty("type");
    if (typeString == null) {
      throw new FTPListParseException();
    } else if ("file".equalsIgnoreCase(typeString)) {
      type = FTPFile.TYPE_FILE;
    } else if ("dir".equalsIgnoreCase(typeString)) {
      type = FTPFile.TYPE_DIRECTORY;
    } else if ("cdir".equalsIgnoreCase(typeString)) {
View Full Code Here


        if (typeString.equals("-")) {
          ret[i].setType(FTPFile.TYPE_FILE);
        } else if (typeString.equals("d")) {
          ret[i].setType(FTPFile.TYPE_DIRECTORY);
        } else {
          throw new FTPListParseException();
        }
        long fileSize;
        try {
          fileSize = Long.parseLong(sizeString);
        } catch (Throwable t) {
          throw new FTPListParseException();
        }
        ret[i].setSize(fileSize);
        if (dayString.length() == 1) {
          dayString = "0" + dayString;
        }
        StringBuffer mdString = new StringBuffer();
        mdString.append(monthString);
        mdString.append(' ');
        mdString.append(dayString);
        mdString.append(' ');
        boolean checkYear = false;
        if (yearString == null) {
          mdString.append(currentYear);
          checkYear = true;
        } else {
          mdString.append(yearString);
          checkYear = false;
        }
        mdString.append(' ');
        if (hourString != null && minuteString != null) {
          if (hourString.length() == 1) {
            hourString = "0" + hourString;
          }
          if (minuteString.length() == 1) {
            minuteString = "0" + minuteString;
          }
          mdString.append(hourString);
          mdString.append(':');
          mdString.append(minuteString);
        } else {
          mdString.append("00:00");
        }
        Date md;
        try {
          md = DATE_FORMAT.parse(mdString.toString());
        } catch (ParseException e) {
          throw new FTPListParseException();
        }
        if (checkYear) {
          Calendar mc = Calendar.getInstance();
          mc.setTime(md);
          if (mc.after(now)) {
            mc.set(Calendar.YEAR, currentYear - 1);
            md = mc.getTime();
          }
        }
        ret[i].setModifiedDate(md);
        ret[i].setName(nameString);
      } else {
        throw new FTPListParseException();
      }
    }
    return ret;
  }
View Full Code Here

    FTPFile[] ret = null;
    for (int i = 0; i < size; i++) {
      String l = lines[i];
      // Validate the plus sign.
      if (l.charAt(0) != '+') {
        throw new FTPListParseException();
      }
      // Split the facts from the filename.
      int a = l.indexOf('\t');
      if (a == -1) {
        throw new FTPListParseException();
      }
      String facts = l.substring(1, a);
      String name = l.substring(a + 1, l.length());
      // Parse the facts.
      Date md = null;
View Full Code Here

          ret[i].setType(FTPFile.TYPE_DIRECTORY);
        } else if (typeString.equals("l")) {
          ret[i].setType(FTPFile.TYPE_LINK);
          ret[i].setLink(linkedString);
        } else {
          throw new FTPListParseException();
        }
        long fileSize;
        try {
          fileSize = Long.parseLong(sizeString);
        } catch (Throwable t) {
          throw new FTPListParseException();
        }
        ret[i].setSize(fileSize);
        if (dayString.length() == 1) {
          dayString = "0" + dayString;
        }
        StringBuffer mdString = new StringBuffer();
        mdString.append(monthString);
        mdString.append(' ');
        mdString.append(dayString);
        mdString.append(' ');
        boolean checkYear = false;
        if (yearString == null) {
          mdString.append(currentYear);
          checkYear = true;
        } else {
          mdString.append(yearString);
          checkYear = false;
        }
        mdString.append(' ');
        if (hourString != null && minuteString != null) {
          if (hourString.length() == 1) {
            hourString = "0" + hourString;
          }
          if (minuteString.length() == 1) {
            minuteString = "0" + minuteString;
          }
          mdString.append(hourString);
          mdString.append(':');
          mdString.append(minuteString);
        } else {
          mdString.append("00:00");
        }
        Date md;
        try {
          md = DATE_FORMAT.parse(mdString.toString());
        } catch (ParseException e) {
          throw new FTPListParseException();
        }
        if (checkYear) {
          Calendar mc = Calendar.getInstance();
          mc.setTime(md);
          if (mc.after(now)) {
            mc.set(Calendar.YEAR, currentYear - 1);
            md = mc.getTime();
          }
        }
        ret[i].setModifiedDate(md);
        ret[i].setName(nameString);
      } else {
        throw new FTPListParseException();
      }
    }
    return ret;
  }
View Full Code Here

        } else {
          long fileSize;
          try {
            fileSize = Long.parseLong(dirOrSize);
          } catch (Throwable t) {
            throw new FTPListParseException();
          }
          ret[i].setType(FTPFile.TYPE_FILE);
          ret[i].setSize(fileSize);
        }
        String mdString = month + "/" + day + "/" + year + " " + hour
            + ":" + minute + " " + ampm;
        Date md;
        try {
          md = DATE_FORMAT.parse(mdString);
        } catch (ParseException e) {
          throw new FTPListParseException();
        }
        ret[i].setModifiedDate(md);
      } else {
        throw new FTPListParseException();
      }
    }
    return ret;
  }
View Full Code Here

TOP

Related Classes of it.sauronsoftware.ftp4j.FTPListParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.