1 12 package org.eclipse.core.internal.filesystem.local; 13 14 import org.eclipse.core.filesystem.IFileInfo; 15 import org.eclipse.core.filesystem.IFileSystem; 16 import org.eclipse.core.filesystem.provider.FileInfo; 17 import org.eclipse.core.internal.filesystem.Messages; 18 import org.eclipse.core.internal.filesystem.Policy; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.osgi.util.NLS; 21 22 abstract class LocalFileNatives { 23 private static boolean hasNatives = false; 24 private static boolean isUnicode = false; 25 26 27 private static final String LIBRARY_NAME = "localfile_1_0_0"; 30 static { 31 try { 32 System.loadLibrary(LIBRARY_NAME); 33 hasNatives = true; 34 isUnicode = internalIsUnicode(); 35 } catch (UnsatisfiedLinkError e) { 36 logMissingNativeLibrary(e); 37 } 38 } 39 40 52 private static final native int nativeAttributes(); 53 54 66 public static int attributes() { 67 try { 68 return nativeAttributes(); 69 } catch (UnsatisfiedLinkError e) { 70 return -1; 74 } 75 } 76 77 85 public static boolean copyAttributes(String source, String destination, boolean copyLastModified) { 86 if (hasNatives) 87 return isUnicode ? internalCopyAttributesW(Convert.toPlatformChars(source), Convert.toPlatformChars(destination), copyLastModified) : internalCopyAttributes(Convert.toPlatformBytes(source), Convert.toPlatformBytes(destination), copyLastModified); 89 return false; } 91 92 96 public static FileInfo fetchFileInfo(String fileName) { 97 FileInfo info = new FileInfo(); 98 if (isUnicode) 99 internalGetFileInfoW(Convert.toPlatformChars(fileName), info); 100 else 101 internalGetFileInfo(Convert.toPlatformBytes(fileName), info); 102 return info; 103 } 104 105 109 private static final native boolean internalCopyAttributes(byte[] source, byte[] destination, boolean copyLastModified); 110 111 117 private static final native boolean internalCopyAttributesW(char[] source, char[] destination, boolean copyLastModified); 118 119 123 private static final native boolean internalGetFileInfo(byte[] fileName, IFileInfo info); 124 125 129 private static final native boolean internalGetFileInfoW(char[] fileName, IFileInfo info); 130 131 135 private static final native boolean internalIsUnicode(); 136 137 139 private static final native boolean internalSetFileInfo(byte[] fileName, IFileInfo attribute); 140 141 144 private static final native boolean internalSetFileInfoW(char[] fileName, IFileInfo attribute, int options); 145 146 private static void logMissingNativeLibrary(UnsatisfiedLinkError e) { 147 String libName = System.mapLibraryName(LIBRARY_NAME); 148 String message = NLS.bind(Messages.couldNotLoadLibrary, libName); 149 Policy.log(IStatus.INFO, message, e); 150 } 151 152 157 public static boolean setFileInfo(String fileName, IFileInfo info, int options) { 158 if (isUnicode) 159 return internalSetFileInfoW(Convert.toPlatformChars(fileName), info, options); 160 return internalSetFileInfo(Convert.toPlatformBytes(fileName), info); 161 } 162 163 169 public static boolean usingNatives() { 170 return hasNatives; 171 } 172 } 173 | Popular Tags |