use of org.apache.tools.tar.TarEntry in project hadoop by apache.
the class TestFileUtil method testUnTar.
@Test(timeout = 30000)
public void testUnTar() throws IOException {
setupDirs();
// make a simple tar:
final File simpleTar = new File(del, FILE);
OutputStream os = new FileOutputStream(simpleTar);
TarOutputStream tos = new TarOutputStream(os);
try {
TarEntry te = new TarEntry("/bar/foo");
byte[] data = "some-content".getBytes("UTF-8");
te.setSize(data.length);
tos.putNextEntry(te);
tos.write(data);
tos.closeEntry();
tos.flush();
tos.finish();
} finally {
tos.close();
}
// successfully untar it into an existing dir:
FileUtil.unTar(simpleTar, tmp);
// check result:
assertTrue(new File(tmp, "/bar/foo").exists());
assertEquals(12, new File(tmp, "/bar/foo").length());
final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
regularFile.createNewFile();
assertTrue(regularFile.exists());
try {
FileUtil.unTar(simpleTar, regularFile);
assertTrue("An IOException expected.", false);
} catch (IOException ioe) {
// okay
}
}
use of org.apache.tools.tar.TarEntry in project OpenRefine by OpenRefine.
the class FileProjectManager method untar.
protected void untar(File destDir, InputStream inputStream) throws IOException {
TarInputStream tin = new TarInputStream(inputStream);
TarEntry tarEntry = null;
while ((tarEntry = tin.getNextEntry()) != null) {
File destEntry = new File(destDir, tarEntry.getName());
File parent = destEntry.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
if (tarEntry.isDirectory()) {
destEntry.mkdirs();
} else {
FileOutputStream fout = new FileOutputStream(destEntry);
try {
tin.copyEntryContents(fout);
} finally {
fout.close();
}
}
}
tin.close();
}
use of org.apache.tools.tar.TarEntry in project OpenRefine by OpenRefine.
the class FileProjectManager method tarDir.
protected void tarDir(String relative, File dir, TarOutputStream tos) throws IOException {
File[] files = dir.listFiles();
for (File file : files) {
if (!file.isHidden()) {
String path = relative + file.getName();
if (file.isDirectory()) {
tarDir(path + File.separator, file, tos);
} else {
TarEntry entry = new TarEntry(path);
entry.setMode(TarEntry.DEFAULT_FILE_MODE);
entry.setSize(file.length());
entry.setModTime(file.lastModified());
tos.putNextEntry(entry);
copyFile(file, tos);
tos.closeEntry();
}
}
}
}
use of org.apache.tools.tar.TarEntry in project OpenGrok by OpenGrok.
the class TarAnalyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
ArrayList<String> names = new ArrayList<>();
try (TarInputStream zis = new TarInputStream(src.getStream())) {
TarEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String name = entry.getName();
names.add(name);
if (xrefOut != null) {
Util.htmlize(name, xrefOut);
xrefOut.append("<br/>");
}
}
}
doc.add(new TextField("full", new IteratorReader(names)));
}
use of org.apache.tools.tar.TarEntry in project hudson-2.x by hudson.
the class TarArchiver method visitSymlink.
@Override
public void visitSymlink(File link, String target, String relativePath) throws IOException {
TarEntry e = new TarEntry(relativePath, LF_SYMLINK);
try {
StringBuffer linkName = (StringBuffer) LINKNAME_FIELD.get(e);
linkName.setLength(0);
linkName.append(target);
} catch (IllegalAccessException x) {
throw new IOException2("Failed to set linkName", x);
}
tar.putNextEntry(e);
entriesWritten++;
}
Aggregations