win 32 jni
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / vfs / impl / win32 / Win32Kernel.java
blob7b79cd58ffe315fdf9580dbd34731e7f9ee69afc
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vfs.impl.win32;
18 import java.io.FileNotFoundException;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.Map;
23 /**
24 * @author Dmitry Avdeev
26 public class Win32Kernel {
28 public static final int FILE_ATTRIBUTE_DIRECTORY = 0x0010;
29 public static final int FILE_ATTRIBUTE_READONLY = 0x0001;
31 private IdeaWin32 myKernel = new IdeaWin32();
33 private Map<String, FileInfo> myCache = new HashMap<String, FileInfo>();
35 void clearCache() {
36 myCache.clear();
39 public String[] list(String absolutePath) {
41 FileInfo[] fileInfos = myKernel.listChildren(absolutePath.replace('/', '\\') + "\\*.*");
42 if (fileInfos == null) {
43 return new String[0];
45 ArrayList<String> names = new ArrayList<String>(fileInfos.length);
46 for (int i = 0, fileInfosLength = fileInfos.length; i < fileInfosLength; i++) {
47 FileInfo info = fileInfos[i];
48 if (info.name.equals(".")) {
49 myCache.put(absolutePath, info);
50 continue;
52 else if (info.name.equals("..")) {
53 continue;
55 myCache.put(absolutePath + "/" + info.name, info);
56 names.add(info.name);
59 return names.toArray(new String[names.size()]);
62 public boolean exists(String path) {
63 try {
64 getInfo(path);
65 return true;
67 catch (FileNotFoundException e) {
68 return false;
72 public boolean isDirectory(String path) throws FileNotFoundException {
73 FileInfo data = getInfo(path);
74 return (data.attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
77 public boolean isWritable(String path) throws FileNotFoundException {
78 FileInfo fileInfo = getInfo(path);
79 myCache.remove(path);
80 return (fileInfo.attributes & FILE_ATTRIBUTE_READONLY) == 0;
83 public long getTimeStamp(String path) throws FileNotFoundException {
84 long timestamp = getInfo(path).timestamp;
85 return timestamp / 10000 - 11644473600000l;
88 private FileInfo getInfo(String path) throws FileNotFoundException {
89 FileInfo info = myCache.get(path);
90 if (info == null) {
92 info = myKernel.getInfo(path.replace('/', '\\'));
93 if (info == null) {
94 throw new FileNotFoundException(path);
96 myCache.put(path, info);
98 return info;