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
;
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
>();
39 public String
[] list(String absolutePath
) {
41 FileInfo
[] fileInfos
= myKernel
.listChildren(absolutePath
.replace('/', '\\') + "\\*.*");
42 if (fileInfos
== null) {
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
);
52 else if (info
.name
.equals("..")) {
55 myCache
.put(absolutePath
+ "/" + info
.name
, info
);
59 return names
.toArray(new String
[names
.size()]);
62 public boolean exists(String path
) {
67 catch (FileNotFoundException e
) {
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
);
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
);
92 info
= myKernel
.getInfo(path
.replace('/', '\\'));
94 throw new FileNotFoundException(path
);
96 myCache
.put(path
, info
);