private boolean isDirectory() { return currEntry != null && currEntry.isDirectory(); } }
Resource r = new TarResource(src, entry); String name = entry.getName(); if (entry.isDirectory()) { name = trimSeparator(name); dirEntries.put(name, r);
if (entry.isDirectory()) { this.currSize = 0; } else {
/** * @since Ant 1.7 */ private void expandStream(String name, InputStream stream, File dir) throws IOException { try (TarInputStream tis = new TarInputStream( compression.decompress(name, new BufferedInputStream(stream)), getEncoding())) { log("Expanding: " + name + " into " + dir, Project.MSG_INFO); boolean empty = true; FileNameMapper mapper = getMapper(); TarEntry te; while ((te = tis.getNextEntry()) != null) { empty = false; extractFile(FileUtils.getFileUtils(), null, dir, tis, te.getName(), te.getModTime(), te.isDirectory(), mapper); } if (empty && getFailOnEmptyArchive()) { throw new BuildException("archive '%s' is empty", name); } log("expand complete", Project.MSG_VERBOSE); } }
if (entry.isDirectory()) { currSize = 0; } else {
private void setEntry(TarEntry e) { if (e == null) { setExists(false); return; } setName(e.getName()); setExists(true); setLastModified(e.getModTime().getTime()); setDirectory(e.isDirectory()); setSize(e.getSize()); setMode(e.getMode()); userName = e.getUserName(); groupName = e.getGroupName(); uid = e.getLongUserId(); gid = e.getLongGroupId(); }
if (isDirectory() && !name.endsWith("/")) { name += "/";
public boolean isDirectory() { return entry.isDirectory(); }
public RelativePath getRelativePath() { return new RelativePath(!entry.isDirectory(), entry.getName().split("/")); }
public static void main(String[] args) throws FileNotFoundException, IOException { File destFolder = new File("myfiles"); File tarFile = new File("test.tar"); TarInputStream tis = new TarInputStream(new BufferedInputStream(new FileInputStream(tarFile))); TarEntry entry; destFolder.mkdirs(); while ((entry = tis.getNextEntry()) != null) { int count; byte data[] = new byte[2048]; File f = new File(destFolder, entry.getName()); if (entry.isDirectory()) { f.mkdirs(); } else { f.getParentFile().mkdirs(); try (BufferedOutputStream dest = new BufferedOutputStream(new FileOutputStream(f))) { while ((count = tis.read(data)) != -1) { dest.write(data, 0, count); } } } } tis.close(); }
File destPath = new File(outputDirectory + File.separator + tarEntry.getName()); if (tarEntry.isDirectory()) { destPath.mkdirs(); } else {
public static void decompressTarGz(File tarGzFile, File destDir) { try { IOUtils.forceMkdir(destDir); TarInputStream tin = new TarInputStream(new GZIPInputStream(new FileInputStream(tarGzFile))); TarEntry tarEntry = tin.getNextEntry(); while (tarEntry != null) { File destPath = new File(destDir, tarEntry.getName()); if (tarEntry.isDirectory()) { IOUtils.forceMkdir(destPath); } else { FileOutputStream fout = new FileOutputStream(destPath); tin.copyEntryContents(fout); fout.close(); } tarEntry = tin.getNextEntry(); } tin.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
if (tarEntry.isDirectory()) { destPath.mkdirs();
private void visitImpl(FileVisitor visitor, InputStream inputStream) throws IOException { AtomicBoolean stopFlag = new AtomicBoolean(); NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream); TarEntry entry; File expandedDir = getExpandedDir(); while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) { if (entry.isDirectory()) { visitor.visitDir(new DetailsImpl(resource, expandedDir, entry, tar, stopFlag, chmod)); } else { visitor.visitFile(new DetailsImpl(resource, expandedDir, entry, tar, stopFlag, chmod)); } } }
private void untarTo(InputStream source, File path) throws IOException { TarInputStream is = new TarInputStream(source); TarEntry entry = null; try { while (null != (entry = is.getNextEntry())) { File target = new File(path, entry.getName()); ensureParentDirectory(target); if (entry.isDirectory()) { target.mkdirs(); } else { if (target.exists()) { target.delete(); } FileOutputStream os = new FileOutputStream(target); try { is.copyEntryContents(os); } finally { finallyClose(os); } } } } finally { finallyClose(is); } } public String getName() {
/** * Reads from a tar stream and stores obtained files to the base dir. */ private static void readFromTar(String name, File baseDir, InputStream in) throws IOException { TarInputStream t = new TarInputStream(in); try { TarEntry te; while ((te = t.getNextEntry()) != null) { File f = new File(baseDir,te.getName()); if(te.isDirectory()) { f.mkdirs(); } else { File parent = f.getParentFile(); if (parent != null) parent.mkdirs(); IOUtils.copy(t,f); f.setLastModified(te.getModTime().getTime()); int mode = te.getMode()&0777; if(mode!=0 && !Functions.isWindows()) // be defensive Util.chmod(f, mode); } } } catch(IOException e) { throw new IOException2("Failed to extract "+name,e); } finally { t.close(); } }
/** * Reads from a tar stream and stores obtained files to the base dir. */ private static void readFromTar(String name, File baseDir, InputStream in) throws IOException { TarInputStream t = new TarInputStream(in); try { TarEntry te; while ((te = t.getNextEntry()) != null) { File f = new File(baseDir,te.getName()); if(te.isDirectory()) { f.mkdirs(); } else { File parent = f.getParentFile(); if (parent != null) parent.mkdirs(); IOUtils.copy(t,f); f.setLastModified(te.getModTime().getTime()); int mode = te.getMode()&0777; if(mode!=0 && !Functions.isWindows()) // be defensive _chmod(f,mode); } } } catch(IOException e) { throw new IOException2("Failed to extract "+name,e); } finally { t.close(); } }
while ((te = t.getNextEntry()) != null) { File f = new File(baseDir, te.getName()); if (te.isDirectory()) { f.mkdirs(); } else {
/** * Reads from a tar stream and stores obtained files to the base dir. */ private static void readFromTar(String name, File baseDir, InputStream in) throws IOException { TarInputStream t = new TarInputStream(in); try { TarEntry te; while ((te = t.getNextEntry()) != null) { File f = new File(baseDir,te.getName()); if(te.isDirectory()) { f.mkdirs(); } else { File parent = f.getParentFile(); if (parent != null) parent.mkdirs(); IOUtils.copy(t,f); f.setLastModified(te.getModTime().getTime()); int mode = te.getMode()&0777; if(mode!=0 && !Functions.isWindows()) // be defensive _chmod(f,mode); } } } catch(IOException e) { throw new IOException2("Failed to extract "+name,e); } finally { t.close(); } }
private void processTar(InputStream is) throws Exception { TarInputStream inputStream = new TarInputStream(is); try { TarEntry inputEntry = null; do { inputEntry = inputStream.getNextEntry(); if (inputEntry != null && !inputEntry.isDirectory()) { processEntry(inputEntry.getName(), inputStream, (int) inputEntry.getSize()); } } while (inputEntry != null && !abort); } finally { if (inputStream != null) { inputStream.close(); } } }