2 * Copyright (C) 2008 The Android Open Source Project
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.
17 package com.android.sdklib.io;
22 import java.util.ArrayList;
25 * An implementation of {@link IAbstractFolder} extending {@link File}.
27 public class FolderWrapper extends File implements IAbstractFolder {
29 private static final long serialVersionUID = 1L;
32 * Creates a new File instance from a parent abstract pathname and a child pathname string.
33 * @param parent the parent pathname
34 * @param child the child name
36 * @see File#File(File, String)
38 public FolderWrapper(File parent, String child) {
43 * Creates a new File instance by converting the given pathname string into an abstract
45 * @param pathname the pathname
47 * @see File#File(String)
49 public FolderWrapper(String pathname) {
54 * Creates a new File instance from a parent abstract pathname and a child pathname string.
55 * @param parent the parent pathname
56 * @param child the child name
58 * @see File#File(String, String)
60 public FolderWrapper(String parent, String child) {
65 * Creates a new File instance by converting the given <code>file:</code> URI into an
67 * @param uri An absolute, hierarchical URI with a scheme equal to "file", a non-empty path
68 * component, and undefined authority, query, and fragment components
72 public FolderWrapper(URI uri) {
77 * Creates a new File instance matching a give {@link File} object.
78 * @param file the file to match
80 public FolderWrapper(File file) {
81 super(file.getAbsolutePath());
84 public IAbstractResource[] listMembers() {
85 File[] files = listFiles();
86 final int count = files.length;
87 IAbstractResource[] afiles = new IAbstractResource[count];
89 for (int i = 0 ; i < count ; i++) {
92 afiles[i] = new FileWrapper(f);
94 afiles[i] = new FolderWrapper(f);
101 public boolean hasFile(final String name) {
102 String[] match = list(new FilenameFilter() {
103 public boolean accept(IAbstractFolder dir, String filename) {
104 return name.equals(filename);
108 return match.length > 0;
111 public IAbstractFile getFile(String name) {
112 return new FileWrapper(this, name);
115 public IAbstractFolder getFolder(String name) {
116 return new FolderWrapper(this, name);
119 public IAbstractFolder getParentFolder() {
120 String p = this.getParent();
124 return new FolderWrapper(p);
127 public String getOsLocation() {
128 return getAbsolutePath();
132 public boolean exists() {
133 return isDirectory();
136 public String[] list(FilenameFilter filter) {
137 File[] files = listFiles();
138 if (files.length > 0) {
139 ArrayList<String> list = new ArrayList<String>();
141 for (File file : files) {
142 if (filter.accept(this, file.getName())) {
143 list.add(file.getName());
147 return list.toArray(new String[list.size()]);
150 return new String[0];