當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipArchiveEntry.setUnixMode方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setUnixMode方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipArchiveEntry.setUnixMode方法的具體用法?Java ZipArchiveEntry.setUnixMode怎麽用?Java ZipArchiveEntry.setUnixMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.zip.ZipArchiveEntry的用法示例。


在下文中一共展示了ZipArchiveEntry.setUnixMode方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitFile

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    // Skip pyc files.
    if (file.getFileName().toString().endsWith(".pyc"))
        return FileVisitResult.CONTINUE;
    
    String entryName = rootEntryName;
    String relativePath = start.relativize(file).toString();
    // If empty, file is the start file.
    if(!relativePath.isEmpty()){                          
        entryName = entryName + "/" + relativePath;
    }
    // Zip uses forward slashes
    entryName = entryName.replace(File.separatorChar, '/');
    
    ZipArchiveEntry entry = new ZipArchiveEntry(file.toFile(), entryName);
    if (Files.isExecutable(file))
        entry.setUnixMode(0100770);
    else
        entry.setUnixMode(0100660);

    zos.putArchiveEntry(entry);
    Files.copy(file, zos);
    zos.closeArchiveEntry();
    return FileVisitResult.CONTINUE;
}
 
開發者ID:IBMStreams,項目名稱:streamsx.topology,代碼行數:26,代碼來源:ZippedToolkitRemoteContext.java

示例2: setExtraFields

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private static void setExtraFields(Path filePath, int fileType, ZipArchiveEntry entry) throws IOException {
    if (PosixUtil.isPosixFileStore(filePath)) {
        Set<PosixFilePermission> perms = Files.getPosixFilePermissions(filePath);
        entry.setUnixMode(fileType | PosixUtil.getPosixPermissionsAsInt(perms));
        X5455_ExtendedTimestamp x5455 = getX5455(filePath);
        X7875_NewUnix x7875 = getX7875(filePath);
        if (x5455 != null && x7875 != null) {
            entry.setExtraFields(new ZipExtraField[] {x5455, x7875});
        }
    }
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:12,代碼來源:ZipUtil.java

示例3: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * Zips the contents of the tree at the (optionally) specified revision and the (optionally) specified basepath to the supplied outputstream.
 * 
 * @param repository
 * @param basePath
 *            if unspecified, entire repository is assumed.
 * @param objectId
 *            if unspecified, HEAD is assumed.
 * @param os
 * @return true if repository was successfully zipped to supplied output stream
 */
public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) {
	RevCommit commit = JGitUtils.getCommit(repository, objectId);
	if (commit == null) {
		return false;
	}
	boolean success = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
		zos.setComment("Generated by Gitblit");
		if (!StringUtils.isEmpty(basePath)) {
			PathFilter f = PathFilter.create(basePath);
			tw.setFilter(f);
		}
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		long modified = commit.getAuthorIdent().getWhen().getTime();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			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();
		}
		zos.finish();
		success = true;
	} catch (IOException e) {
		error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
	} finally {
		tw.close();
		rw.close();
		rw.dispose();
	}
	return success;
}
 
開發者ID:tomaswolf,項目名稱:gerrit-gitblit-plugin,代碼行數:62,代碼來源:CompressionUtils.java

示例4: testExtractZipFilePreservesExecutePermissions

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Test
public void testExtractZipFilePreservesExecutePermissions() throws IOException {

  // Create a simple zip archive using apache's commons-compress to store executable info.
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile)) {
    ZipArchiveEntry entry = new ZipArchiveEntry("test.exe");
    entry.setUnixMode((int) MorePosixFilePermissions.toMode(
        PosixFilePermissions.fromString("r-x------")));
    entry.setSize(DUMMY_FILE_CONTENTS.length);
    entry.setMethod(ZipEntry.STORED);
    zip.putArchiveEntry(entry);
    zip.write(DUMMY_FILE_CONTENTS);
    zip.closeArchiveEntry();
  }

  // Now run `Unzip.extractZipFile` on our test zip and verify that the file is executable.
  File extractFolder = tmpFolder.newFolder();
  ImmutableList<Path> result = Unzip.extractZipFile(
      zipFile.toPath().toAbsolutePath(),
      extractFolder.toPath().toAbsolutePath(),
      false);
  File exe = new File(extractFolder.getAbsoluteFile() + "/test.exe");
  assertTrue(exe.exists());
  assertTrue(exe.canExecute());
  assertEquals(
      ImmutableList.of(
          extractFolder.toPath().resolve("test.exe")),
      result);

}
 
開發者ID:saleehk,項目名稱:buck-cutom,代碼行數:31,代碼來源:UnzipTest.java

示例5: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * Zips the contents of the tree at the (optionally) specified revision and
 * the (optionally) specified basepath to the supplied outputstream.
 * 
 * @param repository
 * @param basePath
 *            if unspecified, entire repository is assumed.
 * @param objectId
 *            if unspecified, HEAD is assumed.
 * @param os
 * @return true if repository was successfully zipped to supplied output
 *         stream
 */
public static boolean zip(Repository repository, String basePath, String objectId,
		OutputStream os) {
	RevCommit commit = JGitUtils.getCommit(repository, objectId);
	if (commit == null) {
		return false;
	}
	boolean success = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
		zos.setComment("Generated by Gitblit");
		if (!StringUtils.isEmpty(basePath)) {
			PathFilter f = PathFilter.create(basePath);
			tw.setFilter(f);
		}
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		long modified = commit.getAuthorIdent().getWhen().getTime();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			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();
		}
		zos.finish();
		success = true;
	} catch (IOException e) {
		error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
	} finally {
		tw.release();
		rw.dispose();
	}
	return success;
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:64,代碼來源:CompressionUtils.java

示例6: testExtractZipFilePreservesExecutePermissionsAndModificationTime

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Test
public void testExtractZipFilePreservesExecutePermissionsAndModificationTime()
    throws InterruptedException, IOException {

  // getFakeTime returs time with some non-zero millis. By doing division and multiplication by
  // 1000 we get rid of that.
  final long time = ZipConstants.getFakeTime() / 1000 * 1000;

  // Create a simple zip archive using apache's commons-compress to store executable info.
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
    ZipArchiveEntry entry = new ZipArchiveEntry("test.exe");
    entry.setUnixMode(
        (int) MorePosixFilePermissions.toMode(PosixFilePermissions.fromString("r-x------")));
    entry.setSize(DUMMY_FILE_CONTENTS.length);
    entry.setMethod(ZipEntry.STORED);
    entry.setTime(time);
    zip.putArchiveEntry(entry);
    zip.write(DUMMY_FILE_CONTENTS);
    zip.closeArchiveEntry();
  }

  // Now run `Unzip.extractZipFile` on our test zip and verify that the file is executable.
  Path extractFolder = tmpFolder.newFolder();
  ImmutableList<Path> result =
      ArchiveFormat.ZIP
          .getUnarchiver()
          .extractArchive(
              new DefaultProjectFilesystemFactory(),
              zipFile.toAbsolutePath(),
              extractFolder.toAbsolutePath(),
              ExistingFileMode.OVERWRITE);
  Path exe = extractFolder.toAbsolutePath().resolve("test.exe");
  assertTrue(Files.exists(exe));
  assertThat(Files.getLastModifiedTime(exe).toMillis(), Matchers.equalTo(time));
  assertTrue(Files.isExecutable(exe));
  assertEquals(ImmutableList.of(extractFolder.resolve("test.exe")), result);
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:38,代碼來源:UnzipTest.java

示例7: testExtractSymlink

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Test
public void testExtractSymlink() throws InterruptedException, IOException {
  assumeThat(Platform.detect(), Matchers.is(Matchers.not(Platform.WINDOWS)));

  // Create a simple zip archive using apache's commons-compress to store executable info.
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
    ZipArchiveEntry entry = new ZipArchiveEntry("link.txt");
    entry.setUnixMode((int) MoreFiles.S_IFLNK);
    String target = "target.txt";
    entry.setSize(target.getBytes(Charsets.UTF_8).length);
    entry.setMethod(ZipEntry.STORED);
    zip.putArchiveEntry(entry);
    zip.write(target.getBytes(Charsets.UTF_8));
    zip.closeArchiveEntry();
  }

  Path extractFolder = tmpFolder.newFolder();

  ArchiveFormat.ZIP
      .getUnarchiver()
      .extractArchive(
          new DefaultProjectFilesystemFactory(),
          zipFile.toAbsolutePath(),
          extractFolder.toAbsolutePath(),
          ExistingFileMode.OVERWRITE);
  Path link = extractFolder.toAbsolutePath().resolve("link.txt");
  assertTrue(Files.isSymbolicLink(link));
  assertThat(Files.readSymbolicLink(link).toString(), Matchers.equalTo("target.txt"));
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:30,代碼來源:UnzipTest.java

示例8: testExtractBrokenSymlinkWithOwnerExecutePermissions

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Test
public void testExtractBrokenSymlinkWithOwnerExecutePermissions()
    throws InterruptedException, IOException {
  assumeThat(Platform.detect(), Matchers.is(Matchers.not(Platform.WINDOWS)));

  // Create a simple zip archive using apache's commons-compress to store executable info.
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
    ZipArchiveEntry entry = new ZipArchiveEntry("link.txt");
    entry.setUnixMode((int) MoreFiles.S_IFLNK);
    String target = "target.txt";
    entry.setSize(target.getBytes(Charsets.UTF_8).length);
    entry.setMethod(ZipEntry.STORED);

    // Mark the file as being executable.
    Set<PosixFilePermission> filePermissions = ImmutableSet.of(PosixFilePermission.OWNER_EXECUTE);

    long externalAttributes =
        entry.getExternalAttributes() + (MorePosixFilePermissions.toMode(filePermissions) << 16);
    entry.setExternalAttributes(externalAttributes);

    zip.putArchiveEntry(entry);
    zip.write(target.getBytes(Charsets.UTF_8));
    zip.closeArchiveEntry();
  }

  Path extractFolder = tmpFolder.newFolder();

  ArchiveFormat.ZIP
      .getUnarchiver()
      .extractArchive(
          new DefaultProjectFilesystemFactory(),
          zipFile.toAbsolutePath(),
          extractFolder.toAbsolutePath(),
          ExistingFileMode.OVERWRITE);
  Path link = extractFolder.toAbsolutePath().resolve("link.txt");
  assertTrue(Files.isSymbolicLink(link));
  assertThat(Files.readSymbolicLink(link).toString(), Matchers.equalTo("target.txt"));
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:39,代碼來源:UnzipTest.java

示例9: addZipEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private void addZipEntry(String input, ZipArchiveOutputStream os, String name, boolean executableFile)
  throws Exception
{
  InputStream is = getResourceAsStream(input);

  ZipArchiveEntry zae = new ZipArchiveEntry(name);
  if (executableFile) zae.setUnixMode(33261); else
    zae.setUnixMode(33188);
  os.putArchiveEntry(zae);
  copy(is, os);
  os.closeArchiveEntry();

  is.close();
}
 
開發者ID:lquesada,項目名稱:JarSplicePlus,代碼行數:15,代碼來源:MacAppSplicer.java

示例10: addFileAsZipEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private void addFileAsZipEntry(File inputFile, ZipArchiveOutputStream os, String name) throws Exception
{
  InputStream is = new FileInputStream(inputFile);

  ZipArchiveEntry zae = new ZipArchiveEntry(name);
  zae.setUnixMode(33188);
  os.putArchiveEntry(zae);
  copy(is, os);
  os.closeArchiveEntry();

  is.close();
}
 
開發者ID:lquesada,項目名稱:JarSplicePlus,代碼行數:13,代碼來源:MacAppSplicer.java

示例11: testStripsPrefixAndIgnoresSiblings

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
@Test
public void testStripsPrefixAndIgnoresSiblings() throws IOException, InterruptedException {
  byte[] bazDotSh = "echo \"baz.sh\"\n".getBytes(Charsets.UTF_8);
  try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
    zip.putArchiveEntry(new ZipArchiveEntry("foo"));
    zip.closeArchiveEntry();
    zip.putArchiveEntry(new ZipArchiveEntry("foo/bar/baz.txt"));
    zip.write(DUMMY_FILE_CONTENTS, 0, DUMMY_FILE_CONTENTS.length);
    zip.closeArchiveEntry();

    ZipArchiveEntry exeEntry = new ZipArchiveEntry("foo/bar/baz.sh");
    exeEntry.setUnixMode(
        (int) MorePosixFilePermissions.toMode(PosixFilePermissions.fromString("r-x------")));
    exeEntry.setMethod(ZipEntry.STORED);
    exeEntry.setSize(bazDotSh.length);
    zip.putArchiveEntry(exeEntry);
    zip.write(bazDotSh);

    zip.closeArchiveEntry();
    zip.putArchiveEntry(new ZipArchiveEntry("sibling"));
    zip.closeArchiveEntry();
    zip.putArchiveEntry(new ZipArchiveEntry("sibling/some/dir/and/file.txt"));
    zip.write(DUMMY_FILE_CONTENTS, 0, DUMMY_FILE_CONTENTS.length);
    zip.closeArchiveEntry();
  }

  Path extractFolder = Paths.get("output_dir", "nested");

  ProjectFilesystem filesystem =
      TestProjectFilesystems.createProjectFilesystem(tmpFolder.getRoot());

  ArchiveFormat.ZIP
      .getUnarchiver()
      .extractArchive(
          zipFile,
          filesystem,
          extractFolder,
          Optional.of(Paths.get("foo")),
          ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES);

  assertFalse(filesystem.isDirectory(extractFolder.resolve("sibling")));
  assertFalse(filesystem.isDirectory(extractFolder.resolve("foo")));
  assertFalse(filesystem.isDirectory(extractFolder.resolve("some")));

  Path bazDotTxtPath = extractFolder.resolve("bar").resolve("baz.txt");
  Path bazDotShPath = extractFolder.resolve("bar").resolve("baz.sh");

  assertTrue(filesystem.isDirectory(extractFolder.resolve("bar")));
  assertTrue(filesystem.isFile(bazDotTxtPath));
  assertTrue(filesystem.isFile(bazDotShPath));
  assertTrue(filesystem.isExecutable(bazDotShPath));
  assertEquals(new String(bazDotSh), filesystem.readFileIfItExists(bazDotShPath).get());
  assertEquals(
      new String(DUMMY_FILE_CONTENTS), filesystem.readFileIfItExists(bazDotTxtPath).get());
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:56,代碼來源:UnzipTest.java

示例12: addZipFolder

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
private void addZipFolder(ZipArchiveOutputStream os, String folderName) throws Exception {
  ZipArchiveEntry zae = new ZipArchiveEntry(folderName);
  zae.setUnixMode(16877);
  os.putArchiveEntry(zae);
  os.closeArchiveEntry();
}
 
開發者ID:lquesada,項目名稱:JarSplicePlus,代碼行數:7,代碼來源:MacAppSplicer.java


注:本文中的org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setUnixMode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。