summaryrefslogtreecommitdiffstats
path: root/sched
diff options
context:
space:
mode:
authorBenoit Lamarche <benoitlamarche@google.com>2015-02-23 11:34:42 +0100
committerBenoit Lamarche <benoitlamarche@google.com>2015-02-23 11:38:05 +0100
commit01aefb8ecc7414d590da28dc2418ab9275fcd7a9 (patch)
treea7a765f6ad6546ba098d75446a11f5b64cde4a11 /sched
parent7db31c79befa118c63466f4763960e6f5c9402a4 (diff)
downloadtoolchain_jack-01aefb8ecc7414d590da28dc2418ab9275fcd7a9.tar.gz
toolchain_jack-01aefb8ecc7414d590da28dc2418ab9275fcd7a9.tar.bz2
toolchain_jack-01aefb8ecc7414d590da28dc2418ab9275fcd7a9.zip
Remove old VFS
Change-Id: I7ebd6d1f28158e1a95932774f870c91ded28dc48
Diffstat (limited to 'sched')
-rw-r--r--sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java9
-rw-r--r--sched/src/com/android/sched/vfs/DirectDir.java148
-rw-r--r--sched/src/com/android/sched/vfs/DirectFile.java95
-rw-r--r--sched/src/com/android/sched/vfs/DirectVFS.java63
-rw-r--r--sched/src/com/android/sched/vfs/InputOutputZipVDir.java167
-rw-r--r--sched/src/com/android/sched/vfs/InputOutputZipVFS.java114
-rw-r--r--sched/src/com/android/sched/vfs/InputOutputZipVFile.java99
-rw-r--r--sched/src/com/android/sched/vfs/InputZipVDir.java133
-rw-r--r--sched/src/com/android/sched/vfs/InputZipVFS.java133
-rw-r--r--sched/src/com/android/sched/vfs/InputZipVFile.java67
-rw-r--r--sched/src/com/android/sched/vfs/OutputZipVDir.java68
-rw-r--r--sched/src/com/android/sched/vfs/OutputZipVFS.java81
-rw-r--r--sched/src/com/android/sched/vfs/OutputZipVFile.java94
-rw-r--r--sched/src/com/android/sched/vfs/PrefixedInputVFS.java53
-rw-r--r--sched/src/com/android/sched/vfs/PrefixedOutputVFS.java68
-rw-r--r--sched/tests/com/android/sched/vfs/VFSTest.java121
16 files changed, 10 insertions, 1503 deletions
diff --git a/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java b/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java
index 6871bf3a..d0f4d338 100644
--- a/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java
+++ b/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java
@@ -21,8 +21,9 @@ import com.android.sched.util.RunnableHooks;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.OutputZipFile;
import com.android.sched.util.log.LoggerFactory;
+import com.android.sched.vfs.GenericInputOutputVFS;
import com.android.sched.vfs.InputOutputVFS;
-import com.android.sched.vfs.InputOutputZipVFS;
+import com.android.sched.vfs.ReadWriteZipFS;
import java.io.IOException;
import java.util.logging.Logger;
@@ -55,9 +56,9 @@ public class ZipInputOutputVFSCodec extends InputOutputVFSCodec
@Nonnull final String string) throws ParsingException {
RunnableHooks hooks = context.getRunnableHooks();
try {
- final InputOutputZipVFS vDir =
- new InputOutputZipVFS(new OutputZipFile(string, hooks, existence, change));
- return vDir;
+ final ReadWriteZipFS vfs =
+ new ReadWriteZipFS(new OutputZipFile(string, hooks, existence, change));
+ return new GenericInputOutputVFS(vfs);
} catch (IOException e) {
throw new ParsingException(e.getMessage(), e);
}
diff --git a/sched/src/com/android/sched/vfs/DirectDir.java b/sched/src/com/android/sched/vfs/DirectDir.java
deleted file mode 100644
index ffb9216f..00000000
--- a/sched/src/com/android/sched/vfs/DirectDir.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.ConcurrentIOException;
-import com.android.sched.util.file.CannotCreateFileException;
-import com.android.sched.util.file.NoSuchFileException;
-import com.android.sched.util.file.NotDirectoryException;
-import com.android.sched.util.file.NotFileException;
-import com.android.sched.util.location.DirectoryLocation;
-import com.android.sched.util.location.FileLocation;
-import com.android.sched.util.location.Location;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-
-import javax.annotation.Nonnull;
-
-/**
- * A VFS directory backed by a real filesystem directory.
- */
-public class DirectDir extends AbstractVElement implements InputOutputVDir {
- @Nonnull
- private final File dir;
- @Nonnull
- private final InputOutputVFS vfs;
-
- DirectDir(@Nonnull File dir, @Nonnull InputOutputVFS vfs)
- throws NotDirectoryException {
- if (!dir.isDirectory()) {
- throw new NotDirectoryException(new DirectoryLocation(dir));
- }
- this.dir = dir;
- this.vfs = vfs;
- }
-
- @Nonnull
- @Override
- public String getName() {
- return dir.getName();
- }
-
- @Nonnull
- @Override
- public synchronized Collection<? extends InputVElement> list() {
- File[] subs = dir.listFiles();
- if (subs == null) {
- throw new ConcurrentIOException(new ListDirException(dir));
- }
- if (subs.length == 0) {
- return Collections.emptyList();
- }
-
- ArrayList<InputVElement> items = new ArrayList<InputVElement>(subs.length);
- for (File sub : subs) {
- try {
- if (sub.isFile()) {
- items.add(new DirectFile(sub, vfs));
- } else {
- items.add(new DirectDir(sub, vfs));
- }
- } catch (NotDirectoryException e) {
- throw new ConcurrentIOException(e);
- }
- }
-
- return items;
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new DirectoryLocation(dir);
- }
-
- @Override
- @Nonnull
- public InputOutputVFile getInputVFile(@Nonnull VPath path) throws NotFileException,
- NoSuchFileException {
- File file = new File(dir, path.getPathAsString(File.separatorChar));
- if (!file.exists()) {
- throw new NoSuchFileException(new FileLocation(file));
- }
- if (!file.isFile()) {
- throw new NotFileException(new FileLocation(file));
- }
- return new DirectFile(file, vfs);
- }
-
- @Override
- @Nonnull
- public InputOutputVDir getInputVDir(@Nonnull VPath path) throws NotDirectoryException,
- NoSuchFileException {
- File file = new File(dir, path.getPathAsString(File.separatorChar));
- if (!file.exists()) {
- throw new NoSuchFileException(new DirectoryLocation(file));
- }
- if (file.isFile()) {
- throw new NotDirectoryException(new DirectoryLocation(file));
- }
- return new DirectDir(file, vfs);
- }
-
- @Override
- @Nonnull
- public OutputVFile createOutputVFile(@Nonnull VPath path) throws CannotCreateFileException {
- File file = new File(dir, path.getPathAsString(File.separatorChar));
- if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {
- throw new CannotCreateFileException(new DirectoryLocation(file.getParentFile()));
- }
- return new DirectFile(file, vfs);
- }
-
- @Override
- @Nonnull
- public OutputVDir createOutputVDir(@Nonnull VPath path) throws CannotCreateFileException,
- NotDirectoryException {
- File file = new File(dir, path.getPathAsString(File.separatorChar));
- if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {
- throw new CannotCreateFileException(new DirectoryLocation(file.getParentFile()));
- }
- if (!file.mkdir()) {
- throw new CannotCreateFileException(new DirectoryLocation(file));
- }
- return new DirectDir(file, vfs);
- }
-
- @Override
- public boolean isVDir() {
- return true;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/DirectFile.java b/sched/src/com/android/sched/vfs/DirectFile.java
deleted file mode 100644
index 2bc170b2..00000000
--- a/sched/src/com/android/sched/vfs/DirectFile.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.ConcurrentIOException;
-import com.android.sched.util.file.CannotCreateFileException;
-import com.android.sched.util.file.CannotDeleteFileException;
-import com.android.sched.util.file.InputStreamFile;
-import com.android.sched.util.file.NoSuchFileException;
-import com.android.sched.util.file.NotFileException;
-import com.android.sched.util.file.OutputStreamFile;
-import com.android.sched.util.file.WrongPermissionException;
-import com.android.sched.util.location.FileLocation;
-import com.android.sched.util.location.Location;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.annotation.Nonnull;
-
-/**
- * A {@code VFile} directly backed by a {@code java.io.File}.
- */
-public class DirectFile extends AbstractVElement implements InputOutputVFile {
-
- @Nonnull
- private final File file;
- @Nonnull
- private final InputOutputVFS vfs;
-
- DirectFile(@Nonnull File file, @Nonnull InputOutputVFS vfs) {
- this.file = file;
- this.vfs = vfs;
- }
-
- @Nonnull
- @Override
- public InputStream openRead() throws WrongPermissionException {
- try {
- return new InputStreamFile(file.getPath()).getInputStream();
- } catch (NoSuchFileException e) {
- // we have already checked that the file exists when creating the VFile in the VDir
- throw new ConcurrentIOException(e);
- } catch (NotFileException e) {
- // we have already checked that this is not a directory when creating the VFile in the VDir
- throw new ConcurrentIOException(e);
- }
- }
-
- @Nonnull
- @Override
- public OutputStream openWrite() throws CannotCreateFileException, WrongPermissionException,
- NotFileException {
- return new OutputStreamFile(file.getPath(), null).getOutputStream();
- }
-
- @Nonnull
- @Override
- public String getName() {
- return file.getName();
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new FileLocation(file);
- }
-
- @Override
- public boolean isVDir() {
- return false;
- }
-
- @Override
- public void delete() throws CannotDeleteFileException {
- if (!file.delete()) {
- throw new CannotDeleteFileException(getLocation());
- }
- }
-}
diff --git a/sched/src/com/android/sched/vfs/DirectVFS.java b/sched/src/com/android/sched/vfs/DirectVFS.java
deleted file mode 100644
index 951c05e5..00000000
--- a/sched/src/com/android/sched/vfs/DirectVFS.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.ConcurrentIOException;
-import com.android.sched.util.file.Directory;
-import com.android.sched.util.file.NotDirectoryException;
-import com.android.sched.util.location.Location;
-
-import javax.annotation.Nonnull;
-
-/**
- * A VFS directory backed by a real filesystem directory.
- */
-public class DirectVFS extends AbstractInputOutputVFS {
- @Nonnull
- private final Directory dir;
-
- public DirectVFS(@Nonnull Directory dir) {
- this.dir = dir;
-
- try {
- setRootDir(new DirectDir(dir.getFile(), this));
- } catch (NotDirectoryException e) {
- throw new ConcurrentIOException(e);
- }
- }
-
- @Override
- public void close() {
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return dir.getLocation();
- }
-
- @Override
- @Nonnull
- public String getPath() {
- return dir.getPath();
- }
-
- @Override
- public boolean needsSequentialWriting() {
- return false;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/InputOutputZipVDir.java b/sched/src/com/android/sched/vfs/InputOutputZipVDir.java
deleted file mode 100644
index 6f490820..00000000
--- a/sched/src/com/android/sched/vfs/InputOutputZipVDir.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.ConcurrentIOException;
-import com.android.sched.util.file.CannotCreateFileException;
-import com.android.sched.util.file.NoSuchFileException;
-import com.android.sched.util.file.NotDirectoryException;
-import com.android.sched.util.file.NotFileException;
-import com.android.sched.util.location.DirectoryLocation;
-import com.android.sched.util.location.FileLocation;
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.zip.ZipEntry;
-
-import javax.annotation.Nonnull;
-
-/**
- * A directory in an {@link InputOutputZipVFS} VFS.
- */
-class InputOutputZipVDir extends AbstractVElement implements InputOutputVDir {
-
- @Nonnull
- protected final File dir;
- @Nonnull
- protected final InputOutputZipVFS vfs;
- @Nonnull
- private final ZipEntry zipEntry;
-
- public InputOutputZipVDir(@Nonnull InputOutputZipVFS vfs, @Nonnull File dir,
- @Nonnull ZipEntry zipEntry) {
- this.vfs = vfs;
- this.dir = dir;
- this.zipEntry = zipEntry;
- }
-
- @Nonnull
- @Override
- public String getName() {
- return dir.getName();
- }
-
- @Nonnull
- @Override
- public synchronized Collection<? extends InputVElement> list() {
- File[] subs = dir.listFiles();
- if (subs == null) {
- throw new ConcurrentIOException(new ListDirException(dir));
- }
- if (subs.length == 0) {
- return Collections.emptyList();
- }
-
- ArrayList<InputVElement> items = new ArrayList<InputVElement>(subs.length);
- for (File sub : subs) {
- String subZipEntryName = zipEntry.getName() + sub.getName();
- if (sub.isFile()) {
- items.add(new InputOutputZipVFile(vfs, sub, new ZipEntry(subZipEntryName)));
- } else {
- items.add(new InputOutputZipVDir(vfs, sub,
- new ZipEntry(subZipEntryName + ZipUtils.ZIP_SEPARATOR)));
- }
- }
-
- return items;
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new ZipLocation(vfs.getLocation(), zipEntry);
- }
-
- @Override
- public boolean isVDir() {
- return true;
- }
-
- @Override
- @Nonnull
- public OutputVFile createOutputVFile(@Nonnull VPath path) throws CannotCreateFileException {
- assert !vfs.isClosed();
- File file = new File(dir, path.getPathAsString(ZipUtils.ZIP_SEPARATOR));
- if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {
- throw new CannotCreateFileException(new DirectoryLocation(file.getParentFile()));
- }
-
- assert !(path.equals(VPath.ROOT));
- String newEntryName = path.getPathAsString(ZipUtils.ZIP_SEPARATOR);
- String parentEntryName = zipEntry.getName();
- if (!parentEntryName.isEmpty()) {
- newEntryName = parentEntryName + newEntryName;
- }
- return new InputOutputZipVFile(vfs, file, new ZipEntry(newEntryName));
- }
-
- @Override
- @Nonnull
- public OutputVDir createOutputVDir(@Nonnull VPath path) throws CannotCreateFileException {
- assert !vfs.isClosed();
- File file = new File(dir, path.getPathAsString(ZipUtils.ZIP_SEPARATOR));
- if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {
- throw new CannotCreateFileException(new DirectoryLocation(file.getParentFile()));
- }
-
- if (!file.mkdir()) {
- throw new CannotCreateFileException(new DirectoryLocation(file));
- }
-
- assert !(path.equals(VPath.ROOT));
- String newEntryName = path.getPathAsString(ZipUtils.ZIP_SEPARATOR);
- String parentEntryName = zipEntry.getName();
- if (!parentEntryName.isEmpty()) {
- newEntryName = parentEntryName + newEntryName;
- }
- return new InputOutputZipVDir(vfs, file, new ZipEntry(newEntryName));
- }
-
- @Override
- @Nonnull
- public InputOutputVDir getInputVDir(@Nonnull VPath path) throws NotDirectoryException,
- NoSuchFileException {
- File file = new File(dir, path.getPathAsString(File.separatorChar));
- if (!file.exists()) {
- throw new NoSuchFileException(new DirectoryLocation(file));
- }
- if (file.isFile()) {
- throw new NotDirectoryException(new DirectoryLocation(file));
- }
- return new InputOutputZipVDir(vfs, file,
- new ZipEntry(path.getPathAsString(ZipUtils.ZIP_SEPARATOR) + ZipUtils.ZIP_SEPARATOR));
- }
-
- @Override
- @Nonnull
- public InputOutputVFile getInputVFile(@Nonnull VPath path) throws NotFileException,
- NoSuchFileException {
- File file = new File(dir, path.getPathAsString(File.separatorChar));
- if (!file.exists()) {
- throw new NoSuchFileException(new FileLocation(file));
- }
- if (!file.isFile()) {
- throw new NotFileException(new FileLocation(file));
- }
- return new InputOutputZipVFile(vfs, file,
- new ZipEntry(path.getPathAsString(ZipUtils.ZIP_SEPARATOR)));
- }
-}
diff --git a/sched/src/com/android/sched/vfs/InputOutputZipVFS.java b/sched/src/com/android/sched/vfs/InputOutputZipVFS.java
deleted file mode 100644
index e5aaa6c1..00000000
--- a/sched/src/com/android/sched/vfs/InputOutputZipVFS.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.google.common.io.Files;
-
-import com.android.sched.util.file.FileUtils;
-import com.android.sched.util.file.OutputZipFile;
-import com.android.sched.util.location.Location;
-import com.android.sched.util.stream.ByteStreamSucker;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import javax.annotation.Nonnull;
-
-/**
- * The root of a VFS backed by a real filesystem directory, compressed into a zip archive when
- * closed.
- */
-public class InputOutputZipVFS extends AbstractInputOutputVFS implements InputOutputVFS {
-
- private boolean closed = false;
- @Nonnull
- private final OutputZipFile zipFile;
- @Nonnull
- private final File dir;
- @Nonnull
- private final ZipOutputStream zipOS;
-
- public InputOutputZipVFS(@Nonnull OutputZipFile zipFile) {
- this.zipFile = zipFile;
- dir = Files.createTempDir();
- setRootDir(new InputOutputZipVDir(this, dir, new ZipEntry(ZipUtils.ROOT_ENTRY_NAME)));
- // it would be better to open the stream in the close() method, but it's not possible because
- // close() is called by a shutdown hook and OutputZipFile.getOutputStream() modifies those hooks
- zipOS = zipFile.getOutputStream();
- }
-
- @Override
- public synchronized void close() throws IOException {
- if (!closed) {
- try {
- addDirToZip(zipOS, getRootInputOutputVDir());
- } finally {
- zipOS.close();
- FileUtils.deleteDir(dir);
- closed = true;
- }
- }
- }
-
- @Override
- @Nonnull
- public InputOutputZipVDir getRootInputOutputVDir() {
- return (InputOutputZipVDir) super.getRootInputOutputVDir();
- }
-
- private void addDirToZip(@Nonnull ZipOutputStream zos, @Nonnull InputOutputZipVDir vDir)
- throws IOException {
- for (InputVElement sub : vDir.list()) {
- if (sub.isVDir()) {
- addDirToZip(zos, (InputOutputZipVDir) sub);
- } else {
- InputOutputZipVFile vFile = (InputOutputZipVFile) sub;
- zos.putNextEntry(vFile.getZipEntry());
- InputStream is = vFile.openRead();
- try {
- new ByteStreamSucker(is, zos).suck();
- } finally {
- is.close();
- }
- }
- }
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return zipFile.getLocation();
- }
-
- @Override
- @Nonnull
- public String getPath() {
- return zipFile.getPath();
- }
-
- synchronized boolean isClosed() {
- return closed;
- }
-
- @Override
- public boolean needsSequentialWriting() {
- return false;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/InputOutputZipVFile.java b/sched/src/com/android/sched/vfs/InputOutputZipVFile.java
deleted file mode 100644
index c817cd62..00000000
--- a/sched/src/com/android/sched/vfs/InputOutputZipVFile.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.file.CannotDeleteFileException;
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.zip.ZipEntry;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-/**
- * A file in an {@link InputOutputZipVFS} VFS.
- */
-class InputOutputZipVFile extends AbstractVElement implements InputOutputVFile {
-
- @Nonnull
- private final File file;
- @CheckForNull
- private ArrayList<InputVElement> list;
- @Nonnull
- private final InputOutputZipVFS vfs;
- @Nonnull
- private final ZipEntry zipEntry;
-
- public InputOutputZipVFile(@Nonnull InputOutputZipVFS vfs, @Nonnull File file,
- @Nonnull ZipEntry zipEntry) {
- this.vfs = vfs;
- this.zipEntry = zipEntry;
- this.file = file;
- }
-
- @Nonnull
- @Override
- public String getName() {
- return file.getName();
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new ZipLocation(vfs.getLocation(), zipEntry);
- }
-
- @Override
- public boolean isVDir() {
- return false;
- }
-
-
- @Nonnull
- @Override
- public InputStream openRead() throws FileNotFoundException {
- return new FileInputStream(file);
- }
-
- @Nonnull
- @Override
- public OutputStream openWrite() throws FileNotFoundException {
- assert !vfs.isClosed();
- return new FileOutputStream(file);
- }
-
- @Nonnull
- public ZipEntry getZipEntry() {
- return zipEntry;
- }
-
- @Override
- public void delete() throws CannotDeleteFileException {
- assert !vfs.isClosed();
- if (!file.delete()) {
- throw new CannotDeleteFileException(getLocation());
- }
- }
-}
diff --git a/sched/src/com/android/sched/vfs/InputZipVDir.java b/sched/src/com/android/sched/vfs/InputZipVDir.java
deleted file mode 100644
index 68eca1b5..00000000
--- a/sched/src/com/android/sched/vfs/InputZipVDir.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.file.NoSuchFileException;
-import com.android.sched.util.file.NotDirectoryException;
-import com.android.sched.util.file.NotFileException;
-import com.android.sched.util.file.NotFileOrDirectoryException;
-import com.android.sched.util.location.DirectoryLocation;
-import com.android.sched.util.location.FileLocation;
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.zip.ZipEntry;
-
-import javax.annotation.Nonnull;
-
-class InputZipVDir extends AbstractVElement implements InputVDir {
-
- @Nonnull
- private final InputZipVFS vfs;
- @Nonnull
- protected final HashMap<String, InputVElement> subs = new HashMap<String, InputVElement>();
- @Nonnull
- private final ZipEntry entry;
-
- InputZipVDir(@Nonnull InputZipVFS vfs, @Nonnull ZipEntry entry) {
- this.vfs = vfs;
- this.entry = entry;
- }
-
- @Nonnull
- @Override
- public String getName() {
- return ZipUtils.getDirSimpleName(entry);
- }
-
- @Nonnull
- @Override
- public Collection<? extends InputVElement> list() {
- return subs.values();
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new ZipLocation(vfs.getLocation(), entry);
- }
-
- @Override
- public boolean isVDir() {
- return true;
- }
-
- @Override
- @Nonnull
- public InputVFile getInputVFile(@Nonnull VPath path) throws NoSuchFileException,
- NotFileOrDirectoryException {
- Iterator<String> iterator = path.split().iterator();
- assert iterator.hasNext();
- String firstElement = iterator.next();
- InputVElement ive = subs.get(firstElement);
- String pathAsString = path.getPathAsString(ZipUtils.ZIP_SEPARATOR);
-
- if (ive == null) {
- throw new NoSuchFileException(new FileLocation(pathAsString));
- }
-
- if (iterator.hasNext()) {
- if (ive instanceof InputVDir) {
- ive = ((InputVDir) ive).getInputVFile(new VPath(
- pathAsString.substring(pathAsString.indexOf(ZipUtils.ZIP_SEPARATOR) + 1),
- ZipUtils.ZIP_SEPARATOR));
- }
- }
-
- if (ive.isVDir()) {
- throw new NotFileException(new FileLocation(pathAsString));
- }
-
- return (InputVFile) ive;
- }
-
- @Override
- @Nonnull
- public InputVDir getInputVDir(@Nonnull VPath path) throws NotDirectoryException,
- NoSuchFileException {
- if (path.equals(VPath.ROOT)) {
- return this;
- }
-
- Iterator<String> iterator = path.split().iterator();
- assert iterator.hasNext();
- String firstElement = iterator.next();
- InputVElement ive = subs.get(firstElement);
- String pathAsString = path.getPathAsString(ZipUtils.ZIP_SEPARATOR);
-
- if (ive == null) {
- throw new NoSuchFileException(new DirectoryLocation(pathAsString));
- }
-
- if (iterator.hasNext()) {
- if (ive instanceof InputVDir) {
- ive = ((InputVDir) ive).getInputVDir(new VPath(
- pathAsString.substring(pathAsString.indexOf(ZipUtils.ZIP_SEPARATOR) + 1),
- ZipUtils.ZIP_SEPARATOR));
- }
- }
-
- if (!ive.isVDir()) {
- throw new NotDirectoryException(new DirectoryLocation(pathAsString));
- }
-
- return (InputVDir) ive;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/InputZipVFS.java b/sched/src/com/android/sched/vfs/InputZipVFS.java
deleted file mode 100644
index dd3216c7..00000000
--- a/sched/src/com/android/sched/vfs/InputZipVFS.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.google.common.base.Splitter;
-
-import com.android.sched.util.file.InputZipFile;
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-/**
- * Virtual directory for viewing the content of a zip file.
- */
-public class InputZipVFS extends AbstractInputVFS {
- @Nonnull
- private final ZipFile zip;
- @Nonnull
- private final Location location;
- @Nonnull
- private final String path;
- private static final Splitter splitter = Splitter.on(ZipUtils.ZIP_SEPARATOR);
-
- public InputZipVFS(@Nonnull InputZipFile zipFile) {
- setRootDir(new InputZipVDir(this, new ZipEntry(ZipUtils.ROOT_ENTRY_NAME)));
- this.zip = zipFile.getZipFile();
- this.location = zipFile.getLocation();
- this.path = zipFile.getPath();
-
- fillSubElements(zip, null);
- }
-
- public InputZipVFS(@Nonnull InputZipFile zipFile, @Nonnull String prefix) {
- setRootDir(new InputZipVDir(this, new ZipEntry(prefix)));
- assert prefix.endsWith(ZipUtils.ZIP_SEPARATOR_STRING);
- this.zip = zipFile.getZipFile();
- this.location = new ZipLocation(zipFile.getLocation(), new ZipEntry(prefix));
- this.path = zipFile.getPath().substring(prefix.length());
-
- fillSubElements(zip, prefix);
- }
-
- private void fillSubElements(@Nonnull ZipFile zip, @CheckForNull String prefix) {
-
- for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements();) {
- ZipEntry entry = entries.nextElement();
- if (!entry.isDirectory()) {
- String entryName = entry.getName();
- if (prefix == null || entryName.startsWith(prefix)) {
- InputZipVDir dir = getRootInputVDir();
- StringBuilder inZipPath = new StringBuilder();
- String relativePath;
- if (prefix != null) {
- relativePath = entryName.substring(prefix.length(), entryName.length());
- inZipPath.append(prefix);
- } else {
- relativePath = entryName;
- }
- Iterator<String> names = splitter.split(relativePath).iterator();
-
- String simpleName = null;
- while (names.hasNext()) {
- simpleName = names.next();
- assert !simpleName.isEmpty();
- if (names.hasNext()) {
- // simpleName is a dir name
- inZipPath.append(simpleName).append(ZipUtils.ZIP_SEPARATOR);
- InputZipVDir nextDir = (InputZipVDir) dir.subs.get(simpleName);
- if (nextDir == null) {
- // VDir does not already exist
- nextDir = new InputZipVDir(this, new ZipEntry(inZipPath.toString()));
- dir.subs.put(simpleName, nextDir);
- }
- dir = nextDir;
- }
- }
- dir.subs.put(simpleName, new InputZipVFile(this, entry));
- }
- }
- }
-
- }
-
- @Nonnull
- ZipFile getZipFile() {
- return zip;
- }
-
- @Override
- @Nonnull
- public InputZipVDir getRootInputVDir() {
- return (InputZipVDir) super.getRootInputVDir();
- }
-
- @Override
- public void close() throws IOException {
- zip.close();
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return location;
- }
-
- @Override
- @Nonnull
- public String getPath() {
- return path;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/InputZipVFile.java b/sched/src/com/android/sched/vfs/InputZipVFile.java
deleted file mode 100644
index 0f115be2..00000000
--- a/sched/src/com/android/sched/vfs/InputZipVFile.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-
-import javax.annotation.Nonnull;
-
-class InputZipVFile extends AbstractVElement implements InputVFile {
- @Nonnull
- private final InputZipVFS vfs;
- @Nonnull
- private final ZipEntry entry;
-
- InputZipVFile(@Nonnull InputZipVFS vfs, @Nonnull ZipEntry entry) {
- this.vfs = vfs;
- this.entry = entry;
- }
-
- @Nonnull
- @Override
- public String getName() {
- return ZipUtils.getFileSimpleName(entry);
- }
-
- @Nonnull
- @Override
- public InputStream openRead() throws IOException {
- return vfs.getZipFile().getInputStream(entry);
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new ZipLocation(vfs.getLocation(), entry);
- }
-
- @Override
- public boolean isVDir() {
- return false;
- }
-
- @Override
- public void delete() {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/sched/src/com/android/sched/vfs/OutputZipVDir.java b/sched/src/com/android/sched/vfs/OutputZipVDir.java
deleted file mode 100644
index eeb92343..00000000
--- a/sched/src/com/android/sched/vfs/OutputZipVDir.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.util.zip.ZipEntry;
-
-import javax.annotation.Nonnull;
-
-/**
- * A root {@link OutputVDir} backed by a zip archive.
- */
-public class OutputZipVDir extends AbstractVElement implements OutputVDir {
- @Nonnull
- private final OutputZipVFS vfs;
- @Nonnull
- private final ZipEntry entry;
-
- public OutputZipVDir(@Nonnull OutputZipVFS vfs, @Nonnull ZipEntry entry) {
- this.vfs = vfs;
- this.entry = entry;
- }
-
- @Override
- @Nonnull
- public String getName() {
- return ZipUtils.getDirSimpleName(entry);
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new ZipLocation(vfs.getLocation(), entry);
- }
-
- @Override
- @Nonnull
- public OutputVFile createOutputVFile(@Nonnull VPath path) {
- assert !(path.equals(VPath.ROOT));
- String newEntryName = path.getPathAsString(ZipUtils.ZIP_SEPARATOR);
- String parentEntryName = entry.getName();
- if (!parentEntryName.isEmpty()) {
- newEntryName = parentEntryName + ZipUtils.ZIP_SEPARATOR + newEntryName;
- }
- return new OutputZipVFile(vfs, new ZipEntry(newEntryName));
- }
-
- @Override
- public boolean isVDir() {
- return true;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/OutputZipVFS.java b/sched/src/com/android/sched/vfs/OutputZipVFS.java
deleted file mode 100644
index 7f6fcebe..00000000
--- a/sched/src/com/android/sched/vfs/OutputZipVFS.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.file.OutputZipFile;
-import com.android.sched.util.location.Location;
-
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import javax.annotation.Nonnull;
-
-/**
- * A root {@link OutputVDir} backed by a zip archive.
- */
-public class OutputZipVFS extends AbstractOutputVFS {
- @Nonnull
- protected final ZipOutputStream zos;
- @Nonnull
- private final OutputZipFile file;
- @Nonnull
- private final AtomicBoolean lastVFileOpen = new AtomicBoolean(false);
-
- public OutputZipVFS(@Nonnull OutputZipFile file) {
- setRootDir(new OutputZipVDir(this, new ZipEntry(ZipUtils.ROOT_ENTRY_NAME)));
- zos = file.getOutputStream();
- this.file = file;
- }
-
- void notifyVFileClosed() {
- boolean previousState = lastVFileOpen.getAndSet(false);
- assert previousState;
- }
-
- boolean notifyVFileOpenAndReturnPreviousState() {
- return lastVFileOpen.getAndSet(true);
- }
-
- @Override
- public void close() throws IOException {
- zos.close();
- }
-
- @Nonnull
- ZipOutputStream getZipOutputStream() {
- return zos;
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return file.getLocation();
- }
-
- @Override
- @Nonnull
- public String getPath() {
- return file.getPath();
- }
-
- @Override
- public boolean needsSequentialWriting() {
- return true;
- }
-}
diff --git a/sched/src/com/android/sched/vfs/OutputZipVFile.java b/sched/src/com/android/sched/vfs/OutputZipVFile.java
deleted file mode 100644
index 72db4a9e..00000000
--- a/sched/src/com/android/sched/vfs/OutputZipVFile.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.location.Location;
-import com.android.sched.util.location.ZipLocation;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.zip.ZipEntry;
-
-import javax.annotation.Nonnull;
-
-class OutputZipVFile extends AbstractVElement implements OutputVFile {
- @Nonnull
- private final OutputZipVFS vfs;
- @Nonnull
- private final ZipEntry entry;
-
- OutputZipVFile(@Nonnull OutputZipVFS vfs, @Nonnull ZipEntry entry) {
- this.vfs = vfs;
- this.entry = entry;
- }
-
- @Nonnull
- @Override
- public OutputStream openWrite() throws IOException {
- vfs.getZipOutputStream().putNextEntry(entry);
- if (vfs.notifyVFileOpenAndReturnPreviousState()) {
- throw new AssertionError(getLocation().getDescription()
- + " cannot be written to because a previous stream has not been closed.");
- }
-
- return new UnclosableVFileOutputStream(vfs);
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return new ZipLocation(vfs.getLocation(), entry);
- }
-
- @Override
- public boolean isVDir() {
- return false;
- }
-
- @Override
- @Nonnull
- public String getName() {
- return ZipUtils.getFileSimpleName(entry);
- }
-
- private static class UnclosableVFileOutputStream extends FilterOutputStream {
- @Nonnull
- private final OutputZipVFS vfs;
-
- public UnclosableVFileOutputStream(@Nonnull OutputZipVFS vfs) {
- super(vfs.getZipOutputStream());
- this.vfs = vfs;
- }
-
- @Override
- public void close() {
- // we do not actually close the stream
- vfs.notifyVFileClosed();
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- out.write(b);
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- out.write(b, off, len);
- }
- }
-}
diff --git a/sched/src/com/android/sched/vfs/PrefixedInputVFS.java b/sched/src/com/android/sched/vfs/PrefixedInputVFS.java
deleted file mode 100644
index 517f5ee2..00000000
--- a/sched/src/com/android/sched/vfs/PrefixedInputVFS.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.file.NoSuchFileException;
-import com.android.sched.util.file.NotDirectoryException;
-import com.android.sched.util.location.Location;
-
-import javax.annotation.Nonnull;
-
-/**
- * An {@link InputVFS} that is a part of another {@link InputVFS}, prefixed by a path. The parent
- * {@link InputVFS} is still the one that needs to be closed.
- */
-public class PrefixedInputVFS extends AbstractInputVFS {
-
- public PrefixedInputVFS(@Nonnull InputVFS inputVFS, @Nonnull VPath path)
- throws NotDirectoryException, NoSuchFileException {
- InputVDir previousRootDir = inputVFS.getRootInputVDir();
- setRootDir(previousRootDir.getInputVDir(path));
- }
-
- @Override
- @Nonnull
- public String getPath() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return getRootInputVDir().getLocation();
- }
-
- @Override
- public void close() {
- // do not actually close
- }
-}
diff --git a/sched/src/com/android/sched/vfs/PrefixedOutputVFS.java b/sched/src/com/android/sched/vfs/PrefixedOutputVFS.java
deleted file mode 100644
index 262c24db..00000000
--- a/sched/src/com/android/sched/vfs/PrefixedOutputVFS.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sched.vfs;
-
-import com.android.sched.util.file.CannotCreateFileException;
-import com.android.sched.util.file.NoSuchFileException;
-import com.android.sched.util.file.NotDirectoryException;
-import com.android.sched.util.location.Location;
-
-import javax.annotation.Nonnull;
-
-/**
- * An {@link OutputVFS} that is a part of another {@link OutputVFS}, prefixed by a path. The parent
- * {@link OutputVFS} is still the one that needs to be closed.
- */
-public class PrefixedOutputVFS extends AbstractOutputVFS {
-
- private final boolean needsSequentialWriting;
-
- public PrefixedOutputVFS(@Nonnull InputOutputVFS outputVFS, @Nonnull VPath path)
- throws NotDirectoryException, CannotCreateFileException {
- InputOutputVDir previousRootDir = outputVFS.getRootInputOutputVDir();
- OutputVDir newRootDir = null;
- try {
- newRootDir = previousRootDir.getInputVDir(path);
- } catch (NoSuchFileException e) {
- newRootDir = previousRootDir.createOutputVDir(path);
- }
- setRootDir(newRootDir);
- needsSequentialWriting = outputVFS.needsSequentialWriting();
- }
-
- @Override
- @Nonnull
- public String getPath() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- @Nonnull
- public Location getLocation() {
- return getRootOutputVDir().getLocation();
- }
-
- @Override
- public void close() {
- // do not actually close
- }
-
- @Override
- public boolean needsSequentialWriting() {
- return needsSequentialWriting;
- }
-}
diff --git a/sched/tests/com/android/sched/vfs/VFSTest.java b/sched/tests/com/android/sched/vfs/VFSTest.java
index 0769a409..50b6ff99 100644
--- a/sched/tests/com/android/sched/vfs/VFSTest.java
+++ b/sched/tests/com/android/sched/vfs/VFSTest.java
@@ -62,45 +62,6 @@ public class VFSTest {
}
@Test
- public void testDirectVFS()
- throws NotDirectoryException,
- CannotCreateFileException,
- WrongPermissionException,
- CannotSetPermissionException,
- NoSuchFileException,
- FileAlreadyExistsException,
- IOException {
- File file = null;
- DirectVFS directVFS = null;
- DirectVFS directVFS2 = null;
- try {
- file = File.createTempFile("vfs", "dir");
- String path = file.getAbsolutePath();
- Assert.assertTrue(file.delete());
- directVFS = new DirectVFS(new Directory(path, null, Existence.NOT_EXIST,
- Permission.READ | Permission.WRITE, ChangePermission.NOCHANGE));
- testOutputVFS(directVFS);
- testDelete(directVFS);
- testInputVFS(directVFS);
- directVFS.close();
-
- directVFS2 = new DirectVFS(new Directory(path, null, Existence.MUST_EXIST,
- Permission.READ | Permission.WRITE, ChangePermission.NOCHANGE));
- testInputVFS(directVFS2);
- } finally {
- if (directVFS != null) {
- directVFS.close();
- }
- if (directVFS2 != null) {
- directVFS2.close();
- }
- if (file != null) {
- FileUtils.deleteDir(file);
- }
- }
- }
-
- @Test
public void testDirectFS()
throws NotDirectoryException,
CannotCreateFileException,
@@ -397,7 +358,7 @@ public class VFSTest {
IOException {
File file = null;
InputOutputVFS outputZipVFS = null;
- InputZipVFS inputZipVFS = null;
+ InputVFS inputZipVFS = null;
try {
file = File.createTempFile("vfs", ".zip");
String path = file.getAbsolutePath();
@@ -405,78 +366,6 @@ public class VFSTest {
new OutputZipFile(path, null, Existence.MAY_EXIST, ChangePermission.NOCHANGE)));
testOutputVFS(outputZipVFS);
outputZipVFS.close();
- inputZipVFS = new InputZipVFS(
- new InputZipFile(path, null, Existence.MUST_EXIST, ChangePermission.NOCHANGE));
- testInputVFS(inputZipVFS);
- } finally {
- if (outputZipVFS != null) {
- outputZipVFS.close();
- }
- if (inputZipVFS != null) {
- inputZipVFS.close();
- }
- if (file != null) {
- Assert.assertTrue(file.delete());
- }
- }
- }
-
- @Test
- public void testInputOutputZipVFS()
- throws NotDirectoryException,
- CannotCreateFileException,
- WrongPermissionException,
- CannotSetPermissionException,
- NoSuchFileException,
- FileAlreadyExistsException,
- IOException {
- File file = null;
- InputOutputZipVFS zipVFS = null;
- InputZipVFS inputZipVFS = null;
- try {
- file = File.createTempFile("vfs", ".zip");
- String path = file.getAbsolutePath();
- zipVFS = new InputOutputZipVFS(
- new OutputZipFile(path, null, Existence.MAY_EXIST, ChangePermission.NOCHANGE));
- testOutputVFS(zipVFS);
- testDelete(zipVFS);
- testInputVFS(zipVFS);
- zipVFS.close();
- inputZipVFS = new InputZipVFS(
- new InputZipFile(path, null, Existence.MUST_EXIST, ChangePermission.NOCHANGE));
- testInputVFS(inputZipVFS);
- } finally {
- if (zipVFS != null) {
- zipVFS.close();
- }
- if (inputZipVFS != null) {
- inputZipVFS.close();
- }
- if (file != null) {
- Assert.assertTrue(file.delete());
- }
- }
- }
-
- @Test
- public void testReadZipVFS()
- throws NotDirectoryException,
- CannotCreateFileException,
- WrongPermissionException,
- CannotSetPermissionException,
- NoSuchFileException,
- FileAlreadyExistsException,
- IOException {
- File file = null;
- InputOutputVFS outputZipVFS = null;
- InputVFS inputZipVFS = null;
- try {
- file = File.createTempFile("vfs", ".zip");
- String path = file.getAbsolutePath();
- outputZipVFS = new InputOutputZipVFS(
- new OutputZipFile(path, null, Existence.MAY_EXIST, ChangePermission.NOCHANGE));
- testOutputVFS(outputZipVFS);
- outputZipVFS.close();
inputZipVFS = new GenericInputVFS(new ReadZipFS(
new InputZipFile(path, null, Existence.MUST_EXIST, ChangePermission.NOCHANGE)));
testInputVFS(inputZipVFS);
@@ -558,7 +447,7 @@ public class VFSTest {
}
@Test
- public void testReadWriteZipFS()
+ public void testReadWriteZipFSAndReadZipFS()
throws NotDirectoryException,
CannotCreateFileException,
WrongPermissionException,
@@ -568,7 +457,7 @@ public class VFSTest {
IOException {
File file = null;
InputOutputVFS zipVFS = null;
- InputZipVFS inputZipVFS = null;
+ InputVFS inputZipVFS = null;
try {
file = File.createTempFile("vfs", ".zip");
String path = file.getAbsolutePath();
@@ -578,8 +467,8 @@ public class VFSTest {
testDelete(zipVFS);
testInputVFS(zipVFS);
zipVFS.close();
- inputZipVFS = new InputZipVFS(
- new InputZipFile(path, null, Existence.MUST_EXIST, ChangePermission.NOCHANGE));
+ inputZipVFS = new GenericInputVFS(new ReadZipFS(
+ new InputZipFile(path, null, Existence.MUST_EXIST, ChangePermission.NOCHANGE)));
testInputVFS(inputZipVFS);
} finally {
if (zipVFS != null) {