Lines 294-305
Link Here
|
294 |
private boolean initialized = false; |
294 |
private boolean initialized = false; |
295 |
private Map attrs = Collections.EMPTY_MAP; //Map<String->Attribute> |
295 |
private Map attrs = Collections.EMPTY_MAP; //Map<String->Attribute> |
296 |
|
296 |
|
|
|
297 |
// for equality comparisons |
298 |
private int hash = 0; |
299 |
|
297 |
public BFSBase(String name, FileObject parent, int offset) { |
300 |
public BFSBase(String name, FileObject parent, int offset) { |
298 |
this.name = name; |
301 |
this.name = name; |
299 |
this.parent = parent; |
302 |
this.parent = parent; |
300 |
this.offset = offset; |
303 |
this.offset = offset; |
301 |
} |
304 |
} |
302 |
|
305 |
|
|
|
306 |
public boolean equals(Object o) { |
307 |
if (!(o instanceof BFSBase)) return false; |
308 |
BFSBase f = (BFSBase)o; |
309 |
if (f.hashCode() != hashCode()) return false; |
310 |
return f.getPath().equals(getPath()) && specificEquals(f); |
311 |
} |
312 |
|
313 |
public int hashCode() { |
314 |
if (hash == 0) { |
315 |
hash = getPath().hashCode() ^ (specificHashCode() + 265478956); |
316 |
} |
317 |
return hash; |
318 |
} |
319 |
|
320 |
protected abstract boolean specificEquals(BFSBase f); |
321 |
protected abstract int specificHashCode(); |
322 |
|
303 |
/** no-op implementations of read-only, fixed, never firing FS */ |
323 |
/** no-op implementations of read-only, fixed, never firing FS */ |
304 |
public void addFileChangeListener(FileChangeListener fcl) {} |
324 |
public void addFileChangeListener(FileChangeListener fcl) {} |
305 |
public void removeFileChangeListener(FileChangeListener fcl) {} |
325 |
public void removeFileChangeListener(FileChangeListener fcl) {} |
Lines 636-641
Link Here
|
636 |
public boolean isFolder() { |
657 |
public boolean isFolder() { |
637 |
return false; |
658 |
return false; |
638 |
} |
659 |
} |
|
|
660 |
|
661 |
private byte[] data() throws IOException { |
662 |
if (len == -1) throw new IllegalArgumentException(); |
663 |
return new Pointer(contentOffset).getBytes(len); |
664 |
} |
639 |
|
665 |
|
640 |
/** Get input stream. */ |
666 |
/** Get input stream. */ |
641 |
public InputStream getInputStream() throws java.io.FileNotFoundException { |
667 |
public InputStream getInputStream() throws java.io.FileNotFoundException { |
Lines 643-649
Link Here
|
643 |
try { |
669 |
try { |
644 |
return len == -1 ? // URI or not |
670 |
return len == -1 ? // URI or not |
645 |
new URL(uri).openConnection().getInputStream() : // len from URI |
671 |
new URL(uri).openConnection().getInputStream() : // len from URI |
646 |
new ByteArrayInputStream(new Pointer(contentOffset).getBytes(len)); |
672 |
new ByteArrayInputStream(data()); |
647 |
} catch (Exception e) { |
673 |
} catch (Exception e) { |
648 |
FileNotFoundException x = new FileNotFoundException (e.getMessage()); |
674 |
FileNotFoundException x = new FileNotFoundException (e.getMessage()); |
649 |
ErrorManager.getDefault().annotate(x,e); |
675 |
ErrorManager.getDefault().annotate(x,e); |
Lines 676-682
Link Here
|
676 |
contentOffset = ptr.getOffset(); |
702 |
contentOffset = ptr.getOffset(); |
677 |
if (len == -1) uri = ptr.getString(); |
703 |
if (len == -1) uri = ptr.getString(); |
678 |
} |
704 |
} |
|
|
705 |
|
706 |
// hashCode and equals compare data: URI or byte contents. |
679 |
|
707 |
|
|
|
708 |
protected int specificHashCode() { |
709 |
initialize(); |
710 |
if (len == -1) { |
711 |
return uri.hashCode(); |
712 |
} else { |
713 |
byte[] data; |
714 |
try { |
715 |
data = data(); |
716 |
} catch (IOException ioe) { |
717 |
return 55; |
718 |
} |
719 |
int x = 0; |
720 |
for (int i = 0; i < data.length; i++) { |
721 |
x += 876824551; |
722 |
x ^= data[i]; |
723 |
} |
724 |
return x; |
725 |
} |
726 |
} |
727 |
|
728 |
protected boolean specificEquals(BFSBase _f) { |
729 |
if (!(_f instanceof BFSFile)) return false; |
730 |
BFSFile f = (BFSFile)_f; |
731 |
initialize(); |
732 |
f.initialize(); |
733 |
if (len == -1 && f.len == -1) { |
734 |
return uri.equals(f.uri); |
735 |
} else if (len != -1 && f.len != -1) { |
736 |
byte[] data, fdata; |
737 |
try { |
738 |
data = data(); |
739 |
fdata = f.data(); |
740 |
} catch (IOException ioe) { |
741 |
return false; |
742 |
} |
743 |
if (data.length != fdata.length) return false; |
744 |
for (int i = 0; i < data.length; i++) { |
745 |
if (data[i] != fdata[i]) return false; |
746 |
} |
747 |
return true; |
748 |
} else { |
749 |
return false; |
750 |
} |
751 |
} |
752 |
|
680 |
} |
753 |
} |
681 |
|
754 |
|
682 |
private class BFSFolder extends BFSBase { |
755 |
private class BFSFolder extends BFSBase { |
Lines 742-746
Link Here
|
742 |
} |
815 |
} |
743 |
} |
816 |
} |
744 |
} |
817 |
} |
|
|
818 |
|
819 |
// hashCode and equals compare contents recursively. |
820 |
|
821 |
protected int specificHashCode() { |
822 |
initialize(); |
823 |
int x = 0; |
824 |
Iterator it = childrenMap.values().iterator(); |
825 |
while (it.hasNext()) { |
826 |
x ^= ((BFSBase)it.next()).hashCode(); |
827 |
} |
828 |
return x; |
829 |
} |
830 |
|
831 |
protected boolean specificEquals(BFSBase _f) { |
832 |
if (!(_f instanceof BFSFolder)) return false; |
833 |
BFSFolder f = (BFSFolder)_f; |
834 |
initialize(); |
835 |
return childrenMap.equals(f.childrenMap); |
836 |
} |
837 |
|
745 |
} |
838 |
} |
746 |
} |
839 |
} |