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


Java ZipArchiveEntry.setExternalAttributes方法代碼示例

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


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

示例1: entryToNewName

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * Entry to new name.
 *
 * @param source the source
 * @param name the name
 * @return the zip archive entry
 * @throws ZipException the zip exception
 */
public static ZipArchiveEntry entryToNewName(ZipArchiveEntry source, String name) throws ZipException {
  if (source.getName().equals(name))
    return new ZipArchiveEntry(source);
  ZipArchiveEntry ret = new ZipArchiveEntry(name);
  byte[] extra = source.getExtra();
  if (extra != null) {
    ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ));
  } else {
    ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true)));
  }
  ret.setInternalAttributes(source.getInternalAttributes());
  ret.setExternalAttributes(source.getExternalAttributes());
  ret.setExtraFields(source.getExtraFields(true));
  ret.setCrc(source.getCrc());
  ret.setMethod(source.getMethod());
  ret.setSize(source.getSize());
  return ret;
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:27,代碼來源:JarDelta.java

示例2: addFolder

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * 
 * @param folder
 * @param parentFolderInZip - 
 * @throws Exception
 */
public void addFolder(File folder, String parentFolderInZip) throws Exception {
	StringBuilder sb = new StringBuilder(parentFolderInZip.length()+64).append(parentFolderInZip);
	if (!parentFolderInZip.endsWith("/")) {
		sb.append('/');
	}
	sb.append(folder.getName()).append('/');
	int baseLen = sb.length();
	long attr = getExternalAttribute(folder);
	if (attr != 0) {
		attr = attr | ATTR_DIR;
		ZipArchiveEntry ze = new ZipArchiveEntry(sb.toString());
		ze.setExternalAttributes(attr);
		zout.putArchiveEntry(ze);
		zout.closeArchiveEntry();
	}
	
	File[] fa = folder.listFiles();
	for (int i = 0; i < fa.length; i++) {
		File f = fa[i];
		if (f.isDirectory()) {
			addFolder(f, sb.toString());
		} else {
			FileInputStream fin = new FileInputStream(f);
			addStream(sb.append(f.getName()).toString(), fin, getExternalAttribute(f));
			sb.setLength(baseLen);
		}
	}
}
 
開發者ID:BeckYang,項目名稱:TeamFileList,代碼行數:35,代碼來源:ZipUtil.java

示例3: copyEntry

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //導入方法依賴的package包/類
/**
 * Entry to new name.
 *
 * @param source the source
 * @param name the name
 * @return the zip archive entry
 * @throws ZipException the zip exception
 */
private ZipArchiveEntry copyEntry(ZipArchiveEntry source) throws ZipException {
  ZipArchiveEntry ret = new ZipArchiveEntry(source.getName());
  byte[] extra = source.getExtra();
  if (extra != null) {
    ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ));
  } else {
    ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true)));
  }
  ret.setInternalAttributes(source.getInternalAttributes());
  ret.setExternalAttributes(source.getExternalAttributes());
  ret.setExtraFields(source.getExtraFields(true));
  return ret;
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:22,代碼來源:JarPatcher.java

示例4: 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


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