📄 unixremotefile.java
字号:
/* * @(#) UnixRemoteFile.java * <p>Copyright: Copyright (c) 2003,2004 Rad Inks (Pvt) Ltd </p> * <p>Company: Rad Inks (Pvt) Ltd</p> */package com.radinks.net;/* * License * * The contents of this file are subject to the Jabber Open Source License * Version 1.0 (the "JOSL"). You may not copy or use this file, in either * source code or executable form, except in compliance with the JOSL. You * may obtain a copy of the JOSL at http://www.jabber.org/ or at * http://www.opensource.org/. * * Software distributed under the JOSL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL * for the specific language governing rights and limitations under the * JOSL. *//** * Represents a file on a FTP server that runs on a unix like operating system. * * @author Raditha Dissanayake * @version 1.01 */import java.text.*;import java.util.*;public class UnixRemoteFile extends RemoteFile { /** * This defaults constructor with package access is inteded for use by * the RemoteFile class. */ UnixRemoteFile() { } /** * Creates a new instance by parsing the data given. * @param s a line that was read in after executing the LIST command. */ public UnixRemoteFile(String s) { /* * the order of the parts are * flags, inode, uid, gid, size, month, day, time, name */ System.out.println(s); String[] parts = s.split(" "); /* * splitting by ' ' is actually a bit tricky because the filename * might contain spaces as well. If this happens we will have more * than 9 elements that we bargained for. * * A Second complication is the fact that often there is more than * one space character between two elements. Hence the need for us * to have two different iterators i and j. */ Calendar cal = Calendar.getInstance(); String dateTime =""; if(parts.length < 8) { /* * this entry is malfored or it's the summary. */ fileName=null; return; } for (int i = 0, j=0 ; i < parts.length; i++) { if(parts[i].trim().equals("")) { continue; } else { switch(j) { case 0: attrs = new FileAttrs(); attrs.parseFlags(parts[i]); break; case 1: try { attrs.setInode(Integer.parseInt(parts[i])); } catch (NumberFormatException ex) { attrs.setInode(0); } break; case 2: /* * wu-ftpd sends the username instead of the uid at times. */ try { attrs.setUId(Integer.parseInt(parts[i])); } catch (NumberFormatException ex) { attrs.setUId(0); } break; case 3: try { attrs.setGId(Integer.parseInt(parts[i])); } catch (NumberFormatException ex) { attrs.setGId(0); } break; case 4: attrs.setSize(Long.parseLong(parts[i])); break; case 5: if(parts[i+2].indexOf(":") != -1) { /* time given assume current year */ } case 6: dateTime += parts[i] + " "; break; case 7: dateTime += parts[i]; try { if(parts[i].indexOf(":") != -1) { //DateFormat dateFormat = DateFormat.getDateTimeInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy MMM dd HH:mm"); dateTime = cal.get(cal.YEAR) + " " + dateTime; Date date = dateFormat.parse(dateTime); /* System.out.println("date " + date.getTime()); System.out.println("date " + new Date(date.getTime())); */ attrs.setTime(date.getTime()); } else { SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy"); Date date = dateFormat.parse(dateTime); attrs.setTime(date.getTime()); } } catch (Exception ex) { System.err.println("unparsable data for " + s); } break; case 8: fileName = ""; if(i == parts.length-1) { this.fileName = (parts[i] == null) ? "" : parts[i]; } else { while(i < parts.length) { this.fileName += " " + parts[i++]; } } break; } j++; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -