1 12 13 package org.eclipse.core.resources; 14 15 import org.eclipse.core.filesystem.EFS; 16 import org.eclipse.core.internal.utils.FileUtil; 17 import org.eclipse.core.runtime.CoreException; 18 19 33 public class ResourceAttributes { 34 private int attributes; 35 36 45 public static ResourceAttributes fromFile(java.io.File file) { 46 try { 47 return FileUtil.fileInfoToAttributes(EFS.getStore(file.toURI()).fetchInfo()); 48 } catch (CoreException e) { 49 return new ResourceAttributes(); 51 } 52 } 53 54 57 public ResourceAttributes() { 58 super(); 59 } 60 61 68 public boolean isArchive() { 69 return (attributes & EFS.ATTRIBUTE_ARCHIVE) != 0; 70 } 71 72 79 public boolean isExecutable() { 80 return (attributes & EFS.ATTRIBUTE_EXECUTABLE) != 0; 81 } 82 83 91 public boolean isHidden() { 92 return (attributes & EFS.ATTRIBUTE_HIDDEN) != 0; 93 } 94 95 102 public boolean isReadOnly() { 103 return (attributes & EFS.ATTRIBUTE_READ_ONLY) != 0; 104 } 105 106 113 public void setArchive(boolean archive) { 114 set(EFS.ATTRIBUTE_ARCHIVE, archive); 115 } 116 117 120 private void set(int mask, boolean value) { 121 if (value) 122 attributes |= mask; 123 else 124 attributes &= ~mask; 125 } 126 127 134 public void setExecutable(boolean executable) { 135 set(EFS.ATTRIBUTE_EXECUTABLE, executable); 136 } 137 138 146 public void setHidden(boolean hidden) { 147 set(EFS.ATTRIBUTE_HIDDEN, hidden); 148 } 149 150 157 public void setReadOnly(boolean readOnly) { 158 set(EFS.ATTRIBUTE_READ_ONLY, readOnly); 159 } 160 161 165 public String toString() { 166 return "ResourceAttributes(" + attributes + ')'; } 168 } | Popular Tags |