1 17 package org.alfresco.filesys.server.filesys; 18 19 import java.io.Serializable ; 20 import java.util.Date ; 21 22 import org.alfresco.filesys.smb.SMBDate; 23 24 33 public class FileInfo implements Serializable 34 { 35 private static final long serialVersionUID = 5710753560656277110L; 36 37 41 public static final int SetFileSize = 0x0001; 42 public static final int SetAllocationSize = 0x0002; 43 public static final int SetAttributes = 0x0004; 44 public static final int SetModifyDate = 0x0008; 45 public static final int SetCreationDate = 0x0010; 46 public static final int SetAccessDate = 0x0020; 47 public static final int SetChangeDate = 0x0040; 48 public static final int SetGid = 0x0080; 49 public static final int SetUid = 0x0100; 50 public static final int SetMode = 0x0200; 51 public static final int SetDeleteOnClose = 0x0400; 52 53 55 protected String m_name; 56 57 59 protected String m_shortName; 60 61 63 protected String m_path; 64 65 67 protected long m_size; 68 69 71 protected int m_attr = -1; 72 73 75 private long m_modifyDate; 76 77 79 private long m_createDate; 80 81 83 private long m_accessDate; 84 85 87 private long m_changeDate; 88 89 91 private long m_allocSize; 92 93 95 private int m_fileId = -1; 96 private int m_dirId = -1; 97 98 100 private int m_gid = -1; 101 private int m_uid = -1; 102 103 105 private int m_mode = -1; 106 107 109 private boolean m_deleteOnClose; 110 111 117 private int m_setFlags; 118 119 122 public FileInfo() 123 { 124 } 125 126 133 public FileInfo(String fname, long fsize, int fattr) 134 { 135 m_name = fname; 136 m_size = fsize; 137 m_attr = fattr; 138 139 setAllocationSize(0); 140 } 141 142 150 public FileInfo(String fname, long fsize, int fattr, int ftime) 151 { 152 m_name = fname; 153 m_size = fsize; 154 m_attr = fattr; 155 m_modifyDate = new SMBDate(ftime).getTime(); 156 157 setAllocationSize(0); 158 } 159 160 169 public FileInfo(String fname, long fsize, int fattr, int fdate, int ftime) 170 { 171 m_name = fname; 172 m_size = fsize; 173 m_attr = fattr; 174 175 if (fdate != 0 && ftime != 0) 176 m_modifyDate = new SMBDate(fdate, ftime).getTime(); 177 178 setAllocationSize(0); 179 } 180 181 189 public FileInfo(String fpath, String fname, long fsize, int fattr) 190 { 191 m_path = fpath; 192 m_name = fname; 193 m_size = fsize; 194 m_attr = fattr; 195 196 setAllocationSize(0); 197 } 198 199 208 public FileInfo(String fpath, String fname, long fsize, int fattr, int ftime) 209 { 210 m_path = fpath; 211 m_name = fname; 212 m_size = fsize; 213 m_attr = fattr; 214 m_modifyDate = new SMBDate(ftime).getTime(); 215 216 setAllocationSize(0); 217 } 218 219 229 public FileInfo(String fpath, String fname, long fsize, int fattr, int fdate, int ftime) 230 { 231 m_path = fpath; 232 m_name = fname; 233 m_size = fsize; 234 m_attr = fattr; 235 m_modifyDate = new SMBDate(fdate, ftime).getTime(); 236 237 setAllocationSize(0); 238 } 239 240 245 public long getAccessDateTime() 246 { 247 return m_accessDate; 248 } 249 250 255 public long getAllocationSize() 256 { 257 return m_allocSize; 258 } 259 260 265 public int getAllocationSizeInt() 266 { 267 return (int) (m_allocSize & 0x0FFFFFFFFL); 268 } 269 270 275 public long getChangeDateTime() 276 { 277 return m_changeDate; 278 } 279 280 285 public long getCreationDateTime() 286 { 287 return m_createDate; 288 } 289 290 295 public final boolean hasDeleteOnClose() 296 { 297 return m_deleteOnClose; 298 } 299 300 305 public int getFileAttributes() 306 { 307 return m_attr; 308 } 309 310 315 public final String getFileName() 316 { 317 return m_name; 318 } 319 320 325 public final boolean hasShortName() 326 { 327 return m_shortName != null ? true : false; 328 } 329 330 335 public final String getShortName() 336 { 337 return m_shortName; 338 } 339 340 345 public final long getModifyDateTime() 346 { 347 return m_modifyDate; 348 } 349 350 355 public final String getPath() 356 { 357 return m_path; 358 } 359 360 365 public final long getSize() 366 { 367 return m_size; 368 } 369 370 375 public final int getSizeInt() 376 { 377 return (int) (m_size & 0x0FFFFFFFFL); 378 } 379 380 385 public final int getFileId() 386 { 387 return m_fileId; 388 } 389 390 395 public final long getFileIdLong() 396 { 397 return ((long) m_fileId) & 0xFFFFFFFFL; 398 } 399 400 405 public final int getDirectoryId() 406 { 407 return m_dirId; 408 } 409 410 415 public final long getDirectoryIdLong() 416 { 417 return ((long) m_dirId) & 0xFFFFFFFFL; 418 } 419 420 425 public boolean hasAccessDateTime() 426 { 427 return m_accessDate == 0L ? false : true; 428 } 429 430 435 public boolean hasChangeDateTime() 436 { 437 return m_changeDate == 0L ? false : true; 438 } 439 440 445 public boolean hasCreationDateTime() 446 { 447 return m_createDate == 0L ? false : true; 448 } 449 450 455 public boolean hasModifyDateTime() 456 { 457 return m_modifyDate == 0L ? false : true; 458 } 459 460 465 public final boolean hasFileAttributes() 466 { 467 return m_attr != -1 ? true : false; 468 } 469 470 475 public final boolean hasAttribute(int attr) 476 { 477 return (m_attr & attr) != 0 ? true : false; 478 } 479 480 485 public final boolean isDirectory() 486 { 487 return (m_attr & FileAttribute.Directory) != 0 ? true : false; 488 } 489 490 495 public final boolean isHidden() 496 { 497 return (m_attr & FileAttribute.Hidden) != 0 ? true : false; 498 } 499 500 505 public final boolean isReadOnly() 506 { 507 return (m_attr & FileAttribute.ReadOnly) != 0 ? true : false; 508 } 509 510 515 public final boolean isSystem() 516 { 517 return (m_attr & FileAttribute.System) != 0 ? true : false; 518 } 519 520 525 public final boolean isArchived() 526 { 527 return (m_attr & FileAttribute.Archive) != 0 ? true : false; 528 } 529 530 535 public final boolean hasGid() 536 { 537 return m_gid != -1 ? true : false; 538 } 539 540 545 public final int getGid() 546 { 547 return m_gid; 548 } 549 550 555 public final boolean hasUid() 556 { 557 return m_uid != -1 ? true : false; 558 } 559 560 565 public final int getUid() 566 { 567 return m_uid; 568 } 569 570 575 public final boolean hasMode() 576 { 577 return m_mode != -1 ? true : false; 578 } 579 580 585 public final int getMode() 586 { 587 return m_mode; 588 } 589 590 593 public final void resetInfo() 594 { 595 m_name = ""; 596 m_path = null; 597 598 m_size = 0L; 599 m_allocSize = 0L; 600 601 m_attr = 0; 602 603 m_accessDate = 0L; 604 m_createDate = 0L; 605 m_modifyDate = 0L; 606 m_changeDate = 0L; 607 608 m_fileId = -1; 609 m_dirId = -1; 610 611 m_gid = -1; 612 m_uid = -1; 613 m_mode = -1; 614 } 615 616 621 public final void copyFrom(FileInfo finfo) 622 { 623 m_name = finfo.getFileName(); 624 m_path = finfo.getPath(); 625 626 m_size = finfo.getSize(); 627 m_allocSize = finfo.getAllocationSize(); 628 629 m_attr = finfo.getFileAttributes(); 630 631 m_accessDate = finfo.getAccessDateTime(); 632 m_createDate = finfo.getCreationDateTime(); 633 m_modifyDate = finfo.getModifyDateTime(); 634 m_changeDate = finfo.getChangeDateTime(); 635 636 m_fileId = finfo.getFileId(); 637 m_dirId = finfo.getDirectoryId(); 638 639 m_gid = finfo.getGid(); 640 m_uid = finfo.getUid(); 641 m_mode = finfo.getMode(); 642 } 643 644 649 public void setAccessDateTime(long timesec) 650 { 651 652 654 m_accessDate = timesec; 655 } 656 657 662 public void setAllocationSize(long siz) 663 { 664 m_allocSize = siz; 665 } 666 667 672 public void setChangeDateTime(long timesec) 673 { 674 675 677 m_changeDate = timesec; 678 } 679 680 685 public void setCreationDateTime(long timesec) 686 { 687 688 690 m_createDate = timesec; 691 } 692 693 698 public final void setDeleteOnClose(boolean del) 699 { 700 m_deleteOnClose = del; 701 } 702 703 708 public final void setFileAttributes(int attr) 709 { 710 m_attr = attr; 711 } 712 713 718 public final void setFileName(String name) 719 { 720 m_name = name; 721 } 722 723 728 public final void setFileSize(long siz) 729 { 730 m_size = siz; 731 } 732 733 738 public void setModifyDateTime(long timesec) 739 { 740 741 743 m_modifyDate = timesec; 744 } 745 746 751 public final void setFileId(int id) 752 { 753 m_fileId = id; 754 } 755 756 761 public final void setDirectoryId(int id) 762 { 763 m_dirId = id; 764 } 765 766 771 public final void setShortName(String name) 772 { 773 m_shortName = name; 774 } 775 776 781 public final void setPath(String path) 782 { 783 m_path = path; 784 } 785 786 791 public final void setSize(int siz) 792 { 793 m_size = siz; 794 } 795 796 801 public final void setSize(long siz) 802 { 803 m_size = siz; 804 } 805 806 811 public final void setGid(int id) 812 { 813 m_gid = id; 814 } 815 816 821 public final void setUid(int id) 822 { 823 m_uid = id; 824 } 825 826 831 public final void setMode(int mode) 832 { 833 m_mode = mode; 834 } 835 836 841 public final void setFileInformationFlags(int setFlags) 842 { 843 m_setFlags = setFlags; 844 } 845 846 852 public final boolean hasSetFlag(int flag) 853 { 854 if ((m_setFlags & flag) != 0) 855 return true; 856 return false; 857 } 858 859 864 public final int getSetFileInformationFlags() 865 { 866 return m_setFlags; 867 } 868 869 874 public String toString() 875 { 876 StringBuffer str = new StringBuffer (); 877 878 880 if (m_path != null) 881 { 882 str.append(m_path); 883 if (!m_path.endsWith("\\")) 884 str.append("\\"); 885 } 886 887 889 str.append(m_name); 890 891 893 while (str.length() < 15) 894 str.append(" "); 895 896 898 if (isReadOnly()) 899 str.append("R"); 900 else 901 str.append("-"); 902 if (isHidden()) 903 str.append("H"); 904 else 905 str.append("-"); 906 if (isSystem()) 907 str.append("S"); 908 else 909 str.append("-"); 910 if (isDirectory()) 911 str.append("D"); 912 else 913 str.append("-"); 914 915 917 str.append(" "); 918 str.append(m_size); 919 920 922 while (str.length() < 30) 923 str.append(" "); 924 925 927 if (m_modifyDate != 0L) 928 { 929 str.append(" - "); 930 str.append(new Date (m_modifyDate)); 931 } 932 933 935 if (hasShortName()) 936 { 937 str.append(" ("); 938 str.append(getShortName()); 939 str.append(")"); 940 } 941 942 944 return str.toString(); 945 } 946 } | Popular Tags |