Package org.apache.commons.compress.archivers.zip

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveEntry


        OutputStream os = response.getOutputStream();
        ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);

        // add the Python script
        ZipArchiveEntry pyEntry = new ZipArchiveEntry("pt.py");
        pyEntry.setSize(pyBytes.length);
        pyEntry.setUnixMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setTime(lastModified);
        zos.putArchiveEntry(pyEntry);
        zos.write(pyBytes);
        zos.closeArchiveEntry();

        // add a Python launch cmd file
        byte [] cmdBytes = readAll(getClass().getResourceAsStream("/pt.cmd"));
        ZipArchiveEntry cmdEntry = new ZipArchiveEntry("pt.cmd");
        cmdEntry.setSize(cmdBytes.length);
        cmdEntry.setUnixMode(FileMode.REGULAR_FILE.getBits());
        cmdEntry.setTime(lastModified);
        zos.putArchiveEntry(cmdEntry);
        zos.write(cmdBytes);
        zos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        ZipArchiveEntry txtEntry = new ZipArchiveEntry("readme.txt");
        txtEntry.setSize(txtBytes.length);
        txtEntry.setUnixMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setTime(lastModified);
        zos.putArchiveEntry(txtEntry);
        zos.write(txtBytes);
        zos.closeArchiveEntry();

        // cleanup
        zos.finish();
        zos.close();
        os.flush();
      } else {
        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
        TarArchiveEntry pyEntry = new TarArchiveEntry("pt");
        pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setModTime(lastModified);
        pyEntry.setSize(pyBytes.length);
        tos.putArchiveEntry(pyEntry);
        tos.write(pyBytes);
        tos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        TarArchiveEntry txtEntry = new TarArchiveEntry("README");
        txtEntry.setMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setModTime(lastModified);
        txtEntry.setSize(txtBytes.length);
        tos.putArchiveEntry(txtEntry);
        tos.write(txtBytes);
        tos.closeArchiveEntry();

        // cleanup
View Full Code Here


        if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
          continue;
        }
        tw.getObjectId(id, 0);

        ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
        entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
        entry.setComment(commit.getName());
        entry.setUnixMode(mode.getBits());
        entry.setTime(modified);
        zos.putArchiveEntry(entry);

        ObjectLoader ldr = repository.open(id);
        ldr.copyTo(zos);
        zos.closeArchiveEntry();
View Full Code Here

        OutputStream os = response.getOutputStream();
        ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);

        // add the Python script
        ZipArchiveEntry pyEntry = new ZipArchiveEntry("pt.py");
        pyEntry.setSize(pyBytes.length);
        pyEntry.setUnixMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setTime(lastModified);
        zos.putArchiveEntry(pyEntry);
        zos.write(pyBytes);
        zos.closeArchiveEntry();

        // add a Python launch cmd file
        byte [] cmdBytes = readAll(getClass().getResourceAsStream("/pt.cmd"));
        ZipArchiveEntry cmdEntry = new ZipArchiveEntry("pt.cmd");
        cmdEntry.setSize(cmdBytes.length);
        cmdEntry.setUnixMode(FileMode.REGULAR_FILE.getBits());
        cmdEntry.setTime(lastModified);
        zos.putArchiveEntry(cmdEntry);
        zos.write(cmdBytes);
        zos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        ZipArchiveEntry txtEntry = new ZipArchiveEntry("readme.txt");
        txtEntry.setSize(txtBytes.length);
        txtEntry.setUnixMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setTime(lastModified);
        zos.putArchiveEntry(txtEntry);
        zos.write(txtBytes);
        zos.closeArchiveEntry();

        // cleanup
        zos.finish();
        zos.close();
        os.flush();
      } else {
        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
        TarArchiveEntry pyEntry = new TarArchiveEntry("pt");
        pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setModTime(lastModified);
        pyEntry.setSize(pyBytes.length);
        tos.putArchiveEntry(pyEntry);
        tos.write(pyBytes);
        tos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        TarArchiveEntry txtEntry = new TarArchiveEntry("README");
        txtEntry.setMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setModTime(lastModified);
        txtEntry.setSize(txtBytes.length);
        tos.putArchiveEntry(txtEntry);
        tos.write(txtBytes);
        tos.closeArchiveEntry();

        // cleanup
View Full Code Here

        if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
          continue;
        }
        tw.getObjectId(id, 0);

        ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
        entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
        entry.setComment(commit.getName());
        entry.setUnixMode(mode.getBits());
        entry.setTime(modified);
        zos.putArchiveEntry(entry);

        ObjectLoader ldr = repository.open(id);
        ldr.copyTo(zos);
        zos.closeArchiveEntry();
View Full Code Here

      throw new IllegalArgumentException(MessageFormat.format(
          ArchiveText.get().pathDoesNotMatchMode, path, mode));
    if (!path.endsWith("/") && mode == FileMode.TREE) //$NON-NLS-1$
      path = path + "/"; //$NON-NLS-1$

    final ZipArchiveEntry entry = new ZipArchiveEntry(path);
    if (mode == FileMode.TREE) {
      out.putArchiveEntry(entry);
      out.closeArchiveEntry();
      return;
    }

    if (mode == FileMode.REGULAR_FILE) {
      // ok
    } else if (mode == FileMode.EXECUTABLE_FILE
        || mode == FileMode.SYMLINK) {
      entry.setUnixMode(mode.getBits());
    } else {
      // Unsupported mode (e.g., GITLINK).
      throw new IllegalArgumentException(MessageFormat.format(
          ArchiveText.get().unsupportedMode, mode));
    }
    entry.setSize(loader.getSize());
    out.putArchiveEntry(entry);
    loader.copyTo(out);
    out.closeArchiveEntry();
  }
View Full Code Here

        return MediaType.APPLICATION_ZIP;
    }

    private MediaType detectOpenDocument(ZipFile zip) {
        try {
            ZipArchiveEntry mimetype = zip.getEntry("mimetype");
            if (mimetype != null) {
                InputStream stream = zip.getInputStream(mimetype);
                try {
                    return MediaType.parse(IOUtils.toString(stream, "UTF-8"));
                } finally {
View Full Code Here

    }

    public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
            throws IOException, SAXException, TikaException {
        ZipArchiveInputStream zip = new ZipArchiveInputStream(stream);
        ZipArchiveEntry entry = zip.getNextZipEntry();

        while (entry != null) {
            if (!IWORK_CONTENT_ENTRIES.contains(entry.getName())) {
                entry = zip.getNextZipEntry();
                continue;
            }

            InputStream entryStream = new BufferedInputStream(zip, 4096);
View Full Code Here

  }

  public void putEntry(ArchiveOutputStream out,
      String path, FileMode mode, ObjectLoader loader)
      throws IOException {
    final ZipArchiveEntry entry = new ZipArchiveEntry(path);

    if (mode == FileMode.REGULAR_FILE) {
      // ok
    } else if (mode == FileMode.EXECUTABLE_FILE
        || mode == FileMode.SYMLINK) {
      entry.setUnixMode(mode.getBits());
    } else {
      // TODO(jrn): Let the caller know the tree contained
      // an entry with unsupported mode (e.g., a submodule).
    }
    entry.setSize(loader.getSize());
    out.putArchiveEntry(entry);
    try {
      loader.copyTo(out);
    } finally {
      out.closeArchiveEntry();
View Full Code Here

            }
            if(zipArchive != null){
                boolean isError = false;
                Enumeration<ZipArchiveEntry> entries = zipArchive.getEntries();
                while(entries.hasMoreElements()){
                    ZipArchiveEntry entry = entries.nextElement();
                    if(!entry.isDirectory()){
                        String entryName = entry.getName();
                        log.info("     o loading entry '{}'", entryName);
                        try {
                            ResourceState state = resourceImporter.importResource(
                                zipArchive.getInputStream(entry),
                                FilenameUtils.getName(entryName));
View Full Code Here

        }
        if(paodingDict.isFile()){
            throw new IllegalArgumentException("The parsed paoding dictionary MUST NOT be a File");
        }
        ZipArchiveInputStream zin = new ZipArchiveInputStream(in);
        ZipArchiveEntry entry;
        try {
            while((entry = zin.getNextZipEntry()) != null){
                if(!entry.isDirectory()){
                    File file = new File(paodingDict,entry.getName());
                    if(!file.isFile()){
                        //copy the entry
                        log.debug("   > copy {}",entry.getName());
                        IOUtils.copy(zin, FileUtils.openOutputStream(file));
                    } else {
                        log.debug("   < {} already present",entry.getName());
                    }
                }
            }
            log.info("  ... paoding dictionaly initialised");
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.zip.ZipArchiveEntry

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.