当前位置: 首页>>代码示例>>Java>>正文


Java ArchiveEntry.isDirectory方法代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveEntry.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java ArchiveEntry.isDirectory方法的具体用法?Java ArchiveEntry.isDirectory怎么用?Java ArchiveEntry.isDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.compress.archivers.ArchiveEntry的用法示例。


在下文中一共展示了ArchiveEntry.isDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractMetadataFromArchive

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private static Map<String, String> extractMetadataFromArchive(final String archiveType, final InputStream is) {
  final ArchiveStreamFactory archiveFactory = new ArchiveStreamFactory();
  try (ArchiveInputStream ais = archiveFactory.createArchiveInputStream(archiveType, is)) {
    ArchiveEntry entry = ais.getNextEntry();
    while (entry != null) {
      if (!entry.isDirectory() && DESCRIPTION_FILE_PATTERN.matcher(entry.getName()).matches()) {
        return parseDescriptionFile(ais);
      }
      entry = ais.getNextEntry();
    }
  }
  catch (ArchiveException | IOException e) {
    throw new RException(null, e);
  }
  throw new IllegalStateException("No metadata file found");
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-r,代码行数:17,代码来源:RDescriptionUtils.java

示例2: untar

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
public static List<String> untar(FileInputStream input, String targetPath) throws IOException {
    TarArchiveInputStream tarInput = new TarArchiveInputStream(input);
    ArrayList<String> result = new ArrayList<String>();

    ArchiveEntry  entry;
    while ((entry = tarInput.getNextEntry()) != null) {
        File destPath=new File(targetPath,entry.getName());
        result.add(destPath.getPath());
        if (!entry.isDirectory()) {
            FileOutputStream fout=new FileOutputStream(destPath);
            final byte[] buffer=new byte[8192];
            int n=0;
            while (-1 != (n=tarInput.read(buffer))) {
                fout.write(buffer,0,n);
            }
            fout.close();
        }
        else {
            destPath.mkdir();
        }
    }
    tarInput.close();
    return result;
}
 
开发者ID:BloomBooks,项目名称:BloomReader,代码行数:25,代码来源:IOUtilities.java

示例3: extractArchive

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private static void extractArchive(final File destination, final ArchiveInputStream archiveInputStream)
        throws IOException {
    final int BUFFER_SIZE = 8192;
    ArchiveEntry entry = archiveInputStream.getNextEntry();

    while (entry != null) {
        final File destinationFile = new File(destination, entry.getName());

        if (entry.isDirectory()) {
            destinationFile.mkdir();
        } else {
            destinationFile.getParentFile().mkdirs();
            try (final OutputStream fileOutputStream = new FileOutputStream(destinationFile)) {
                final byte[] buffer = new byte[BUFFER_SIZE];
                int bytesRead;

                while ((bytesRead = archiveInputStream.read(buffer)) != -1) {
                    fileOutputStream.write(buffer, 0, bytesRead);
                }
            }
        }

        entry = archiveInputStream.getNextEntry();
    }
}
 
开发者ID:awslabs,项目名称:aws-codepipeline-plugin-for-jenkins,代码行数:26,代码来源:ExtractionTools.java

示例4: extractTarOrGZToTempDir

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private boolean extractTarOrGZToTempDir(File nestedTempDir, File tar, String virtualPath)  {
    ArchiveInputStream tarInputStream = null;
    try {
        tarInputStream = getArchiveInputStream(tar);
        ArchiveEntry entry;
        while ((entry = tarInputStream.getNextEntry()) != null) {
            String fileName = entry.getName();
            if (!entry.isDirectory() && (isCandidateForSha1(virtualPath + "/" + fileName) || isCandidateForExtract(virtualPath + "/" + fileName))) {
                byte[] buffer = new byte[(int) entry.getSize()];
                tarInputStream.read(buffer, 0, buffer.length);
                FileUtils.writeByteArrayToFile(new File(nestedTempDir +"/" + fileName), buffer);
            }
        }

    } catch (IOException e) {
        listener.getLogger().println("Failed to extract archive: ["+tar.getAbsolutePath()+"]: " + e.getMessage());

    } finally {
        IOUtils.closeQuietly(tarInputStream);
    }

    return nestedTempDir.exists();
}
 
开发者ID:jenkinsci,项目名称:checkmarx-plugin,代码行数:24,代码来源:OSAScanner.java

示例5: ArchiveEntryImpl

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
public ArchiveEntryImpl(@Nonnull ArchiveEntry... entries) {
    if (entries.length == 0) {
        throw new IllegalArgumentException("Cannot create ZipEntryInfo without a ZipEntry!");
    }

    ArchiveEntry entry = entries[entries.length - 1];

    if (entries.length > 1) {
        StringBuilder fullPath = new StringBuilder();
        for (int i = 0; i < entries.length; i++) {
            fullPath.append(entries[i].getName());
            if (i != entries.length - 1) {
                fullPath.append(RepoPath.ARCHIVE_SEP).append('/');
            }
        }
        this.path = fullPath.toString();
    } else {
        this.path = entry.getName();
    }
    this.name = PathUtils.getFileName(entry.getName());
    this.time = entry.getLastModifiedDate().getTime();
    this.size = entry.getSize();
    this.directory = entry.isDirectory();
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:25,代码来源:ArchiveEntryImpl.java

示例6: addDicomFiles

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private static void addDicomFiles(ArchiveInputStream in, ArchiveOutput out, int[] counter) throws Throwable {
	ArchiveEntry ae = in.getNextEntry();
	while (ae != null) {
		if (!ae.isDirectory()) {
			String dicomFileName = String.format("%08d.dcm", counter[0] + 1);
			File tf = PluginTask.createTemporaryFile();
			try {
				StreamCopy.copy(in, tf);
				if (DicomFileCheck.isDicomFile(tf)) {
					out.add(DICOM_MIME_TYPE, dicomFileName, tf);
				}
			} finally {
				PluginTask.deleteTemporaryFile(tf);
			}
			counter[0] += 1;
		}
		ae = in.getNextEntry();
	}
}
 
开发者ID:uom-daris,项目名称:daris,代码行数:20,代码来源:SvcMyTardisDatasetImport.java

示例7: unpack

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
@SneakyThrows
public void unpack( Path archive, Path dest, ArchiveType type ) {
    switch( type ) {
        case TAR_GZ:
            try( TarArchiveInputStream tar = new TarArchiveInputStream( IoStreams.in( archive, GZIP ) ) ) {
                ArchiveEntry entry;
                while( ( entry = tar.getNextEntry() ) != null ) {
                    Path path = dest.resolve( entry.getName() );
                    if( entry.isDirectory() )
                        path.toFile().mkdirs();
                    else IoStreams.write( path, PLAIN, tar );
                }
                tar.close();
            }
    }
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:17,代码来源:Archiver.java

示例8: untar

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
public static void untar(
        InputStream tar,
        File parentDir
) throws IOException {
    TarArchiveInputStream tin = new TarArchiveInputStream(tar);
    ArchiveEntry e;
    while ((e = tin.getNextEntry()) != null) {
        File f = new File(parentDir, e.getName());
        f.setLastModified(e.getLastModifiedDate().getTime());
        f.getParentFile().mkdirs();
        if (e.isDirectory()) {
            f.mkdir();
            continue;
        }
        long size = e.getSize();
        checkFileSize(size);
        try (OutputStream out = new FileOutputStream(f)) {
            /* TarInputStream pretends each
               entry's EOF is the stream's EOF */
            IOUtils.copy(tin, out);
        }
    }
}
 
开发者ID:winstonli,项目名称:writelatex-git-bridge,代码行数:24,代码来源:Tar.java

示例9: unzip

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
/**
 * Unzips the zip file to the target directory.
 *
 * @param zipFile   the zip file to unzip
 * @param targetDir the directory to extract the zip file to
 *
 * @throws java.io.IOException if an I/O error occurs
 */
public static void unzip(final Path zipFile, final Path targetDir) throws IOException {
    final Path archive = getArchive(zipFile);

    try (ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(Files.newInputStream(archive)))) {
        ArchiveEntry entry;
        while ((entry = in.getNextEntry()) != null) {
            final Path extractTarget = targetDir.resolve(entry.getName());
            if (entry.isDirectory()) {
                Files.createDirectories(extractTarget);
            } else {
                Files.createDirectories(extractTarget.getParent());
                Files.copy(in, extractTarget);
            }
        }
    } catch (ArchiveException e) {
        throw new IOException(e);
    }
}
 
开发者ID:wildfly,项目名称:wildfly-maven-plugin,代码行数:27,代码来源:Archives.java

示例10: process

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
@Override
public void process(final Reader reader) {
    try (
            InputStream stream = new ReaderInputStream(reader,
                    Charset.defaultCharset());
            ArchiveInputStream tarStream = new TarArchiveInputStream(stream);
    ) {
        ArchiveEntry entry;
        while ((entry = tarStream.getNextEntry()) != null) {
            if (!entry.isDirectory()) {
                processFileEntry(tarStream);
            }
        }
    } catch (IOException e) {
        throw new MetafactureException(e);
    }
}
 
开发者ID:metafacture,项目名称:metafacture-core,代码行数:18,代码来源:TarReader.java

示例11: createArchiveEntry

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
/**
 * Creates a new {@link ArchiveEntry} in the given {@link ArchiveOutputStream}, and copies the given {@link File}
 * into the new entry.
 * 
 * @param file the file to add to the archive
 * @param entryName the name of the archive entry
 * @param archive the archive to write to
 * @throws IOException when an I/O error occurs during FileInputStream creation or during copying
 */
protected void createArchiveEntry(File file, String entryName, ArchiveOutputStream archive) throws IOException {
    ArchiveEntry entry = archive.createArchiveEntry(file, entryName);
    // TODO #23: read permission from file, write it to the ArchiveEntry
    archive.putArchiveEntry(entry);

    if (!entry.isDirectory()) {
        FileInputStream input = null;
        try {
            input = new FileInputStream(file);
            IOUtils.copy(input, archive);
        } finally {
            IOUtils.closeQuietly(input);
        }
    }

    archive.closeArchiveEntry();
}
 
开发者ID:thrau,项目名称:jarchivelib,代码行数:27,代码来源:CommonsArchiver.java

示例12: decompress

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private static void decompress(ArchiveInputStream archiveInputStream, File outputFile) throws IOException {
    int entries = 0;
    ArchiveEntry entry;
    while ((entry = archiveInputStream.getNextEntry()) != null) {
        log.log(LogLevel.DEBUG, "Unpacking " + entry.getName());
        File outFile = new File(outputFile, entry.getName());
        if (entry.isDirectory()) {
            if (!(outFile.exists() && outFile.isDirectory())) {
                log.log(LogLevel.DEBUG, "Creating dir: " + outFile.getAbsolutePath());
                if (!outFile.mkdirs()) {
                    log.log(LogLevel.WARNING, "Could not create dir " + entry.getName());
                }
            }
        } else {
            // Create parent dir if necessary
            File parent = new File(outFile.getParent());
            if (!parent.exists() && !parent.mkdirs()) {
                log.log(LogLevel.WARNING, "Could not create dir " + parent.getAbsolutePath());
            }
            FileOutputStream fos = new FileOutputStream(outFile);
            ByteStreams.copy(archiveInputStream, fos);
            fos.close();
        }
        entries++;
    }
    if (entries == 0) {
        log.log(LogLevel.WARNING, "Not able to read any entries from " + outputFile.getName());
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:30,代码来源:CompressedFileReference.java

示例13: decompressInto

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
private void decompressInto(File application) throws IOException {
    log.log(LogLevel.DEBUG, "Application is in " + application.getAbsolutePath());
    int entries = 0;
    ArchiveEntry entry;
    while ((entry = ais.getNextEntry()) != null) {
        log.log(LogLevel.DEBUG, "Unpacking " + entry.getName());
        File outFile = new File(application, entry.getName());
        // FIXME/TODO: write more tests that break this logic. I have a feeling it is not very robust.
        if (entry.isDirectory()) {
            if (!(outFile.exists() && outFile.isDirectory())) {
                log.log(LogLevel.DEBUG, "Creating dir: " + outFile.getAbsolutePath());
                boolean res = outFile.mkdirs();
                if (!res) {
                    log.log(LogLevel.WARNING, "Could not create dir " + entry.getName());
                }
            }
        } else {
            log.log(LogLevel.DEBUG, "Creating output file: " + outFile.getAbsolutePath());

            // Create parent dir if necessary
            String parent = outFile.getParent();
            new File(parent).mkdirs();

            FileOutputStream fos = new FileOutputStream(outFile);
            ByteStreams.copy(ais, fos);
            fos.close();
        }
        entries++;
    }
    if (entries == 0) {
        log.log(LogLevel.WARNING, "Not able to read any entries from " + application.getName());
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:34,代码来源:CompressedApplicationInputStream.java

示例14: testHasNextForOneEntry

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
@Test
public void testHasNextForOneEntry(@Mocked final ArchiveInputStream ain, @Mocked final ArchiveEntry entry) throws Exception {
    new NonStrictExpectations() {{
        ain.getNextEntry(); result = entry; result = null;
        entry.isDirectory(); result = false;
    }};
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is a item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:13,代码来源:TestArchiveInputStreamIterator.java

示例15: testHasNextForTwoEntries

import org.apache.commons.compress.archivers.ArchiveEntry; //导入方法依赖的package包/类
@Test
public void testHasNextForTwoEntries(@Mocked final ArchiveInputStream ain, @Mocked final ArchiveEntry entry) throws Exception {
    new NonStrictExpectations() {{
        ain.getNextEntry(); result = entry; result = entry; result = null;
        entry.isDirectory(); result = false;
    }};
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is 1st item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertTrue("Verify there is 2nd item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", (InputStream)ain, it.next());
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:15,代码来源:TestArchiveInputStreamIterator.java


注:本文中的org.apache.commons.compress.archivers.ArchiveEntry.isDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。