org.apache.commons.compress.archivers.zip.ZipArchiveEntry Java Examples
The following examples show how to use
org.apache.commons.compress.archivers.zip.ZipArchiveEntry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZipLeveledStructureProvider.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Creates a new container zip entry with the specified name, iff it has * not already been created. If the parent of the given element does not * already exist it will be recursively created as well. * @param pathname The path representing the container * @return The element represented by this pathname (it may have already existed) */ protected ZipArchiveEntry createContainer(IPath pathname) { ZipArchiveEntry existingEntry = directoryEntryCache.get(pathname); if (existingEntry != null) { return existingEntry; } ZipArchiveEntry parent; if (pathname.segmentCount() == 0) { return null; } else if (pathname.segmentCount() == 1) { parent = root; } else { parent = createContainer(pathname.removeLastSegments(1)); } ZipArchiveEntry newEntry = new ZipArchiveEntry(pathname.toString()); directoryEntryCache.put(pathname, newEntry); List<ZipArchiveEntry> childList = new ArrayList<>(); children.put(newEntry, childList); List<ZipArchiveEntry> parentChildList = children.get(parent); NonNullUtils.checkNotNull(parentChildList).add(newEntry); return newEntry; }
Example #2
Source File: InstrumentTaskTest.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
private Map<String, byte[]> readZipFromResource(String path) throws IOException { ClassLoader cl = ClassLoader.getSystemClassLoader(); URL url = cl.getResource(path); Validate.isTrue(url != null); Map<String, byte[]> ret = new LinkedHashMap<>(); try (InputStream is = url.openStream(); ZipArchiveInputStream zais = new ZipArchiveInputStream(is)) { ZipArchiveEntry entry; while ((entry = zais.getNextZipEntry()) != null) { ret.put(entry.getName(), IOUtils.toByteArray(zais)); } } return ret; }
Example #3
Source File: AbstractInitializrIntegrationTests.java From initializr with Apache License 2.0 | 6 votes |
private void unzip(Path archiveFile, Path project) throws IOException { try (ZipFile zip = new ZipFile(archiveFile.toFile())) { Enumeration<? extends ZipArchiveEntry> entries = zip.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); Path path = project.resolve(entry.getName()); if (entry.isDirectory()) { Files.createDirectories(path); } else { Files.createDirectories(path.getParent()); Files.write(path, StreamUtils.copyToByteArray(zip.getInputStream(entry))); } applyPermissions(path, getPosixFilePermissions(entry.getUnixMode())); } } }
Example #4
Source File: ZipUtils.java From yes-cart with Apache License 2.0 | 6 votes |
private void unzipEntry(final ZipFile zipfile, final ZipArchiveEntry entry, final File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return; } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } try (BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) { IOUtils.copy(inputStream, outputStream); } }
Example #5
Source File: ZipStripper.java From reproducible-build-maven-plugin with Apache License 2.0 | 6 votes |
private void fixAttributes(ZipArchiveEntry entry) { if (fixZipExternalFileAttributes) { /* ZIP external file attributes: TTTTsstrwxrwxrwx0000000000ADVSHR ^^^^____________________________ file type (file: 1000 , dir: 0100) ^^^_________________________ setuid, setgid, sticky ^^^^^^^^^________________ Unix permissions ^^^^^^ DOS attributes The argument of setUnixMode() only takes the 2 upper bytes. */ if (entry.isDirectory()) { entry.setUnixMode((0b0100 << 12) + 0755); } else { entry.setUnixMode((0b1000 << 12) + 0644); } } }
Example #6
Source File: CompressExtension.java From jphp with Apache License 2.0 | 6 votes |
@Override public void onRegister(CompileScope scope) { // register classes ... registerWrapperClass(scope, ArchiveEntry.class, PArchiveEntry.class); registerWrapperClass(scope, TarArchiveEntry.class, PTarArchiveEntry.class); registerWrapperClass(scope, ZipArchiveEntry.class, PZipArchiveEntry.class); registerWrapperClass(scope, ArchiveInputStream.class, PArchiveInput.class); registerWrapperClass(scope, TarArchiveInputStream.class, PTarArchiveInput.class); registerWrapperClass(scope, ZipArchiveInputStream.class, PZipArchiveInput.class); registerWrapperClass(scope, ArchiveOutputStream.class, PArchiveOutput.class); registerWrapperClass(scope, TarArchiveOutputStream.class, PTarArchiveOutput.class); registerWrapperClass(scope, ZipArchiveOutputStream.class, PZipArchiveOutput.class); registerClass(scope, PGzipOutputStream.class); registerClass(scope, PGzipInputStream.class); registerClass(scope, PBzip2OutputStream.class); registerClass(scope, PBZip2InputStream.class); registerClass(scope, PLz4OutputStream.class); registerClass(scope, PLz4InputStream.class); registerClass(scope, PArchive.class); registerClass(scope, PTarArchive.class); registerClass(scope, PZipArchive.class); }
Example #7
Source File: ZipTest.java From document-management-system with GNU General Public License v2.0 | 6 votes |
public void testApache() throws IOException, ArchiveException { log.debug("testApache()"); File zip = File.createTempFile("apache_", ".zip"); // Create zip FileOutputStream fos = new FileOutputStream(zip); ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos); aos.putArchiveEntry(new ZipArchiveEntry("coñeta")); aos.closeArchiveEntry(); aos.close(); // Read zip FileInputStream fis = new FileInputStream(zip); ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis); ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry(); assertEquals(zae.getName(), "coñeta"); ais.close(); }
Example #8
Source File: ZipAssertTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void isDirectoryShouldNotThrowWhenDirectory() throws Exception { try (ZipArchiveOutputStream archiveOutputStream = new ZipArchiveOutputStream(destination)) { ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new Directory("any"), DIRECTORY_NAME); archiveOutputStream.putArchiveEntry(archiveEntry); archiveOutputStream.closeArchiveEntry(); archiveOutputStream.finish(); } try (ZipFile zipFile = new ZipFile(destination)) { assertThatCode(() -> assertThatZip(zipFile) .containsOnlyEntriesMatching( hasName(DIRECTORY_NAME) .isDirectory())) .doesNotThrowAnyException(); } }
Example #9
Source File: Package.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Hook called right after a file has been unzipped (during an install). * <p/> * The base class implementation makes sure to properly adjust set executable * permission on Linux and MacOS system if the zip entry was marked as +x. * * @param archive The archive that is being installed. * @param monitor The {@link ITaskMonitor} to display errors. * @param fileOp The {@link IFileOp} used by the archive installer. * @param unzippedFile The file that has just been unzipped in the install temp directory. * @param zipEntry The {@link ZipArchiveEntry} that has just been unzipped. */ public void postUnzipFileHook( Archive archive, ITaskMonitor monitor, IFileOp fileOp, File unzippedFile, ZipArchiveEntry zipEntry) { // if needed set the permissions. if (sUsingUnixPerm && fileOp.isFile(unzippedFile)) { // get the mode and test if it contains the executable bit int mode = zipEntry.getUnixMode(); if ((mode & 0111) != 0) { try { fileOp.setExecutablePermission(unzippedFile); } catch (IOException ignore) {} } } }
Example #10
Source File: Unzip.java From buck with Apache License 2.0 | 6 votes |
private void extractDirectory( ExistingFileMode existingFileMode, SortedMap<Path, ZipArchiveEntry> pathMap, DirectoryCreator creator, Path target) throws IOException { ProjectFilesystem filesystem = creator.getFilesystem(); if (filesystem.isDirectory(target, LinkOption.NOFOLLOW_LINKS)) { // We have a pre-existing directory: delete its contents if they aren't in the zip. if (existingFileMode == ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES) { for (Path path : filesystem.getDirectoryContents(target)) { if (!pathMap.containsKey(path)) { filesystem.deleteRecursivelyIfExists(path); } } } } else if (filesystem.exists(target, LinkOption.NOFOLLOW_LINKS)) { filesystem.deleteFileAtPath(target); creator.mkdirs(target); } else { creator.forcefullyCreateDirs(target); } }
Example #11
Source File: ZipUtils.java From youtubedl-android with GNU General Public License v3.0 | 6 votes |
public static void unzip(InputStream inputStream, File targetDirectory) throws IOException, IllegalAccessException { try (ZipArchiveInputStream zis = new ZipArchiveInputStream(new BufferedInputStream(inputStream))) { ZipArchiveEntry entry = null; while ((entry = zis.getNextZipEntry()) != null) { File entryDestination = new File(targetDirectory, entry.getName()); // prevent zipSlip if (!entryDestination.getCanonicalPath().startsWith(targetDirectory.getCanonicalPath() + File.separator)) { throw new IllegalAccessException("Entry is outside of the target dir: " + entry.getName()); } if (entry.isDirectory()) { entryDestination.mkdirs(); } else { entryDestination.getParentFile().mkdirs(); try (OutputStream out = new FileOutputStream(entryDestination)) { IOUtils.copy(zis, out); } } } } }
Example #12
Source File: ZippedToolkitRemoteContext.java From streamsx.topology with Apache License 2.0 | 6 votes |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fn = file.getFileName().toString(); // Skip pyc and pyi files. if (fn.endsWith(".pyc") || fn.endsWith(".pyi")) 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; }
Example #13
Source File: ZipRuleIntegrationTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void shouldZipSources() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "zip-rule", tmp); workspace.setUp(); Path zip = workspace.buildAndReturnOutput("//example:ziptastic"); // Make sure we have the right files and attributes. try (ZipFile zipFile = new ZipFile(zip.toFile())) { ZipArchiveEntry cake = zipFile.getEntry("cake.txt"); assertThat(cake, Matchers.notNullValue()); assertFalse(cake.isUnixSymlink()); assertFalse(cake.isDirectory()); ZipArchiveEntry beans = zipFile.getEntry("beans/"); assertThat(beans, Matchers.notNullValue()); assertFalse(beans.isUnixSymlink()); assertTrue(beans.isDirectory()); ZipArchiveEntry cheesy = zipFile.getEntry("beans/cheesy.txt"); assertThat(cheesy, Matchers.notNullValue()); assertFalse(cheesy.isUnixSymlink()); assertFalse(cheesy.isDirectory()); } }
Example #14
Source File: BarFileValidateTest.java From io with Apache License 2.0 | 6 votes |
/** * barファイル内エントリのファイルサイズ上限値を超えた場合に例外が発生すること. */ @Test public void barファイル内エントリのファイルサイズ上限値を超えた場合に例外が発生すること() { TestBarInstaller testBarInstaller = new TestBarInstaller(); URL fileUrl = ClassLoader.getSystemResource("requestData/barInstall/V1_1_2_bar_minimum.bar"); File file = new File(fileUrl.getPath()); try { ZipFile zipFile = new ZipFile(file, "UTF-8"); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); long maxBarEntryFileSize = 0; while (entries.hasMoreElements()) { ZipArchiveEntry zae = entries.nextElement(); if (zae.isDirectory()) { continue; } testBarInstaller.checkBarFileEntrySize(zae, zae.getName(), maxBarEntryFileSize); } fail("Unexpected exception"); } catch (DcCoreException dce) { String code = DcCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE.getCode(); assertEquals(code, dce.getCode()); } catch (Exception ex) { fail("Unexpected exception"); } }
Example #15
Source File: ScatterZipOutputStream.java From importer-exporter with Apache License 2.0 | 6 votes |
void writeTo(ZipArchiveOutputStream target) throws IOException { entryStore.closeForWriting(); backingStore.closeForWriting(); String line; try (InputStream stream = backingStore.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(entryStore.getInputStream(), StandardCharsets.UTF_8))) { while ((line = reader.readLine()) != null) { String[] values = line.split(","); if (values.length != 5) throw new IOException("Failed to read temporary zip entry."); ZipArchiveEntry entry = new ZipArchiveEntry(values[0]); entry.setMethod(Integer.parseInt(values[1])); entry.setCrc(Long.parseLong(values[2])); entry.setCompressedSize(Long.parseLong(values[3])); entry.setSize(Long.parseLong(values[4])); try (BoundedInputStream rawStream = new BoundedInputStream(stream, entry.getCompressedSize())) { target.addRawArchiveEntry(entry, rawStream); } } } catch (NumberFormatException e) { throw new IOException("Failed to read temporary zip entry.", e); } }
Example #16
Source File: CompressExample.java From spring-boot with Apache License 2.0 | 6 votes |
public static void makeOnlyUnZip() throws ArchiveException, IOException{ final InputStream is = new FileInputStream("D:/中文名字.zip"); ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is); ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry(); String dir = "D:/cnname"; File filedir = new File(dir); if(!filedir.exists()){ filedir.mkdir(); } // OutputStream out = new FileOutputStream(new File(dir, entry.getName())); OutputStream out = new FileOutputStream(new File(filedir, entry.getName())); IOUtils.copy(in, out); out.close(); in.close(); }
Example #17
Source File: ScrubService.java From support-diagnostics with Apache License 2.0 | 6 votes |
public Vector<TaskEntry> collectZipEntries(String filename, String scrubDir) { Vector<TaskEntry> archiveEntries = new Vector<>(); try { ZipFile zf = new ZipFile(new File(filename)); Enumeration<ZipArchiveEntry> entries = zf.getEntries(); ZipArchiveEntry ent = entries.nextElement(); String archiveName = ent.getName(); while (entries.hasMoreElements()) { ZipArchiveEntry zae = entries.nextElement(); TaskEntry te = new ZipFileTaskEntry(zf, zae, archiveName); if(zae.isDirectory()){ new File(scrubDir + SystemProperties.fileSeparator + te.entryName()).mkdir(); } else{ archiveEntries.add(te); } } } catch (IOException e) { logger.error(Constants.CONSOLE, "Error obtaining zip file entries"); logger.error(e); } return archiveEntries; }
Example #18
Source File: DownloadService.java From fredbet with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
byte[] compressToZipFile(List<BinaryImage> allImages) { try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ZipArchiveOutputStream zipOutput = new ZipArchiveOutputStream(byteOut);) { zipOutput.setEncoding("UTF-8"); for (int i = 0; i < allImages.size(); i++) { BinaryImage image = allImages.get(i); String fileName = createEntryFileName(image, i + 1); ZipArchiveEntry entry = new ZipArchiveEntry(fileName); entry.setSize(image.getImageBinary().length); zipOutput.putArchiveEntry(entry); copyToOutputStream(zipOutput, image.getImageBinary()); zipOutput.closeArchiveEntry(); } zipOutput.close(); return byteOut.toByteArray(); } catch (Exception e) { LOG.error(e.getMessage(), e); return null; } }
Example #19
Source File: AttributeAccessor.java From jarchivelib with Apache License 2.0 | 6 votes |
/** * Detects the type of the given ArchiveEntry and returns an appropriate AttributeAccessor for it. * * @param entry the adaptee * @return a new attribute accessor instance */ public static AttributeAccessor<?> create(ArchiveEntry entry) { if (entry instanceof TarArchiveEntry) { return new TarAttributeAccessor((TarArchiveEntry) entry); } else if (entry instanceof ZipArchiveEntry) { return new ZipAttributeAccessor((ZipArchiveEntry) entry); } else if (entry instanceof CpioArchiveEntry) { return new CpioAttributeAccessor((CpioArchiveEntry) entry); } else if (entry instanceof ArjArchiveEntry) { return new ArjAttributeAccessor((ArjArchiveEntry) entry); } else if (entry instanceof ArArchiveEntry) { return new ArAttributeAccessor((ArArchiveEntry) entry); } return new FallbackAttributeAccessor(entry); }
Example #20
Source File: ACPImportPackageHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public InputStream importStream(String content) { ZipArchiveEntry zipEntry = zipFile.getEntry(content); if (zipEntry == null) { // Note: for some reason, when modifying a zip archive the path seperator changes // TODO: Need to investigate further as to why and whether this workaround is enough content = content.replace('\\', '/'); zipEntry = zipFile.getEntry(content); if (zipEntry == null) { throw new ImporterException("Failed to find content " + content + " within zip package"); } } try { return zipFile.getInputStream(zipEntry); } catch (IOException e) { throw new ImporterException("Failed to open content " + content + " within zip package due to " + e.getMessage(), e); } }
Example #21
Source File: Unzip.java From buck with Apache License 2.0 | 6 votes |
private void extractFile( ImmutableSet.Builder<Path> filesWritten, ZipFile zip, DirectoryCreator creator, Path target, ZipArchiveEntry entry) throws IOException { ProjectFilesystem filesystem = creator.getFilesystem(); if (filesystem.isFile(target, LinkOption.NOFOLLOW_LINKS)) { // NOPMD for clarity // pass } else if (filesystem.exists(target, LinkOption.NOFOLLOW_LINKS)) { filesystem.deleteRecursivelyIfExists(target); } else if (target.getParent() != null) { creator.forcefullyCreateDirs(target.getParent()); } filesWritten.add(target); writeZipContents(zip, entry, filesystem, target); }
Example #22
Source File: ZipRuleIntegrationTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void shouldUnpackContentsOfZipSources() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "zip-rule", tmp); workspace.setUp(); Path zip = workspace.buildAndReturnOutput("//example:zipsources"); try (ZipFile zipFile = new ZipFile(zip.toFile())) { ZipArchiveEntry menu = zipFile.getEntry("menu.txt"); assertThat(menu, Matchers.notNullValue()); assertFalse(menu.isUnixSymlink()); assertFalse(menu.isDirectory()); ZipArchiveEntry cake = zipFile.getEntry("cake.txt"); assertThat(cake, Matchers.notNullValue()); assertFalse(cake.isUnixSymlink()); assertFalse(cake.isDirectory()); } }
Example #23
Source File: Unzip.java From buck with Apache License 2.0 | 6 votes |
/** * Get a listing of all files in a zip file that start with a prefix, ignore others * * @param zip The zip file to scan * @param relativePath The relative path where the extraction will be rooted * @param prefix The prefix that will be stripped off. * @return The list of paths in {@code zip} sorted by path so dirs come before contents. Prefixes * are stripped from paths in the zip file, such that foo/bar/baz.txt with a prefix of foo/ * will be in the map at {@code relativePath}/bar/baz.txt */ private static SortedMap<Path, ZipArchiveEntry> getZipFilePathsStrippingPrefix( ZipFile zip, Path relativePath, Path prefix, PatternsMatcher entriesToExclude) { SortedMap<Path, ZipArchiveEntry> pathMap = new TreeMap<>(); for (ZipArchiveEntry entry : Collections.list(zip.getEntries())) { String entryName = entry.getName(); if (entriesToExclude.matches(entryName)) { continue; } Path entryPath = Paths.get(entryName); if (entryPath.startsWith(prefix)) { Path target = relativePath.resolve(prefix.relativize(entryPath)).normalize(); pathMap.put(target, entry); } } return pathMap; }
Example #24
Source File: GeneratorService.java From vertx-starter with Apache License 2.0 | 6 votes |
private void addFile(Path rootPath, Path filePath, ArchiveOutputStream stream) throws IOException { String relativePath = rootPath.relativize(filePath).toString(); if (relativePath.length() == 0) return; String entryName = jarFileWorkAround(leadingDot(relativePath)); ArchiveEntry entry = stream.createArchiveEntry(filePath.toFile(), entryName); if (EXECUTABLES.contains(entryName)) { if (entry instanceof ZipArchiveEntry) { ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entry; zipArchiveEntry.setUnixMode(0744); } else if (entry instanceof TarArchiveEntry) { TarArchiveEntry tarArchiveEntry = (TarArchiveEntry) entry; tarArchiveEntry.setMode(0100744); } } stream.putArchiveEntry(entry); if (filePath.toFile().isFile()) { try (InputStream i = Files.newInputStream(filePath)) { IOUtils.copy(i, stream); } } stream.closeArchiveEntry(); }
Example #25
Source File: AzkabanJobHelper.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@edu.umd.cs.findbugs.annotations.SuppressWarnings( value = "OBL_UNSATISFIED_OBLIGATION", justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs") private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException { try { @Cleanup OutputStream archiveStream = new FileOutputStream(zipFile); @Cleanup ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream); for (File fileToAdd : filesToAdd) { ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName()); archive.putArchiveEntry(entry); @Cleanup BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd)); IOUtils.copy(input, archive); archive.closeArchiveEntry(); } archive.finish(); } catch (ArchiveException e) { throw new IOException("Issue with creating archive", e); } }
Example #26
Source File: DocxFile.java From wechattool with MIT License | 5 votes |
@NotNull private String copyImageFile(String filepath) throws IOException { File file = new File(filepath); outfile.putArchiveEntry(new ZipArchiveEntry("word/media/"+file.getName())); BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(stream,outfile); outfile.closeArchiveEntry(); return file.getName(); }
Example #27
Source File: ZipReader.java From kkFileView with Apache License 2.0 | 5 votes |
private Enumeration<ZipArchiveEntry> sortZipEntries(Enumeration<ZipArchiveEntry> entries) { List<ZipArchiveEntry> sortedEntries = Lists.newArrayList(); while(entries.hasMoreElements()){ sortedEntries.add(entries.nextElement()); } sortedEntries.sort(Comparator.comparingInt(o -> o.getName().length())); return Collections.enumeration(sortedEntries); }
Example #28
Source File: ZipAssert.java From james-project with Apache License 2.0 | 5 votes |
public ZipAssert hasEntriesSize(int expectedSize) { isNotNull(); assertThat(expectedSize).describedAs("expectedSize cannot be a negative number") .isGreaterThanOrEqualTo(0); ArrayList<ZipArchiveEntry> zipEntries = Collections.list(zipFile.getEntries()); if (zipEntries.size() != expectedSize) { throwAssertionError(shouldHaveEntriesSize(zipEntries.size(), expectedSize)); } return myself; }
Example #29
Source File: SourcePackage.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Set all the files from a source package as read-only * so that users don't end up modifying sources by mistake in Eclipse. */ @Override public void postUnzipFileHook( Archive archive, ITaskMonitor monitor, IFileOp fileOp, File unzippedFile, ZipArchiveEntry zipEntry) { super.postUnzipFileHook(archive, monitor, fileOp, unzippedFile, zipEntry); if (fileOp.isFile(unzippedFile) && !SdkConstants.FN_SOURCE_PROP.equals(unzippedFile.getName())) { fileOp.setReadOnly(unzippedFile); } }
Example #30
Source File: ZipLeveledStructureProvider.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public InputStream getContents(Object element) { try { return zipFile.getInputStream((ZipArchiveEntry) element); } catch (IOException e) { IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e); return null; } }