use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project incubator-systemml by apache.
the class ValidateLicAndNotice method getFilesFromTGZ.
/**
* This will return the list of files from tgz file.
*
* @param tgzFileName is the name of tgz file from which list of files with specified file extension will be returned.
* @param fileExt is the file extension to be used to get list of files to be returned.
* @return Returns list of files having specified extension from tgz file.
*/
public static List<String> getFilesFromTGZ(String tgzFileName, String fileExt) {
TarArchiveInputStream tarIn = null;
try {
tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tgzFileName))));
} catch (Exception e) {
Utility.debugPrint(Constants.DEBUG_ERROR, "Exception in unzipping tar file: " + e);
return null;
}
List<String> files = new ArrayList<String>();
try {
TarArchiveEntry tarEntry = null;
while ((tarEntry = tarIn.getNextTarEntry()) != null) {
if (tarEntry.getName().endsWith("." + fileExt)) {
int iPos = tarEntry.getName().lastIndexOf("/");
if (iPos == 0)
--iPos;
String strFileName = tarEntry.getName().substring(iPos + 1);
files.add(strFileName);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return (files);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project ignite by apache.
the class IgniteHadoopTestSuite method download.
/**
* Downloads and extracts an Apache product.
*
* @param appName Name of application for log messages.
* @param homeVariable Pointer to home directory of the component.
* @param downloadPath Relative download path of tar package.
* @param destName Local directory name to install component.
* @throws Exception If failed.
*/
private static void download(String appName, String homeVariable, String downloadPath, String destName) throws Exception {
String homeVal = IgniteSystemProperties.getString(homeVariable);
if (!F.isEmpty(homeVal) && new File(homeVal).isDirectory()) {
X.println(homeVariable + " is set to: " + homeVal);
return;
}
List<String> urls = F.asList("http://archive.apache.org/dist/", "http://apache-mirror.rbc.ru/pub/apache/", "http://www.eu.apache.org/dist/", "http://www.us.apache.org/dist/");
String tmpPath = System.getProperty("java.io.tmpdir");
X.println("tmp: " + tmpPath);
final File install = new File(tmpPath + File.separatorChar + "__hadoop");
final File home = new File(install, destName);
X.println("Setting " + homeVariable + " to " + home.getAbsolutePath());
System.setProperty(homeVariable, home.getAbsolutePath());
final File successFile = new File(home, "__success");
if (home.exists()) {
if (successFile.exists()) {
X.println(appName + " distribution already exists.");
return;
}
X.println(appName + " distribution is invalid and it will be deleted.");
if (!U.delete(home))
throw new IOException("Failed to delete directory: " + home.getAbsolutePath());
}
for (String url : urls) {
if (!(install.exists() || install.mkdirs()))
throw new IOException("Failed to create directory: " + install.getAbsolutePath());
URL u = new URL(url + downloadPath);
X.println("Attempting to download from: " + u);
try {
URLConnection c = u.openConnection();
c.connect();
try (TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(c.getInputStream(), 32 * 1024)))) {
TarArchiveEntry entry;
while ((entry = in.getNextTarEntry()) != null) {
File dest = new File(install, entry.getName());
if (entry.isDirectory()) {
if (!dest.mkdirs())
throw new IllegalStateException();
} else if (entry.isSymbolicLink()) {
// Important: in Hadoop installation there are symlinks, we need to create them:
Path theLinkItself = Paths.get(install.getAbsolutePath(), entry.getName());
Path linkTarget = Paths.get(entry.getLinkName());
Files.createSymbolicLink(theLinkItself, linkTarget);
} else {
File parent = dest.getParentFile();
if (!(parent.exists() || parent.mkdirs()))
throw new IllegalStateException();
X.print(" [" + dest);
try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest, false), 128 * 1024)) {
U.copy(in, out);
out.flush();
}
Files.setPosixFilePermissions(dest.toPath(), modeToPermissionSet(entry.getMode()));
X.println("]");
}
}
}
if (successFile.createNewFile())
return;
} catch (Exception e) {
e.printStackTrace();
U.delete(home);
}
}
throw new IllegalStateException("Failed to install " + appName + ".");
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project knime-core by knime.
the class ExtractTarGz method untar.
private static void untar(final InputStream in, final File destDir) throws IOException {
try (TarArchiveInputStream tarInS = new TarArchiveInputStream(in)) {
TarArchiveEntry entry;
while ((entry = tarInS.getNextTarEntry()) != null) {
String name = entry.getName();
File destFile = new File(destDir, name);
if (entry.isSymbolicLink()) {
Files.createSymbolicLink(destFile.toPath(), Paths.get(entry.getLinkName()));
} else if (entry.isDirectory()) {
destFile.mkdirs();
chmod(destFile, entry.getMode());
} else {
try (FileOutputStream out = new FileOutputStream(destFile)) {
long size = entry.getSize();
IOUtils.copyLarge(tarInS, out, 0, size);
}
chmod(destFile, entry.getMode());
}
}
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project AmazeFileManager by TeamAmaze.
the class GzipHelperTask method addElements.
@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
TarArchiveInputStream tarInputStream = null;
try {
tarInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(filePath)));
TarArchiveEntry entry;
while ((entry = tarInputStream.getNextTarEntry()) != null) {
String name = entry.getName();
if (name.endsWith(SEPARATOR))
name = name.substring(0, name.length() - 1);
boolean isInBaseDir = relativePath.equals("") && !name.contains(SEPARATOR);
boolean isInRelativeDir = name.contains(SEPARATOR) && name.substring(0, name.lastIndexOf(SEPARATOR)).equals(relativePath);
if (isInBaseDir || isInRelativeDir) {
elements.add(new CompressedObjectParcelable(entry.getName(), entry.getLastModifiedDate().getTime(), entry.getSize(), entry.isDirectory()));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project AmazeFileManager by TeamAmaze.
the class TarHelperTask method addElements.
@Override
void addElements(ArrayList<CompressedObjectParcelable> elements) {
TarArchiveInputStream tarInputStream = null;
try {
tarInputStream = new TarArchiveInputStream(new FileInputStream(filePath));
TarArchiveEntry entry;
while ((entry = tarInputStream.getNextTarEntry()) != null) {
String name = entry.getName();
if (name.endsWith(SEPARATOR))
name = name.substring(0, name.length() - 1);
boolean isInBaseDir = relativePath.equals("") && !name.contains(SEPARATOR);
boolean isInRelativeDir = name.contains(SEPARATOR) && name.substring(0, name.lastIndexOf(SEPARATOR)).equals(relativePath);
if (isInBaseDir || isInRelativeDir) {
elements.add(new CompressedObjectParcelable(entry.getName(), entry.getLastModifiedDate().getTime(), entry.getSize(), entry.isDirectory()));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations