本文整理匯總了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");
}
示例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;
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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());
}
}
示例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());
}
}
示例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());
}
示例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());
}