1 17 package org.alfresco.filesys.server.filesys; 18 19 import java.io.IOException ; 20 21 import org.alfresco.filesys.locking.FileLock; 22 import org.alfresco.filesys.locking.FileLockList; 23 24 31 public abstract class NetworkFile 32 { 33 34 36 public static final int READONLY = 0; 37 public static final int WRITEONLY = 1; 38 public static final int READWRITE = 2; 39 40 42 public static final int IOPending = 0x0001; 43 public static final int DeleteOnClose = 0x0002; 44 45 47 protected int m_fid; 48 protected int m_dirId; 49 50 52 protected long m_uniqueId; 53 54 56 protected String m_name; 57 58 60 protected String m_streamName; 61 protected int m_streamId; 62 63 65 protected String m_fullName; 66 67 69 protected int m_attrib; 70 71 73 protected long m_fileSize; 74 75 77 protected long m_createDate; 78 protected long m_modifyDate; 79 protected long m_accessDate; 80 81 83 protected int m_grantedAccess; 84 85 87 protected boolean m_closed = true; 88 89 91 protected int m_writeCount; 92 93 100 private FileLockList m_lockList; 101 102 104 private int m_flags; 105 106 111 public NetworkFile(int fid) 112 { 113 m_fid = fid; 114 } 115 116 122 public NetworkFile(int fid, int did) 123 { 124 m_fid = fid; 125 m_dirId = did; 126 } 127 128 135 public NetworkFile(int fid, int stid, int did) 136 { 137 m_fid = fid; 138 m_streamId = stid; 139 m_dirId = did; 140 } 141 142 147 public NetworkFile(String name) 148 { 149 m_name = name; 150 } 151 152 157 public final int getDirectoryId() 158 { 159 return m_dirId; 160 } 161 162 167 public final int getFileAttributes() 168 { 169 return m_attrib; 170 } 171 172 177 public final int getFileId() 178 { 179 return m_fid; 180 } 181 182 187 public final long getFileSize() 188 { 189 return m_fileSize; 190 } 191 192 197 public final int getFileSizeInt() 198 { 199 return (int) (m_fileSize & 0x0FFFFFFFFL); 200 } 201 202 207 public final String getFullName() 208 { 209 return m_fullName; 210 } 211 212 217 public final String getFullNameStream() 218 { 219 if (isStream()) 220 return m_fullName + m_streamName; 221 else 222 return m_fullName; 223 } 224 225 228 public final int getGrantedAccess() 229 { 230 return m_grantedAccess; 231 } 232 233 238 public String getName() 239 { 240 return m_name; 241 } 242 243 248 public final int getStreamId() 249 { 250 return m_streamId; 251 } 252 253 258 public final String getStreamName() 259 { 260 return m_streamName; 261 } 262 263 268 public final long getUniqueId() 269 { 270 return m_uniqueId; 271 } 272 273 278 public final boolean isClosed() 279 { 280 return m_closed; 281 } 282 283 288 289 public final boolean isDirectory() 290 { 291 return (m_attrib & FileAttribute.Directory) != 0 ? true : false; 292 } 293 294 299 300 public final boolean isHidden() 301 { 302 return (m_attrib & FileAttribute.Hidden) != 0 ? true : false; 303 } 304 305 310 311 public final boolean isReadOnly() 312 { 313 return (m_attrib & FileAttribute.ReadOnly) != 0 ? true : false; 314 } 315 316 321 322 public final boolean isSystem() 323 { 324 return (m_attrib & FileAttribute.System) != 0 ? true : false; 325 } 326 327 332 public final boolean isArchived() 333 { 334 return (m_attrib & FileAttribute.Archive) != 0 ? true : false; 335 } 336 337 342 public final boolean isStream() 343 { 344 return m_streamName != null ? true : false; 345 } 346 347 352 public final boolean hasLocks() 353 { 354 if (m_lockList != null && m_lockList.numberOfLocks() > 0) 355 return true; 356 return false; 357 } 358 359 365 public final boolean hasNTAttribute(int attr) 366 { 367 return (m_attrib & attr) == attr ? true : false; 368 } 369 370 375 public final boolean hasAccessDate() 376 { 377 return m_accessDate != 0L ? true : false; 378 } 379 380 385 public final long getAccessDate() 386 { 387 return m_accessDate; 388 } 389 390 395 public final boolean hasCreationDate() 396 { 397 return m_createDate != 0L ? true : false; 398 } 399 400 405 public final long getCreationDate() 406 { 407 return m_createDate; 408 } 409 410 415 public final boolean hasDeleteOnClose() 416 { 417 return (m_flags & DeleteOnClose) != 0 ? true : false; 418 } 419 420 425 public final boolean hasIOPending() 426 { 427 return (m_flags & IOPending) != 0 ? true : false; 428 } 429 430 435 public boolean hasModifyDate() 436 { 437 return m_modifyDate != 0L ? true : false; 438 } 439 440 445 public final long getModifyDate() 446 { 447 return m_modifyDate; 448 } 449 450 455 public final int getWriteCount() 456 { 457 return m_writeCount; 458 } 459 460 463 public final void incrementWriteCount() 464 { 465 m_writeCount++; 466 } 467 468 473 public final void setAttributes(int attrib) 474 { 475 m_attrib = attrib; 476 } 477 478 483 public final void setDeleteOnClose(boolean del) 484 { 485 setStatusFlag(DeleteOnClose, del); 486 } 487 488 493 public final void setDirectoryId(int dirId) 494 { 495 m_dirId = dirId; 496 } 497 498 503 public final void setFileId(int fid) 504 { 505 m_fid = fid; 506 } 507 508 513 public final void setFileSize(long siz) 514 { 515 m_fileSize = siz; 516 } 517 518 523 public final void setFileSize(int siz) 524 { 525 m_fileSize = (long) siz; 526 } 527 528 533 public final void setFullName(String name) 534 { 535 m_fullName = name; 536 } 537 538 543 public final void setGrantedAccess(int mode) 544 { 545 m_grantedAccess = mode; 546 } 547 548 553 public final void setName(String name) 554 { 555 m_name = name; 556 } 557 558 563 public final void setIOPending(boolean pending) 564 { 565 setStatusFlag(IOPending, pending); 566 } 567 568 573 public final void setStreamId(int id) 574 { 575 m_streamId = id; 576 } 577 578 583 public final void setStreamName(String name) 584 { 585 m_streamName = name; 586 } 587 588 593 public final synchronized void setClosed(boolean b) 594 { 595 m_closed = b; 596 } 597 598 603 public final void setAccessDate(long dattim) 604 { 605 m_accessDate = dattim; 606 } 607 608 613 public final void setCreationDate(long dattim) 614 { 615 m_createDate = dattim; 616 } 617 618 623 public final void setModifyDate(long dattim) 624 { 625 m_modifyDate = dattim; 626 } 627 628 634 protected final synchronized void setStatusFlag(int flag, boolean sts) 635 { 636 boolean state = (m_flags & flag) != 0; 637 if (sts == true && state == false) 638 m_flags += flag; 639 else if (sts == false && state == true) 640 m_flags -= flag; 641 } 642 643 648 public final synchronized void addLock(FileLock lock) 649 { 650 651 653 if (m_lockList == null) 654 m_lockList = new FileLockList(); 655 656 658 m_lockList.addLock(lock); 659 } 660 661 666 public final synchronized void removeLock(FileLock lock) 667 { 668 669 671 if (m_lockList == null) 672 return; 673 674 676 m_lockList.removeLock(lock); 677 } 678 679 682 public final synchronized void removeAllLocks() 683 { 684 685 687 if (m_lockList != null) 688 m_lockList.removeAllLocks(); 689 } 690 691 696 public final int numberOfLocks() 697 { 698 699 701 if (m_lockList == null) 702 return 0; 703 return m_lockList.numberOfLocks(); 704 } 705 706 712 public final FileLock getLockAt(int idx) 713 { 714 715 717 if (m_lockList != null) 718 return m_lockList.getLockAt(idx); 719 720 722 return null; 723 } 724 725 730 public final FileLockList getLockList() 731 { 732 return m_lockList; 733 } 734 735 740 protected final void setUniqueId(long id) 741 { 742 m_uniqueId = id; 743 } 744 745 751 protected final void setUniqueId(int fid, int did) 752 { 753 long ldid = (long) did; 754 long lfid = (long) fid; 755 m_uniqueId = (ldid << 32) + lfid; 756 } 757 758 763 protected final void setUniqueId(String path) 764 { 765 m_uniqueId = (long) path.toUpperCase().hashCode(); 766 } 767 768 774 public abstract void openFile(boolean createFlag) throws IOException ; 775 776 786 public abstract int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException ; 787 788 797 public abstract void writeFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException ; 798 799 807 public abstract long seekFile(long pos, int typ) throws IOException ; 808 809 814 public abstract void flushFile() throws IOException ; 815 816 822 public abstract void truncateFile(long siz) throws IOException ; 823 824 827 public abstract void closeFile() throws IOException ; 828 829 832 public void close() throws IOException 833 { 834 closeFile(); 835 } 836 } | Popular Tags |