예제 #1
0
 /**
  * Searches for an entry inside the zip stream by entry path. If there are alternative extensions,
  * will also look for entry with alternative extension. The search stops reading the stream when
  * the entry is found, so calling read on the stream will read the returned entry.
  *
  * <p>The zip input stream doesn't support mark/reset so once this method is used you cannot go
  * back - either the stream was fully read (when entry is not found) or the stream was read until
  * the current entry.
  *
  * @param zis The zip input stream
  * @param entryPath The entry path to search for
  * @param alternativeExtensions List of alternative file extensions to try if the main entry path
  *     is not found.
  * @return The entry if found, null otherwise
  * @throws IOException On failure to read the stream
  */
 public static ZipEntry locateEntry(
     ZipInputStream zis, String entryPath, List<String> alternativeExtensions) throws IOException {
   ZipEntry zipEntry;
   while ((zipEntry = zis.getNextEntry()) != null) {
     String zipEntryName = zipEntry.getName();
     if (zipEntryName.equals(entryPath)) {
       return zipEntry;
     } else if (alternativeExtensions != null) {
       String basePath = PathUtils.stripExtension(entryPath);
       for (String alternativeExtension : alternativeExtensions) {
         String alternativeSourcePath = basePath + "." + alternativeExtension;
         if (zipEntryName.equals(alternativeSourcePath)) {
           return zipEntry;
         }
       }
     }
   }
   return null;
 }