本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveEntry.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveEntry.isDirectory方法的具体用法?Java TarArchiveEntry.isDirectory怎么用?Java TarArchiveEntry.isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveEntry
的用法示例。
在下文中一共展示了TarArchiveEntry.isDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDirectory
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* @deprecated see {@link PLP5ProjectParser#parse(File)}
*/
private static void addDirectory(TarArchiveInputStream plpInputStream,
TarArchiveEntry entry, File assembleFile, List<ASMFile> projectFiles)
throws IOException
{
for (TarArchiveEntry subEntry : entry.getDirectoryEntries())
{
if (!subEntry.isDirectory())
{
addFile(plpInputStream, subEntry, assembleFile, projectFiles);
}
else
{
addDirectory(plpInputStream, subEntry, assembleFile, projectFiles);
}
}
}
示例2: extractTar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static void extractTar(String dataIn, String dataOut) throws IOException {
try (TarArchiveInputStream inStream = new TarArchiveInputStream(
new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(dataIn))))) {
TarArchiveEntry tarFile;
while ((tarFile = (TarArchiveEntry) inStream.getNextEntry()) != null) {
if (tarFile.isDirectory()) {
new File(dataOut + tarFile.getName()).mkdirs();
} else {
int count;
byte data[] = new byte[BUFFER_SIZE];
FileOutputStream fileInStream = new FileOutputStream(dataOut + tarFile.getName());
BufferedOutputStream outStream= new BufferedOutputStream(fileInStream, BUFFER_SIZE);
while ((count = inStream.read(data, 0, BUFFER_SIZE)) != -1) {
outStream.write(data, 0, count);
}
}
}
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:22,代码来源:DL4JSentimentAnalysisExample.java
示例3: extract
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void extract(File projectFile) throws IOException
{
try (FileInputStream fileStream = new FileInputStream(projectFile);
TarArchiveInputStream inputStream = new TarArchiveInputStream(fileStream))
{
this.inputStream = inputStream;
// TODO: verify the first entry is not relevant
TarArchiveEntry entry = inputStream.getNextTarEntry();
while ((entry = inputStream.getNextTarEntry()) != null)
{
if (!entry.isDirectory())
{
addFile(entry);
}
else
{
addDirectory(entry);
}
}
}
catch (IOException exception)
{
throw exception;
}
}
示例4: dearchive
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* 文件 解归档
*
* @param destFile
* 目标文件
* @param tais
* ZipInputStream
* @throws Exception
*/
private static void dearchive(File destFile, TarArchiveInputStream tais)
throws Exception {
TarArchiveEntry entry = null;
while ((entry = tais.getNextTarEntry()) != null) {
// 文件
String dir = destFile.getPath() + File.separator + entry.getName();
File dirFile = new File(dir);
// 文件检查
fileProber(dirFile);
if (entry.isDirectory()) {
dirFile.mkdirs();
} else {
dearchiveFile(dirFile, tais);
}
}
}
示例5: unpackTarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static void unpackTarArchiveEntry(TarArchiveInputStream tarStream, TarArchiveEntry entry, File outputDirectory) throws IOException {
String fileName = entry.getName().substring(entry.getName().indexOf("/"), entry.getName().length());
File outputFile = new File(outputDirectory,fileName);
if (entry.isDirectory()) {
if (!outputFile.exists()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
}
}
unpackTar(tarStream, entry.getDirectoryEntries(), outputFile);
return;
}
OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(tarStream, outputFileStream);
outputFileStream.close();
}
示例6: unTgz
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static List<String> unTgz(File tarFile, File directory) throws IOException {
List<String> result = new ArrayList<>();
try (TarArchiveInputStream in = new TarArchiveInputStream(
new GzipCompressorInputStream(new FileInputStream(tarFile)))) {
TarArchiveEntry entry = in.getNextTarEntry();
while (entry != null) {
if (entry.isDirectory()) {
entry = in.getNextTarEntry();
continue;
}
File curfile = new File(directory, entry.getName());
File parent = curfile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
try (OutputStream out = new FileOutputStream(curfile)) {
IOUtils.copy(in, out);
}
result.add(entry.getName());
entry = in.getNextTarEntry();
}
}
return result;
}
示例7: untarFile
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static void untarFile(File file) throws IOException {
FileInputStream fileInputStream = null;
String currentDir = file.getParent();
try {
fileInputStream = new FileInputStream(file);
GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gzipInputStream);
TarArchiveEntry tarArchiveEntry;
while (null != (tarArchiveEntry = tarArchiveInputStream.getNextTarEntry())) {
if (tarArchiveEntry.isDirectory()) {
FileUtils.forceMkdir(new File(currentDir + File.separator + tarArchiveEntry.getName()));
} else {
byte[] content = new byte[(int) tarArchiveEntry.getSize()];
int offset = 0;
tarArchiveInputStream.read(content, offset, content.length - offset);
FileOutputStream outputFile = new FileOutputStream(currentDir + File.separator + tarArchiveEntry.getName());
org.apache.commons.io.IOUtils.write(content, outputFile);
outputFile.close();
}
}
} catch (FileNotFoundException e) {
throw new IOException(e.getStackTrace().toString());
}
}
示例8: unarchive
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
@Override
public void unarchive(InputStream source, File target) {
try (TarArchiveInputStream tIn = new TarArchiveInputStream(source)) {
TarArchiveEntry entry = tIn.getNextTarEntry();
while (entry != null) {
if (entry.isDirectory()) {
entry = tIn.getNextTarEntry();
continue;
}
File curfile = new File(target, entry.getName());
File parent = curfile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
try (OutputStream out = new FileOutputStream(curfile)) {
IOUtils.copy(tIn, out);
entry = tIn.getNextTarEntry();
}
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例9: extract
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
static void extract(InputStream in, Path destination) throws IOException {
try (
final BufferedInputStream bufferedInputStream = new BufferedInputStream(in);
final GzipCompressorInputStream gzipInputStream =
new GzipCompressorInputStream(bufferedInputStream);
final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzipInputStream)
) {
final String destinationAbsolutePath = destination.toFile().getAbsolutePath();
TarArchiveEntry entry;
while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) {
if (entry.isDirectory()) {
File f = Paths.get(destinationAbsolutePath, entry.getName()).toFile();
f.mkdirs();
} else {
Path fileDestinationPath = Paths.get(destinationAbsolutePath, entry.getName());
Files.copy(tarInputStream, fileDestinationPath, StandardCopyOption.REPLACE_EXISTING);
}
}
}
}
示例10: unzipTAREntry
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void unzipTAREntry(@NonNull final Context context, TarArchiveInputStream zipFileStream, TarArchiveEntry entry,
String outputDir) throws IOException {
String name = entry.getName();
if (entry.isDirectory()) {
FileUtil.mkdir(new File(outputDir, name), context);
return;
}
File outputFile = new File(outputDir, name);
if (!outputFile.getParentFile().exists()) {
FileUtil.mkdir(outputFile.getParentFile(), context);
}
BufferedOutputStream outputStream = new BufferedOutputStream(
FileUtil.getOutputStream(outputFile, context, entry.getRealSize()));
try {
int len;
byte buf[] = new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
while ((len = zipFileStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
ServiceWatcherUtil.POSITION += len;
}
} finally {
outputStream.close();
}
}
示例11: extractTarBallEntry
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* Private Helper Method to Perform Extract for a Tarball Entry.
*
* @param tarArchiveInputStream
* @param entry
* @param outputDirectory
* @throws java.io.IOException
*/
private static void extractTarBallEntry(TarArchiveInputStream tarArchiveInputStream, TarArchiveEntry entry, File outputDirectory)
throws IOException {
final File outputFile = new File(outputDirectory, entry.getName());
if (entry.isDirectory()) {
if (!outputFile.exists()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
}
}
} else {
final OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(tarArchiveInputStream, outputFileStream);
outputFileStream.close();
}
}
示例12: untarGzip
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static void untarGzip(final InputStream inputStream, final File outputDir){
try(TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(
new GZIPInputStream(
inputStream))){
TarArchiveEntry entry;
while((entry = tarArchiveInputStream.getNextTarEntry()) != null){
final File outputFile = new File(outputDir, entry.getName());
if(entry.isFile()){
final OutputStream outputStream = new FileOutputStream(outputFile);
IOUtils.copy(tarArchiveInputStream, outputStream);
outputStream.close();
}
else if (entry.isDirectory()){
if(!outputFile.exists()){
outputFile.mkdirs();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: extractTar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void extractTar( String tarFilePath, String outputDirPath ) {
TarArchiveEntry entry = null;
try (TarArchiveInputStream tis = new TarArchiveInputStream(new FileInputStream(tarFilePath))) {
while ( (entry = (TarArchiveEntry) tis.getNextEntry()) != null) {
if (log.isDebugEnabled()) {
log.debug("Extracting " + entry.getName());
}
File entryDestination = new File(outputDirPath, entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
OutputStream out = new BufferedOutputStream(new FileOutputStream(entryDestination));
IoUtils.copyStream(tis, out, false, true);
}
if (OperatingSystemType.getCurrentOsType() != OperatingSystemType.WINDOWS) {//check if the OS is UNIX
// set file/dir permissions, after it is created
Files.setPosixFilePermissions(entryDestination.getCanonicalFile().toPath(),
getPosixFilePermission(entry.getMode()));
}
}
} catch (Exception e) {
String errorMsg = null;
if (entry != null) {
errorMsg = "Unable to untar " + entry.getName() + " from " + tarFilePath
+ ".Target directory '" + outputDirPath + "' is in inconsistent state.";
} else {
errorMsg = "Could not read data from " + tarFilePath;
}
throw new FileSystemOperationException(errorMsg, e);
}
}
示例14: extractTarGZip
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void extractTarGZip( String tarGzipFilePath, String outputDirPath ) {
TarArchiveEntry entry = null;
try (TarArchiveInputStream tis = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarGzipFilePath)))) {
while ( (entry = (TarArchiveEntry) tis.getNextEntry()) != null) {
if (log.isDebugEnabled()) {
log.debug("Extracting " + entry.getName());
}
File entryDestination = new File(outputDirPath, entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
OutputStream out = new BufferedOutputStream(new FileOutputStream(entryDestination));
IoUtils.copyStream(tis, out, false, true);
}
if (OperatingSystemType.getCurrentOsType() != OperatingSystemType.WINDOWS) {//check if the OS is UNIX
// set file/dir permissions, after it is created
Files.setPosixFilePermissions(entryDestination.getCanonicalFile().toPath(),
getPosixFilePermission(entry.getMode()));
}
}
} catch (Exception e) {
String errorMsg = null;
if (entry != null) {
errorMsg = "Unable to gunzip " + entry.getName() + " from " + tarGzipFilePath
+ ".Target directory '" + outputDirPath + "' is in inconsistent state.";
} else {
errorMsg = "Could not read data from " + tarGzipFilePath;
}
throw new FileSystemOperationException(errorMsg, e);
}
}
示例15: openProject
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* @deprecated replaced by {@link PLP5ProjectParser#parse(File)}
*/
public static List<ASMFile> openProject(File projectFile)
{
try (TarArchiveInputStream plpInputStream = new TarArchiveInputStream(
new FileInputStream(projectFile)))
{
List<ASMFile> projectFiles = new ArrayList<>();
TarArchiveEntry entry = plpInputStream.getNextTarEntry();
while ((entry = plpInputStream.getNextTarEntry()) != null)
{
if (!entry.isDirectory())
{
addFile(plpInputStream, entry, projectFile, projectFiles);
}
else
{
addDirectory(plpInputStream, entry, projectFile, projectFiles);
}
}
return projectFiles;
}
catch (IOException e)
{
e.printStackTrace();
System.exit(-1);
}
return null;
}