本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry.setSize方法的具体用法?Java ZipArchiveEntry.setSize怎么用?Java ZipArchiveEntry.setSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.zip.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.setSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: createArchiveEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* Use for writing streams - must specify file size in advance as well
*/
public static ArchiveEntry createArchiveEntry(String relativePath, ArchiveType archiveType, long size) {
switch (archiveType) {
case ZIP:
ZipArchiveEntry zipEntry = new ZipArchiveEntry(relativePath);
zipEntry.setSize(size);
return zipEntry;
case TAR:
case TARGZ:
case TGZ:
TarArchiveEntry tarEntry = new TarArchiveEntry(relativePath);
tarEntry.setSize(size);
return tarEntry;
}
throw new IllegalArgumentException("Unsupported archive type: '" + archiveType + "'");
}
示例3: zip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
/**
* Add one file to the open zip archive stream. Drops the file if it is a directory
*
* @param fileToZip
* @param baseDir
* @param os
* @throws Throwable
*/
public static void zip(File fileToZip, ZipArchiveOutputStream os) throws Throwable {
if (fileToZip.isDirectory()) return;
byte buffer[] = new byte[BUFFER_SIZE];
String name = fileToZip.getName();
ZipArchiveEntry entry = new ZipArchiveEntry(fileToZip, name);
entry.setSize(fileToZip.length());
os.putArchiveEntry(entry);
BufferedInputStream is = new BufferedInputStream(new FileInputStream(fileToZip), BUFFER_SIZE);
int count;
try {
while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
os.write(buffer, 0, count);
}
} finally {
is.close();
}
os.closeArchiveEntry();
}
示例4: visitEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
public void visitEntry(ApkArchiveEntry entry) throws IOException {
super.visitEntry(entry);
if (includedFiles.contains(entry.getFilename())) {
return;
}
ZipArchiveEntry zipEntry = new ZipArchiveEntry(entry.getFilename());
includedFiles.add(entry.getFilename());
if (entry.getMethod() == ZipEntry.STORED) {
zipEntry.setSize(entry.getSize());
zipEntry.setCrc(entry.getCrc());
}
zaos.setMethod(entry.getMethod());
zaos.putArchiveEntry(zipEntry);
IOUtils.copy(entry.getInputStream(), zaos);
zaos.closeArchiveEntry();
}
示例5: sendCompressedFile
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
protected void sendCompressedFile(MCRPath file, BasicFileAttributes attrs, ZipArchiveOutputStream container)
throws IOException {
ZipArchiveEntry entry = new ZipArchiveEntry(getFilename(file));
entry.setTime(attrs.lastModifiedTime().toMillis());
entry.setSize(attrs.size());
container.putArchiveEntry(entry);
try {
Files.copy(file, container);
} finally {
container.closeArchiveEntry();
}
}
示例6: sendMetadataCompressed
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
protected void sendMetadataCompressed(String fileName, byte[] content, long lastModified,
ZipArchiveOutputStream container) throws IOException {
ZipArchiveEntry entry = new ZipArchiveEntry(fileName);
entry.setSize(content.length);
entry.setTime(lastModified);
container.putArchiveEntry(entry);
container.write(content);
container.closeArchiveEntry();
}
示例7: newTailArchive
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static ArchiveEntry newTailArchive(String name, byte[] tail) {
ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
zipEntry.setSize(tail.length);
zipEntry.setCompressedSize(zipEntry.getSize());
CRC32 crc32 = new CRC32();
crc32.update(tail);
zipEntry.setCrc(crc32.getValue());
return zipEntry;
}
示例8: newArchive
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static ArchiveEntry newArchive(File file) throws IOException {
ZipArchiveEntry zipEntry = new ZipArchiveEntry(file.getName());
zipEntry.setSize(file.length());
zipEntry.setCompressedSize(zipEntry.getSize());
zipEntry.setCrc(FileUtils.checksumCRC32(file));
return zipEntry;
}
示例9: newStoredEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
protected ArchiveEntry newStoredEntry(String name, byte[] data) {
ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
zipEntry.setSize(data.length);
zipEntry.setCompressedSize(zipEntry.getSize());
CRC32 crc32 = new CRC32();
crc32.update(data);
zipEntry.setCrc(crc32.getValue());
return zipEntry;
}
示例10: createEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
ArchiveEntry createEntry(long size) throws IOException {
// TODO: How to set entry name and indexes.
String name = String.format(entryNamePrefix, baseNum, count++);
switch (format) {
case CPIO:
CpioArchiveEntry cpioEntry = new CpioArchiveEntry(name);
cpioEntry.setSize(size);
cpioEntry.setTime(System.currentTimeMillis());
return cpioEntry;
case JAR:
JarArchiveEntry jarEntry = new JarArchiveEntry(name);
jarEntry.setSize(size);
jarEntry.setTime(System.currentTimeMillis());
return jarEntry;
case TAR:
TarArchiveEntry tarEntry = new TarArchiveEntry(name);
tarEntry.setSize(size);
tarEntry.setModTime(System.currentTimeMillis());
return tarEntry;
case ZIP:
ZipArchiveEntry zipEntry = new ZipArchiveEntry(name);
zipEntry.setSize(size);
zipEntry.setTime(System.currentTimeMillis());
return zipEntry;
}
// Normally, this code is not called because of the above switch.
throw new IOException("Format is configured.");
}
示例11: strip
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
public void strip(File in, File out) throws IOException
{
try (final ZipFile zip = new ZipFile(in);
final ZipArchiveOutputStream zout = new ZipArchiveOutputStream(out))
{
final List<String> sortedNames = sortEntriesByName(zip.getEntries());
for (String name : sortedNames)
{
final ZipArchiveEntry entry = zip.getEntry(name);
// Strip Zip entry
final ZipArchiveEntry strippedEntry = filterZipEntry(entry);
// Strip file if required
final Stripper stripper = getSubFilter(name);
if (stripper != null)
{
// Unzip entry to temp file
final File tmp = File.createTempFile("tmp", null);
tmp.deleteOnExit();
Files.copy(zip.getInputStream(entry), tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
final File tmp2 = File.createTempFile("tmp", null);
tmp2.deleteOnExit();
stripper.strip(tmp, tmp2);
final byte[] fileContent = Files.readAllBytes(tmp2.toPath());
strippedEntry.setSize(fileContent.length);
zout.putArchiveEntry(strippedEntry);
zout.write(fileContent);
zout.closeArchiveEntry();
}
else
{
// Copy the Zip entry as-is
zout.addRawArchiveEntry(strippedEntry, zip.getRawInputStream(entry));
}
}
}
}
示例12: writeJarEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static void writeJarEntry(JarArchiveOutputStream jaos, String name, byte[] data) throws IOException {
ZipArchiveEntry entry = new JarArchiveEntry(name);
entry.setSize(data.length);
jaos.putArchiveEntry(entry);
jaos.write(data);
jaos.closeArchiveEntry();
}
示例13: createArchiveEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
@Override
public ArchiveEntry createArchiveEntry(String targetPath, long targetSize, byte[] targetBytes) {
ZipArchiveEntry zipEntry = new ZipArchiveEntry(targetPath);
zipEntry.setSize(targetSize);
zipEntry.setMethod(ZipEntry.STORED);
if (targetBytes != null) {
zipEntry.setCrc(crc32Checksum(targetBytes));
}
return zipEntry;
}
示例14: 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;
}
示例15: 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);
}