diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2015-03-10 16:46:58 +0100 |
---|---|---|
committer | Benoit Lamarche <benoitlamarche@google.com> | 2015-03-12 14:07:47 +0000 |
commit | 2e7f0de7da41e477988387e0237a4096c5dbafc8 (patch) | |
tree | 94871bbe3b01e931a816c47a74fd3079f708d5c6 /sched/src | |
parent | c7b067b53314bde7336fdd254ba2275c6a0f7ba7 (diff) | |
download | toolchain_jack-2e7f0de7da41e477988387e0237a4096c5dbafc8.tar.gz toolchain_jack-2e7f0de7da41e477988387e0237a4096c5dbafc8.tar.bz2 toolchain_jack-2e7f0de7da41e477988387e0237a4096c5dbafc8.zip |
Use working directory in codecs
Change-Id: I073647682c78bd87e93168e6e7839dfa783bec42
Diffstat (limited to 'sched/src')
22 files changed, 258 insertions, 47 deletions
diff --git a/sched/src/com/android/sched/util/codec/DirectDirInputOutputVFSCodec.java b/sched/src/com/android/sched/util/codec/DirectDirInputOutputVFSCodec.java index 0e79e2fd..4c2ee8e4 100644 --- a/sched/src/com/android/sched/util/codec/DirectDirInputOutputVFSCodec.java +++ b/sched/src/com/android/sched/util/codec/DirectDirInputOutputVFSCodec.java @@ -48,9 +48,15 @@ public class DirectDirInputOutputVFSCodec extends InputOutputVFSCodec @Nonnull public InputOutputVFS checkString(@Nonnull CodecContext context, @Nonnull final String string) throws ParsingException { + try { - return new GenericInputOutputVFS(new CachedDirectFS(new Directory(string, - context.getRunnableHooks(), existence, permissions, change), permissions)); + return new GenericInputOutputVFS( + new CachedDirectFS(new Directory(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + existence, + permissions, + change), permissions)); } catch (IOException e) { throw new ParsingException(e); } diff --git a/sched/src/com/android/sched/util/codec/DirectDirOutputVFSCodec.java b/sched/src/com/android/sched/util/codec/DirectDirOutputVFSCodec.java index 5ddffe0b..e0ca984f 100644 --- a/sched/src/com/android/sched/util/codec/DirectDirOutputVFSCodec.java +++ b/sched/src/com/android/sched/util/codec/DirectDirOutputVFSCodec.java @@ -46,9 +46,12 @@ public class DirectDirOutputVFSCodec extends OutputVFSCodec { public OutputVFS checkString(@Nonnull CodecContext context, @Nonnull final String string) throws ParsingException { try { - return new GenericOutputVFS(new DirectFS( - new Directory(string, context.getRunnableHooks(), existence, permissions, change), - permissions)); + return new GenericOutputVFS(new DirectFS(new Directory(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + existence, + permissions, + change), permissions)); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); } diff --git a/sched/src/com/android/sched/util/codec/DirectFSCodec.java b/sched/src/com/android/sched/util/codec/DirectFSCodec.java index 7b6ab631..d53ed9f3 100644 --- a/sched/src/com/android/sched/util/codec/DirectFSCodec.java +++ b/sched/src/com/android/sched/util/codec/DirectFSCodec.java @@ -90,7 +90,7 @@ public class DirectFSCodec extends FileOrDirCodec<VFS> { public VFS checkString(@Nonnull CodecContext context, @Nonnull final String string) throws ParsingException { try { - return new CachedDirectFS(new Directory(string, + return new CachedDirectFS(new Directory(context.getWorkingDirectory(), string, context.getRunnableHooks(), existence, permissions, change), permissions); } catch (IOException e) { throw new ParsingException(e); diff --git a/sched/src/com/android/sched/util/codec/DirectoryCodec.java b/sched/src/com/android/sched/util/codec/DirectoryCodec.java index da7505eb..945b78ec 100644 --- a/sched/src/com/android/sched/util/codec/DirectoryCodec.java +++ b/sched/src/com/android/sched/util/codec/DirectoryCodec.java @@ -63,7 +63,12 @@ public class DirectoryCodec extends FileOrDirCodec<Directory> { public Directory checkString(@Nonnull CodecContext context, @Nonnull String string) throws ParsingException { try { - return new Directory(string, context.getRunnableHooks(), existence, permissions, change); + return new Directory(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + existence, + permissions, + change); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); } diff --git a/sched/src/com/android/sched/util/codec/DirectoryInputVFSCodec.java b/sched/src/com/android/sched/util/codec/DirectoryInputVFSCodec.java index e2904485..e5674712 100644 --- a/sched/src/com/android/sched/util/codec/DirectoryInputVFSCodec.java +++ b/sched/src/com/android/sched/util/codec/DirectoryInputVFSCodec.java @@ -52,8 +52,12 @@ public class DirectoryInputVFSCodec extends InputVFSCodec public InputVFS checkString(@Nonnull CodecContext context, @Nonnull final String string) throws ParsingException { try { - VFS vfs = new DirectFS(new Directory(string, context.getRunnableHooks(), - Existence.MUST_EXIST, Permission.READ, change), Permission.READ); + VFS vfs = new DirectFS(new Directory(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + Existence.MUST_EXIST, + Permission.READ, + change), Permission.READ); return new GenericInputVFS(vfs); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); diff --git a/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java b/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java index b735e50a..a81ff9cf 100644 --- a/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java +++ b/sched/src/com/android/sched/util/codec/InputFileOrDirectoryCodec.java @@ -55,9 +55,14 @@ public class InputFileOrDirectoryCodec extends FileOrDirCodec<FileOrDirectory> { File file = new File(string); try { if (file.isFile()) { - return new InputStreamFile(string); + return new InputStreamFile(context.getWorkingDirectory(), string); } else { - return new Directory(string, context.getRunnableHooks(), existence, permissions, change); + return new Directory(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + existence, + permissions, + change); } } catch (IOException e) { throw new ParsingException(e.getMessage(), e); diff --git a/sched/src/com/android/sched/util/codec/InputStreamCodec.java b/sched/src/com/android/sched/util/codec/InputStreamCodec.java index d0159d20..7b7db5dd 100644 --- a/sched/src/com/android/sched/util/codec/InputStreamCodec.java +++ b/sched/src/com/android/sched/util/codec/InputStreamCodec.java @@ -85,7 +85,7 @@ public class InputStreamCodec extends StreamCodec<InputStreamFile> { return new InputStreamFile(context.getStandardInput(), STANDARD_INPUT_LOCATION); } else { try { - return new InputStreamFile(string); + return new InputStreamFile(context.getWorkingDirectory(), string); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); } diff --git a/sched/src/com/android/sched/util/codec/InputStreamOrDirectoryCodec.java b/sched/src/com/android/sched/util/codec/InputStreamOrDirectoryCodec.java index da77bb24..57994c3a 100644 --- a/sched/src/com/android/sched/util/codec/InputStreamOrDirectoryCodec.java +++ b/sched/src/com/android/sched/util/codec/InputStreamOrDirectoryCodec.java @@ -24,7 +24,7 @@ import javax.annotation.Nonnull; /** * This {@link StringCodec} is used to create an instance of {@link FileOrDirectory}. - * The file or directory must exists and be readable. + * The file or directory must exist and be readable. */ public class InputStreamOrDirectoryCodec extends OrCodec<FileOrDirectory> { @SuppressWarnings("unchecked") diff --git a/sched/src/com/android/sched/util/codec/InputVFSCodec.java b/sched/src/com/android/sched/util/codec/InputVFSCodec.java index 4cb6fc1c..c2b48ada 100644 --- a/sched/src/com/android/sched/util/codec/InputVFSCodec.java +++ b/sched/src/com/android/sched/util/codec/InputVFSCodec.java @@ -79,12 +79,17 @@ public class InputVFSCodec extends FileOrDirCodec<InputVFS> { try { File dirOrZip = new File(string); if (dirOrZip.isDirectory()) { - vfs = new DirectFS(new Directory(string, context.getRunnableHooks(), - Existence.MUST_EXIST, Permission.READ, change), Permission.READ); + vfs = new DirectFS(new Directory(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + Existence.MUST_EXIST, + Permission.READ, + change), Permission.READ); } else { RunnableHooks hooks = context.getRunnableHooks(); assert hooks != null; - vfs = new ReadZipFS(new InputZipFile(string, hooks, Existence.MUST_EXIST, change)); + vfs = new ReadZipFS(new InputZipFile(context.getWorkingDirectory(), string, hooks, + Existence.MUST_EXIST, change)); } return new GenericInputVFS(vfs); diff --git a/sched/src/com/android/sched/util/codec/OutputStreamCodec.java b/sched/src/com/android/sched/util/codec/OutputStreamCodec.java index 3a8a4a2b..7f73ee02 100644 --- a/sched/src/com/android/sched/util/codec/OutputStreamCodec.java +++ b/sched/src/com/android/sched/util/codec/OutputStreamCodec.java @@ -140,7 +140,12 @@ public class OutputStreamCodec extends StreamCodec<OutputStreamFile> { StandardOutputKind.STANDARD_ERROR.getLocation()); } else { try { - return new OutputStreamFile(string, context.getRunnableHooks(), existence, change, append); + return new OutputStreamFile(context.getWorkingDirectory(), + string, + context.getRunnableHooks(), + existence, + change, + append); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); } diff --git a/sched/src/com/android/sched/util/codec/PathCodec.java b/sched/src/com/android/sched/util/codec/PathCodec.java index c221fb70..196d9774 100644 --- a/sched/src/com/android/sched/util/codec/PathCodec.java +++ b/sched/src/com/android/sched/util/codec/PathCodec.java @@ -17,6 +17,8 @@ package com.android.sched.util.codec; +import com.android.sched.util.file.FileOrDirectory; + import java.io.File; import java.util.Collections; import java.util.List; @@ -53,7 +55,7 @@ public class PathCodec implements StringCodec<File> { @Override @Nonnull public File parseString(@Nonnull CodecContext context, @Nonnull String value) { - return new File(value); + return FileOrDirectory.getFileFromWorkingDirectory(context.getWorkingDirectory(), value); } @Override diff --git a/sched/src/com/android/sched/util/codec/ZipFSCodec.java b/sched/src/com/android/sched/util/codec/ZipFSCodec.java index 4aedfc33..42a1db92 100644 --- a/sched/src/com/android/sched/util/codec/ZipFSCodec.java +++ b/sched/src/com/android/sched/util/codec/ZipFSCodec.java @@ -86,7 +86,8 @@ public class ZipFSCodec extends FileOrDirCodec<VFS> { @Nonnull final String string) throws ParsingException { RunnableHooks hooks = context.getRunnableHooks(); try { - return new ReadWriteZipFS(new OutputZipFile(string, hooks, existence, change)); + return new ReadWriteZipFS( + new OutputZipFile(context.getWorkingDirectory(), string, hooks, existence, change)); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); } diff --git a/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java b/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java index d0f4d338..6d360949 100644 --- a/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java +++ b/sched/src/com/android/sched/util/codec/ZipInputOutputVFSCodec.java @@ -56,8 +56,8 @@ public class ZipInputOutputVFSCodec extends InputOutputVFSCodec @Nonnull final String string) throws ParsingException { RunnableHooks hooks = context.getRunnableHooks(); try { - final ReadWriteZipFS vfs = - new ReadWriteZipFS(new OutputZipFile(string, hooks, existence, change)); + final ReadWriteZipFS vfs = new ReadWriteZipFS( + new OutputZipFile(context.getWorkingDirectory(), 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/util/codec/ZipOutputVFSCodec.java b/sched/src/com/android/sched/util/codec/ZipOutputVFSCodec.java index 162917ea..b96a40eb 100644 --- a/sched/src/com/android/sched/util/codec/ZipOutputVFSCodec.java +++ b/sched/src/com/android/sched/util/codec/ZipOutputVFSCodec.java @@ -54,8 +54,8 @@ public class ZipOutputVFSCodec extends OutputVFSCodec { @Nonnull final String string) throws ParsingException { RunnableHooks hooks = context.getRunnableHooks(); try { - WriteZipFS vfs = - new WriteZipFS(new OutputZipFile(string, hooks, existence, change)); + WriteZipFS vfs = new WriteZipFS( + new OutputZipFile(context.getWorkingDirectory(), string, hooks, existence, change)); return new GenericOutputVFS(vfs); } catch (IOException e) { throw new ParsingException(e.getMessage(), e); diff --git a/sched/src/com/android/sched/util/file/AbstractStreamFile.java b/sched/src/com/android/sched/util/file/AbstractStreamFile.java index 55d257a4..f70df7d9 100644 --- a/sched/src/com/android/sched/util/file/AbstractStreamFile.java +++ b/sched/src/com/android/sched/util/file/AbstractStreamFile.java @@ -40,10 +40,15 @@ public abstract class AbstractStreamFile extends FileOrDirectory { protected AbstractStreamFile(@Nonnull String name, @CheckForNull RunnableHooks hooks) { + this(new File(name), new FileLocation(name), hooks); + } + + protected AbstractStreamFile(@Nonnull File file, @Nonnull FileLocation location, + @CheckForNull RunnableHooks hooks) { super(hooks); - this.file = new File(name); - this.location = new FileLocation(file); + this.file = file; + this.location = location; } protected AbstractStreamFile(@Nonnull Location location) { @@ -139,4 +144,4 @@ public abstract class AbstractStreamFile extends FileOrDirectory { assert file != null; return file.getPath(); } -}
\ No newline at end of file +} diff --git a/sched/src/com/android/sched/util/file/Directory.java b/sched/src/com/android/sched/util/file/Directory.java index 0ea2f601..0af9fe94 100644 --- a/sched/src/com/android/sched/util/file/Directory.java +++ b/sched/src/com/android/sched/util/file/Directory.java @@ -45,10 +45,46 @@ public class Directory extends FileOrDirectory { NotDirectoryException, FileAlreadyExistsException, CannotCreateFileException { + + this(new File(name), new DirectoryLocation(name), hooks, existence, permissions, change); + } + + public Directory(@CheckForNull Directory workingDirectory, + @Nonnull String string, + @CheckForNull RunnableHooks runnableHooks, + @Nonnull Existence existence, + int permissions, + @Nonnull ChangePermission change) + throws NotDirectoryException, + WrongPermissionException, + CannotSetPermissionException, + NoSuchFileException, + FileAlreadyExistsException, + CannotCreateFileException { + this(getFileFromWorkingDirectory(workingDirectory, string), + new DirectoryLocation(string), + runnableHooks, + existence, + permissions, + change); + } + + private Directory(@Nonnull File file, + @Nonnull DirectoryLocation location, + @CheckForNull RunnableHooks hooks, + @Nonnull Existence existence, + int permissions, + @Nonnull ChangePermission change) + throws WrongPermissionException, + CannotSetPermissionException, + NoSuchFileException, + NotDirectoryException, + FileAlreadyExistsException, + CannotCreateFileException { super(hooks); - this.file = new File(name); - this.location = new DirectoryLocation(name); + this.file = file; + this.location = location; if (existence == Existence.MAY_EXIST) { if (file.exists()) { @@ -60,7 +96,7 @@ public class Directory extends FileOrDirectory { switch (existence) { case MUST_EXIST: - Directory.check(file, (DirectoryLocation) location); + Directory.check(file, location); FileOrDirectory.checkPermissions(file, location, permissions); break; case NOT_EXIST: @@ -127,4 +163,4 @@ public class Directory extends FileOrDirectory { public String getPath() { return file.getPath(); } -}
\ No newline at end of file +} diff --git a/sched/src/com/android/sched/util/file/FileOrDirectory.java b/sched/src/com/android/sched/util/file/FileOrDirectory.java index c7d7dcae..688e5d22 100644 --- a/sched/src/com/android/sched/util/file/FileOrDirectory.java +++ b/sched/src/com/android/sched/util/file/FileOrDirectory.java @@ -216,4 +216,15 @@ public abstract class FileOrDirectory implements HasLocation { hooks = null; } } + + @Nonnull + public static File getFileFromWorkingDirectory(@CheckForNull Directory workingDirectory, + @Nonnull String path) { + File fileWithoutWorkingDir = new File(path); + if (workingDirectory != null && !fileWithoutWorkingDir.isAbsolute()) { + return new File(workingDirectory.getFile(), path); + } else { + return fileWithoutWorkingDir; + } + } }
\ No newline at end of file diff --git a/sched/src/com/android/sched/util/file/InputStreamFile.java b/sched/src/com/android/sched/util/file/InputStreamFile.java index a693e56a..179da191 100644 --- a/sched/src/com/android/sched/util/file/InputStreamFile.java +++ b/sched/src/com/android/sched/util/file/InputStreamFile.java @@ -17,10 +17,12 @@ package com.android.sched.util.file; import com.android.sched.util.ConcurrentIOException; +import com.android.sched.util.location.FileLocation; import com.android.sched.util.location.Location; import com.android.sched.util.location.StandardInputLocation; import com.android.sched.util.stream.UncloseableInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; @@ -37,17 +39,7 @@ public class InputStreamFile extends AbstractStreamFile { public InputStreamFile(@Nonnull String name) throws WrongPermissionException, NotFileException, NoSuchFileException { - super(name, null /* hooks */); - - try { - performChecks(Existence.MUST_EXIST, Permission.READ, ChangePermission.NOCHANGE); - } catch (FileAlreadyExistsException e) { - throw new AssertionError(e); - } catch (CannotCreateFileException e) { - throw new AssertionError(e); - } catch (CannotSetPermissionException e) { - throw new AssertionError(e); - } + this(new File(name), new FileLocation(name)); } public InputStreamFile() { @@ -60,6 +52,26 @@ public class InputStreamFile extends AbstractStreamFile { this.in = in; } + public InputStreamFile(@CheckForNull Directory workingDirectory, @Nonnull String string) + throws NotFileException, WrongPermissionException, NoSuchFileException { + this(getFileFromWorkingDirectory(workingDirectory, string), new FileLocation(string)); + } + + private InputStreamFile(@Nonnull File file, @Nonnull FileLocation location) + throws WrongPermissionException, NotFileException, NoSuchFileException { + super(file, location, null /* hooks */); + + try { + performChecks(Existence.MUST_EXIST, Permission.READ, ChangePermission.NOCHANGE); + } catch (FileAlreadyExistsException e) { + throw new AssertionError(e); + } catch (CannotCreateFileException e) { + throw new AssertionError(e); + } catch (CannotSetPermissionException e) { + throw new AssertionError(e); + } + } + @Nonnull public InputStream getInputStream() { if (in != null) { diff --git a/sched/src/com/android/sched/util/file/InputZipFile.java b/sched/src/com/android/sched/util/file/InputZipFile.java index 670d7126..e8f1cc5a 100644 --- a/sched/src/com/android/sched/util/file/InputZipFile.java +++ b/sched/src/com/android/sched/util/file/InputZipFile.java @@ -18,6 +18,7 @@ package com.android.sched.util.file; import com.android.sched.util.ConcurrentIOException; import com.android.sched.util.RunnableHooks; +import com.android.sched.util.location.FileLocation; import java.io.File; import java.io.IOException; @@ -35,7 +36,7 @@ public class InputZipFile extends StreamFile { @Nonnull ZipFile zipFile; - public InputZipFile(@Nonnull String name, @CheckForNull RunnableHooks hooks, + public InputZipFile(@Nonnull String path, @CheckForNull RunnableHooks hooks, @Nonnull Existence existence, @Nonnull ChangePermission change) throws FileAlreadyExistsException, CannotCreateFileException, @@ -44,7 +45,34 @@ public class InputZipFile extends StreamFile { NoSuchFileException, NotFileException, ZipException { - super(name, hooks, existence, Permission.READ, change); + this(new File(path), new FileLocation(path), hooks, existence, change); + } + + public InputZipFile(@CheckForNull Directory workingDirectory, String path, + @CheckForNull RunnableHooks hooks, @Nonnull Existence mustExist, + @Nonnull ChangePermission change) + throws NotFileException, + FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + ZipException { + this(getFileFromWorkingDirectory(workingDirectory, path), + new FileLocation(path), hooks, mustExist, change); + } + + private InputZipFile(@Nonnull File file, @Nonnull FileLocation location, + @CheckForNull RunnableHooks hooks, @Nonnull Existence existence, + @Nonnull ChangePermission change) + throws FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + NotFileException, + ZipException { + super(file, location, hooks, existence, Permission.READ, change); zipFile = processZip(file); } diff --git a/sched/src/com/android/sched/util/file/OutputStreamFile.java b/sched/src/com/android/sched/util/file/OutputStreamFile.java index 6956ba13..17644e0a 100644 --- a/sched/src/com/android/sched/util/file/OutputStreamFile.java +++ b/sched/src/com/android/sched/util/file/OutputStreamFile.java @@ -18,12 +18,14 @@ package com.android.sched.util.file; import com.android.sched.util.ConcurrentIOException; import com.android.sched.util.RunnableHooks; +import com.android.sched.util.location.FileLocation; import com.android.sched.util.location.Location; import com.android.sched.util.location.StandardErrorLocation; import com.android.sched.util.location.StandardOutputLocation; import com.android.sched.util.stream.UncloseableOutputStream; import com.android.sched.util.stream.UncloseablePrintStream; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; @@ -52,7 +54,42 @@ public class OutputStreamFile extends AbstractStreamFile { WrongPermissionException, NoSuchFileException, NotFileException { - super(name, hooks); + this(new File(name), new FileLocation(name), hooks, existence, change, append); + } + + public OutputStreamFile(@CheckForNull Directory workingDirectory, + @Nonnull String name, + @CheckForNull RunnableHooks hooks, + @Nonnull Existence existence, + @Nonnull ChangePermission change, + boolean append) + throws FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + NotFileException { + this(getFileFromWorkingDirectory(workingDirectory, name), + new FileLocation(name), + hooks, + existence, + change, + append); + } + + protected OutputStreamFile(@Nonnull File file, + @Nonnull FileLocation location, + @CheckForNull RunnableHooks hooks, + @Nonnull Existence existence, + @Nonnull ChangePermission change, + boolean append) + throws FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + NotFileException { + super(file, location, hooks); performChecks(existence, Permission.WRITE, change); diff --git a/sched/src/com/android/sched/util/file/OutputZipFile.java b/sched/src/com/android/sched/util/file/OutputZipFile.java index 3237ae13..5a867f7d 100644 --- a/sched/src/com/android/sched/util/file/OutputZipFile.java +++ b/sched/src/com/android/sched/util/file/OutputZipFile.java @@ -18,7 +18,9 @@ package com.android.sched.util.file; import com.android.sched.util.ConcurrentIOException; import com.android.sched.util.RunnableHooks; +import com.android.sched.util.location.FileLocation; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -46,7 +48,36 @@ public class OutputZipFile extends OutputStreamFile { WrongPermissionException, NoSuchFileException, NotFileException { - super(name, hooks, existence, change, false); + this(new File(name), new FileLocation(name), hooks, existence, change); + } + + public OutputZipFile(@CheckForNull Directory workingDirectory, + @Nonnull String name, + @CheckForNull RunnableHooks hooks, + @Nonnull Existence existence, + @Nonnull ChangePermission change) + throws FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + NotFileException { + this(getFileFromWorkingDirectory(workingDirectory, name), + new FileLocation(name), hooks, existence, change); + } + + private OutputZipFile(@Nonnull File file, + @Nonnull FileLocation location, + @CheckForNull RunnableHooks hooks, + @Nonnull Existence existence, + @Nonnull ChangePermission change) + throws FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + NotFileException { + super(file, location, hooks, existence, change, false); } @Override diff --git a/sched/src/com/android/sched/util/file/StreamFile.java b/sched/src/com/android/sched/util/file/StreamFile.java index 3903dce5..527f31e9 100644 --- a/sched/src/com/android/sched/util/file/StreamFile.java +++ b/sched/src/com/android/sched/util/file/StreamFile.java @@ -17,6 +17,9 @@ package com.android.sched.util.file; import com.android.sched.util.RunnableHooks; +import com.android.sched.util.location.FileLocation; + +import java.io.File; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -27,7 +30,19 @@ import javax.annotation.Nonnull; */ public class StreamFile extends AbstractStreamFile { - public StreamFile(@Nonnull String name, + public StreamFile(@Nonnull String name, @CheckForNull RunnableHooks hooks, + @Nonnull Existence existence, int permissions, @Nonnull ChangePermission change) + throws FileAlreadyExistsException, + CannotCreateFileException, + CannotSetPermissionException, + WrongPermissionException, + NoSuchFileException, + NotFileException { + this(new File(name), new FileLocation(name), hooks, existence, permissions, change); + } + + protected StreamFile(@Nonnull File file, + @Nonnull FileLocation location, @CheckForNull RunnableHooks hooks, @Nonnull Existence existence, int permissions, @@ -38,7 +53,7 @@ public class StreamFile extends AbstractStreamFile { WrongPermissionException, NoSuchFileException, NotFileException { - super(name, hooks); + super(file, location, hooks); performChecks(existence, permissions, change); } |