Пример #1
0
 /**
  * @param entry instance of ZipEntry
  * @return
  */
 public InputStream getXMLChunkStream(ZipEntry entry) {
   try {
     if (pptxFilesStreams != null) {
       if (entry != null && entry.getName() != null && entry.getName().trim().length() > 0) {
         return (InputStream) pptxFilesStreams.get(entry.getName());
       }
     }
   } catch (Exception ex) {
     DEBUG.errorPrint(
         "PPTX - Could not get zip entry: " + entry.getName() + " Reason: " + ex.getMessage());
     return null;
   }
   return null;
 }
Пример #2
0
  /**
   * @param fileStream of pptx file
   * @return true if pptx file is unzipped, otherwise false
   */
  public boolean unzipFileAndStoreStreams(InputStream fileStream) {
    ZipEntry currentEntry = null;
    this.pptxFilesStreams.clear();

    this.pptxZipStreamFile = new ZipInputStream(fileStream);

    try {
      while (true) {
        currentEntry = this.pptxZipStreamFile.getNextEntry();
        if (currentEntry != null) {
          String name = currentEntry.getName();
          this.PPTXEntries.put(name, currentEntry);

          long bufferSize = currentEntry.getSize();
          Long bufferSizeLong = new Long(bufferSize);
          int bufferSizeIntValue = bufferSizeLong.intValue();
          bufferSizeLong = null;

          byte[] buffer = new byte[bufferSizeIntValue];
          byte[] readBuffer = new byte[bufferSizeIntValue];

          int bytesRead = 0;
          while (bytesRead < bufferSizeIntValue) {
            int currBytesRead = this.pptxZipStreamFile.read(readBuffer, 0, bufferSizeIntValue);
            for (int index = 0; index < currBytesRead; index++) {
              buffer[bytesRead] = readBuffer[index];
              bytesRead++;
            }
          }

          ByteArrayInputStream fileBytesStream = new ByteArrayInputStream(buffer);
          this.pptxFilesStreams.put(name, fileBytesStream);
        } else {
          break;
        }
      }

    } catch (Exception ex) {
      DEBUG.errorPrint("PPTX - Could not unzip pptx source file - " + ex.getMessage());
      return false;
    }
    return true;
  }