2 * Copyright 2000-2011 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.jar;
18 import com.intellij.openapi.vfs.VirtualFile;
19 import com.intellij.openapi.vfs.VirtualFileSystem;
20 import org.jetbrains.annotations.NotNull;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.util.ArrayList;
26 import java.util.List;
31 public class CoreJarVirtualFile extends VirtualFile {
32 private final CoreJarFileSystem myFileSystem;
33 private final CoreJarHandler myHandler;
34 private final String myPathInJar;
36 public CoreJarVirtualFile(CoreJarFileSystem fileSystem, CoreJarHandler handler, String pathInJar) {
37 myFileSystem = fileSystem;
39 myPathInJar = pathInJar;
44 public String getName() {
45 final int lastSlash = myPathInJar.lastIndexOf('/');
49 return myPathInJar.substring(lastSlash+1);
54 public VirtualFileSystem getFileSystem() {
59 public String getPath() {
60 return myHandler.myBasePath + "!/" + myPathInJar;
64 public boolean isWritable() {
69 public boolean isDirectory() {
70 return myHandler.isDirectory(this);
74 public boolean isValid() {
79 public VirtualFile getParent() {
80 if (myPathInJar.length() == 0) {
83 int lastSlash = myPathInJar.lastIndexOf('/');
85 return myHandler.findFileByPath("");
87 return myHandler.findFileByPath(myPathInJar.substring(0, lastSlash));
91 public VirtualFile[] getChildren() {
92 List<VirtualFile> result = new ArrayList<VirtualFile>();
93 final String[] children = myHandler.list(this);
94 for (String child : children) {
95 final VirtualFile childFile = myPathInJar.isEmpty() ? myHandler.findFileByPath(child) : myHandler.findFileByPath(myPathInJar + "/" + child);
96 result.add(childFile);
98 return result.toArray(new VirtualFile[result.size()]);
103 public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
104 throw new UnsupportedOperationException("JarFileSystem is read-only");
109 public byte[] contentsToByteArray() throws IOException {
110 return myHandler.contentsToByteArray(this);
114 public long getTimeStamp() {
115 return myHandler.getTimeStamp(this);
119 public long getLength() {
120 return myHandler.getLength(this);
124 public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
128 public InputStream getInputStream() throws IOException {
129 return myHandler.getInputStream(this);
133 public long getModificationStamp() {