summaryrefslogtreecommitdiff
path: root/java/com/google/devtools/build/android/desugar/io/InputFileProvider.java
diff options
context:
space:
mode:
authorIvan Gavrilovic <gavra@google.com>2018-05-04 11:07:54 +0100
committerIvan Gavrilovic <gavra@google.com>2018-05-04 11:10:50 +0100
commit9d2aa110047c892318c506d8ca5db6e7e14f9189 (patch)
tree74deac1e16e97c2c13f226cd4635cd65abf19303 /java/com/google/devtools/build/android/desugar/io/InputFileProvider.java
parent9e1602fcb030f33d2d263acd783a9e24fccb3e7d (diff)
parentbc0139bb823083b8322a3a58d3fa8eb390c154de (diff)
downloaddesugar-android-p-preview-4.tar.gz
* origin/upstream-master: (43 commits) Allow --worker_max_instances to take MnemonicName=value to specify max for each named worker. Clean up code that directly imports nested classes like Builder, Entry, etc. Clean up code that directly imports nested classes like Builder, Entry, etc. Clean up code that directly imports nested classes like Builder, Entry, etc. Remove use of bare Immutable{List,Map,Set} Builder classes. Relax the assertion in Desugar for checking the calls to $closeResource(...). It is possible that $closeResource(...) is not used as the calls to it might be eliminated by some optimization tools, such as Proguard. Make attempting to change --config in invocation policy an error. Remove alphabetical sorting of options in the canonical list. Remove some deprecated resources flags. Remove category checking from incompatible changes. Support source versions newer than 8 in Bazel's annotation processors stub simple core library bridge methods that only differ in return type RELNOTES: None. Reflect core library moves in super calls, even in default method stubs. Always generate default method stubs for emulated methods. RELNOTES: None. Make KeepScanner tool search classpath for nearest definition of each member reference, instead of potentially referring to a subtype. Refactor desugar's class loading machinery and related code into a separate package for easier reuse in this tool. RELNOTES: None. Minor fixes to KeepScanner tool: - use Guava to read zip entries - Fix keep rules emitted for constructors RELNOTES: None. Support custom implementations of emulated core interface methods RELNOTES: None. tests,windows: enable android.desugar.runtime emulate dynamic dispatch of emulated default interface methods RELNOTES: None. Android desugar config options to exclude methods from interface emulation RELNOTES: None. send invocations to emulated interfaces through dispatch helper. fix logic for implementing emulated interfaces. RELNOTES: None. ... BUG: none Test: existing
Diffstat (limited to 'java/com/google/devtools/build/android/desugar/io/InputFileProvider.java')
-rw-r--r--java/com/google/devtools/build/android/desugar/io/InputFileProvider.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/java/com/google/devtools/build/android/desugar/io/InputFileProvider.java b/java/com/google/devtools/build/android/desugar/io/InputFileProvider.java
new file mode 100644
index 0000000..c41d018
--- /dev/null
+++ b/java/com/google/devtools/build/android/desugar/io/InputFileProvider.java
@@ -0,0 +1,49 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// 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.google.devtools.build.android.desugar.io;
+
+import com.google.errorprone.annotations.MustBeClosed;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.zip.ZipEntry;
+
+/** Input file provider allows to iterate on relative path filename of a directory or a jar file. */
+public interface InputFileProvider extends Closeable, Iterable<String> {
+
+ /**
+ * Return a ZipEntry for {@code filename}. If the provider is a {@link ZipInputFileProvider}, the
+ * method returns the existing ZipEntry in order to keep its metadata, otherwise a new one is
+ * created.
+ */
+ ZipEntry getZipEntry(String filename);
+
+ /**
+ * This method returns an input stream allowing to read the file {@code filename}, it is the
+ * responsibility of the caller to close this stream.
+ */
+ InputStream getInputStream(String filename) throws IOException;
+
+ /** Transform a Path to an InputFileProvider that needs to be closed by the caller. */
+ @MustBeClosed
+ public static InputFileProvider open(Path path) throws IOException {
+ if (Files.isDirectory(path)) {
+ return new DirectoryInputFileProvider(path);
+ } else {
+ return new ZipInputFileProvider(path);
+ }
+ }
+}