Beispiel #1
0
 /**
  * Returns a new RandomAccessInputStream around the raw handle underlying the provided stream,
  * instead of using a zip handle.
  *
  * <p>NB: closes the provided stream.
  */
 public static RandomAccessInputStream getRawStream(
     final LocationService locationService, final RandomAccessInputStream stream)
     throws IOException {
   // NB: We need a raw handle on the ZIP data itself, not a ZipHandle.
   final String id = stream.getFileName();
   final IRandomAccess rawHandle = locationService.getHandle(id, false, false);
   return new RandomAccessInputStream(locationService.getContext(), rawHandle, id);
 }
Beispiel #2
0
    /**
     * Extracts the String id of the provided stream.
     *
     * @param locationService - The location service to use for mapping files
     * @param stream - Stream, built around a .zip file, to extract the actual id from
     * @param mappedFiles - Optional param. If provided, all discovered entries in the underlying
     *     archive will be added to this list.
     * @return An id of the base entry in the .zip
     * @throws IOException
     */
    public static String unzipId(
        final LocationService locationService,
        final RandomAccessInputStream stream,
        final List<String> mappedFiles)
        throws IOException {
      final ZipInputStream zip = new ZipInputStream(stream);
      ZipEntry ze = null;

      while (true) {
        ze = zip.getNextEntry();
        if (ze == null) break;
        final ZipHandle handle =
            new ZipHandle(locationService.getContext(), stream.getFileName(), ze);
        locationService.mapFile(ze.getName(), handle);
        if (mappedFiles != null) mappedFiles.add(ze.getName());
      }

      final ZipHandle base = new ZipHandle(locationService.getContext(), stream.getFileName());
      final String id = base.getEntryName();
      base.close();

      return id;
    }