Search in sources :

Example 1 with EntryNotFoundException

use of com.android.tools.build.bundletool.io.ZipReader.EntryNotFoundException in project bundletool by google.

the class ZipReader method getUncompressedPayload.

/**
 * Returns an {@link InputStream} of the uncompressed payload of a zip entry.
 */
@MustBeClosed
public InputStream getUncompressedPayload(String entryName) {
    Entry entry = getEntry(entryName).orElseThrow(() -> new EntryNotFoundException(zipMap.getFile(), entryName));
    InputStream entryPayload = getEntryPayload(entry);
    if (!entry.isCompressed()) {
        return entryPayload;
    }
    // nowrap = gzip compatible
    Inflater inflater = new Inflater(/* nowrap= */
    true);
    return new InflaterInputStream(entryPayload, inflater, BUFFER_SIZE_BYTES);
}
Also used : Entry(com.android.zipflinger.Entry) InflaterInputStream(java.util.zip.InflaterInputStream) PayloadInputStream(com.android.zipflinger.PayloadInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) EntryNotFoundException(com.android.tools.build.bundletool.io.ZipReader.EntryNotFoundException) Inflater(java.util.zip.Inflater) MustBeClosed(com.google.errorprone.annotations.MustBeClosed)

Example 2 with EntryNotFoundException

use of com.android.tools.build.bundletool.io.ZipReader.EntryNotFoundException in project bundletool by google.

the class ZipReader method transferTo.

/**
 * Copies the bytes of the payload of a zip entry to the given {@link ZipWriter}.
 *
 * <p>The copy happens using {@link FileChannel#transferTo} which takes advantage of filesystem
 * cache, making it a very I/O efficient way to copy data across files.
 */
public void transferTo(ZipWriter zipWriter, String entryName) {
    Entry entry = getEntry(entryName).orElseThrow(() -> new EntryNotFoundException(zipMap.getFile(), entryName));
    Location payloadLocation = entry.getPayloadLocation();
    try {
        zipWriter.transferFrom(fileChannel, payloadLocation.first, payloadLocation.size());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Entry(com.android.zipflinger.Entry) EntryNotFoundException(com.android.tools.build.bundletool.io.ZipReader.EntryNotFoundException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Location(com.android.zipflinger.Location)

Aggregations

EntryNotFoundException (com.android.tools.build.bundletool.io.ZipReader.EntryNotFoundException)2 Entry (com.android.zipflinger.Entry)2 Location (com.android.zipflinger.Location)1 PayloadInputStream (com.android.zipflinger.PayloadInputStream)1 MustBeClosed (com.google.errorprone.annotations.MustBeClosed)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Inflater (java.util.zip.Inflater)1 InflaterInputStream (java.util.zip.InflaterInputStream)1