Home | History | Annotate | Download | only in zfile
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      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
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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.
     15  */
     16 
     17 package com.android.tools.build.apkzlib.zfile;
     18 
     19 import java.io.Closeable;
     20 import java.io.File;
     21 import java.io.IOException;
     22 import java.util.function.Function;
     23 import java.util.function.Predicate;
     24 import javax.annotation.Nonnull;
     25 import javax.annotation.Nullable;
     26 
     27 /**
     28  * Creates or updates APKs based on provided entries.
     29  */
     30 public interface ApkCreator extends Closeable {
     31 
     32     /**
     33      * Copies the content of a Jar/Zip archive into the receiver archive.
     34      *
     35      * <p>An optional predicate allows to selectively choose which files to copy over and an
     36      * option function allows renaming the files as they are copied.
     37      *
     38      * @param zip the zip to copy data from
     39      * @param transform an optional transform to apply to file names before copying them
     40      * @param isIgnored an optional filter or {@code null} to mark which out files should not be
     41      * added, even through they are on the zip; if {@code transform} is specified, then this
     42      * predicate applies after transformation
     43      * @throws IOException I/O error
     44      */
     45     void writeZip(
     46             @Nonnull File zip,
     47             @Nullable Function<String, String> transform,
     48             @Nullable Predicate<String> isIgnored)
     49             throws IOException;
     50 
     51     /**
     52      * Writes a new {@link File} into the archive. If a file already existed with the given
     53      * path, it should be replaced.
     54      *
     55      * @param inputFile the {@link File} to write.
     56      * @param apkPath the filepath inside the archive.
     57      * @throws IOException I/O error
     58      */
     59     void writeFile(@Nonnull File inputFile, @Nonnull String apkPath) throws IOException;
     60 
     61     /**
     62      * Deletes a file in a given path.
     63      *
     64      * @param apkPath the path to remove
     65      * @throws IOException failed to remove the entry
     66      */
     67     void deleteFile(@Nonnull String apkPath) throws IOException;
     68 
     69     /** Returns true if the APK will be rewritten on close. */
     70     boolean hasPendingChangesWithWait() throws IOException;
     71 }
     72