Package net.sf.jazzlib

Examples of net.sf.jazzlib.ZipInputStream


   * @param versioning enabled or not
   * @return  True if successfull, false otherwise
   */
  public static boolean unzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, boolean versioning) {

    ZipInputStream oZip = new ZipInputStream(zipLeaf.getInputStream());
   
    try {
      // unzip files
      ZipEntry oEntr = oZip.getNextEntry();
      while (oEntr != null) {
        if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
          if (oEntr.isDirectory()) {
            // skip MacOSX specific metadata directory
            // create directories
            getAllSubdirs(targetDir, oEntr.getName(), true);
          } else {
            // create file
            VFSContainer createIn = targetDir;
            String name = oEntr.getName();
            // check if entry has directories which did not show up as
            // directories above
            int dirSepIndex = name.lastIndexOf('/');
            if (dirSepIndex == -1) {
              // try it windows style, backslash is also valid format
              dirSepIndex = name.lastIndexOf('\\');
            }
            if (dirSepIndex > 0) {
              // create subdirs
              createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), true);
              if (createIn == null) {
                if (log.isDebug()) log.debug("Error creating directory structure for zip entry: "
                    + oEntr.getName());
                return false;
              }
              name = name.substring(dirSepIndex + 1);
            }
           
            if(versioning) {
              VFSLeaf newEntry = (VFSLeaf)createIn.resolve(name);
              if(newEntry == null) {
                newEntry = createIn.createChildLeaf(name);
                OutputStream out = newEntry.getOutputStream(false);
                if (!FileUtils.copy(oZip, out)) return false;
                FileUtils.closeSafely(out);
              } else if (newEntry instanceof Versionable) {
                Versionable versionable = (Versionable)newEntry;
                if(versionable.getVersions().isVersioned()) {
                  versionable.getVersions().addVersion(identity, "", oZip);
                }
              }
            } else {
              VFSLeaf newEntry = createIn.createChildLeaf(name);
              if (newEntry != null) {
                OutputStream out = newEntry.getOutputStream(false);
                if (!FileUtils.copy(oZip, out)) return false;
                FileUtils.closeSafely(out);
              }
            }
          }
        }
        oZip.closeEntry();
        oEntr = oZip.getNextEntry();
      }
    } catch (IOException e) {
      return false;
    } finally {
      FileUtils.closeSafely(oZip);
View Full Code Here


   * @return the list of files which already exist
   */
  public static List<String> checkLockedFileBeforeUnzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, boolean isAdmin) {
    List<String> lockedFiles = new ArrayList<String>();
   
    ZipInputStream oZip = new ZipInputStream(zipLeaf.getInputStream());
   
    try {
      // unzip files
      ZipEntry oEntr = oZip.getNextEntry();
      while (oEntr != null) {
        if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
          if (oEntr.isDirectory()) {
            // skip MacOSX specific metadata directory
            // directories aren't locked
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
            continue;
          } else {
            // search file
            VFSContainer createIn = targetDir;
            String name = oEntr.getName();
            // check if entry has directories which did not show up as
            // directories above
            int dirSepIndex = name.lastIndexOf('/');
            if (dirSepIndex == -1) {
              // try it windows style, backslash is also valid format
              dirSepIndex = name.lastIndexOf('\\');
            }
            if (dirSepIndex > 0) {
              // get subdirs
              createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), false);
              if (createIn == null) {
                //sub directories don't exist, and aren't locked
                oZip.closeEntry();
                oEntr = oZip.getNextEntry();
                continue;
              }
              name = name.substring(dirSepIndex + 1);
            }
           
            VFSLeaf newEntry = (VFSLeaf)createIn.resolve(name);
            if(MetaInfoHelper.isLocked(newEntry, identity, isAdmin)) {
              lockedFiles.add(name);
            }
          }
        }
        oZip.closeEntry();
        oEntr = oZip.getNextEntry();
      }
    } catch (IOException e) {
      return null;
    } finally {
      FileUtils.closeSafely(oZip);
View Full Code Here

  public String readContent(VFSLeaf leaf) throws DocumentException {
    final OpenDocumentHandler dh = new OpenDocumentHandler();

    InputStream stream = null;
    ZipInputStream zip = null;
    try {
      stream = leaf.getInputStream();
      zip = new ZipInputStream(stream);
      ZipEntry entry = zip.getNextEntry();
      while (entry != null) {
        if (entry.getName().endsWith("content.xml")) {
          parse(new ShieldInputStream(zip), dh);
          break;//we parsed only content
        }
        entry = zip.getNextEntry();
      }
    } catch (DocumentException e) {
      throw e;
    } catch (Exception e) {
      log.error("", e);
View Full Code Here

   * @param encoding the encoding to use for the html files within the epub
   * @return the Book as read from the inputstream
   * @throws IOException
   */
  public Book readEpub(InputStream in, String encoding) throws IOException {
    return readEpub(new ZipInputStream(in), encoding);
 
View Full Code Here

    return lazilyLoadedMediaTypes.contains(mediaType);
  }


  public static Resources loadResources(InputStream in, String defaultHtmlEncoding) throws IOException {
    return loadResources(new ZipInputStream(in), defaultHtmlEncoding);
  }
View Full Code Here

   * @throws IOException
   */
  @Test
  public void testLoadResources_ZipInputStream() throws FileNotFoundException, IOException {
    // given
    ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(new File(testBookFilename)));
   
    // when
    Resources resources = ResourcesLoader.loadResources(zipInputStream, encoding);
   
    // then
View Full Code Here

TOP

Related Classes of net.sf.jazzlib.ZipInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.