/** * Determine if the given entry is a descendant of this entry. * Descendancy is determined by the name of the descendant * starting with this entry's name. * * @param desc Entry to be checked as a descendant of this. * @return True if entry is a descendant of this. */ public boolean isDescendent(TarEntry desc) { return desc.getName().startsWith(getName()); }
/** * Hashcodes are based on entry names. * * @return the entry hashcode */ @Override public int hashCode() { return getName().hashCode(); }
/** * Check if this is a "normal file". * @return <i>true</i> if it is a 'normal' file */ public boolean isFile() { return file != null ? file.isFile() : linkFlag == LF_OLDNORM || linkFlag == LF_NORMAL || !getName().endsWith("/"); }
/** * Return whether or not this entry represents a directory. * * @return True if this entry is a directory. */ public boolean isDirectory() { if (file != null) { return file.isDirectory(); } return linkFlag == LF_DIR || getName().endsWith("/"); }
if (entry.getName().length() >= TarConstants.NAMELEN) { TarConstants.LF_GNUTYPE_LONGNAME); byte[] name = entry.getName().getBytes("UTF-8"); longLinkEntry.setSize(name.length + 1); putNextEntry(longLinkEntry); closeEntry(); } else if (longFileMode != LONGFILE_TRUNCATE) { throw new RuntimeException("file name '" + entry.getName() + "' is too long ( > " + TarConstants.NAMELEN + " bytes)"); this.currSize = entry.getSize(); currName = entry.getName();
@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 OGKTextField(QueryBuilder.FULL, new IteratorReader(names))); } }
/** * fetches information from the named entry inside the archive. */ @Override protected void fetchEntry() { Resource archive = getArchive(); try (TarInputStream i = new TarInputStream(archive.getInputStream())) { TarEntry te = null; while ((te = i.getNextEntry()) != null) { if (te.getName().equals(getName())) { setEntry(te); return; } } } catch (IOException e) { log(e.getMessage(), Project.MSG_DEBUG); throw new BuildException(e); } setEntry(null); }
while ((entry = ti.getNextEntry()) != null) { Resource r = new TarResource(src, entry); String name = entry.getName(); if (entry.isDirectory()) { name = trimSeparator(name);
/** * @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); } }
/** * Return an InputStream for reading the contents of this Resource. * @return an InputStream object. * @throws IOException if the tar file cannot be opened, * or the entry cannot be read. */ @Override public InputStream getInputStream() throws IOException { if (isReference()) { return getCheckedRef().getInputStream(); } Resource archive = getArchive(); final TarInputStream i = new TarInputStream(archive.getInputStream()); TarEntry te; while ((te = i.getNextEntry()) != null) { if (te.getName().equals(getName())) { return i; } } FileUtils.close(i); throw new BuildException("no entry " + getName() + " in " + getArchive()); }
final String entryName = entry.getName(); boolean paxHeaderContainsPath = handleLongName(entry, entryName, paxHeaders, "path", TarConstants.LF_GNUTYPE_LONGNAME, "file name");
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(); }
public File getFile() { if (file == null) { file = new File(expandedDir, entry.getName()); if (!file.exists()) { copyTo(file); } } return file; }
public String getDisplayName() { return String.format("tar entry %s!%s", resource.getDisplayName(), entry.getName()); }
public RelativePath getRelativePath() { return new RelativePath(!entry.isDirectory(), entry.getName().split("/")); }
String tarFile = "c:/test/test.tar"; // Create a TarInputStream TarInputStream tis = new TarInputStream(new BufferedInputStream(new FileInputStream(tarFile))); TarEntry entry; while((entry = tis.getNextEntry()) != null) { System.out.println(entry.getName()); // The following might not be required, but arguably does // additionally check the content of the archive. int count; byte data[] = new byte[2048]; while((count = tis.read(data)) != -1) { } } tis.close();
@Override public ArchiveEntry getNextEntry(boolean calculateSize) { try { TarEntry entry = in.getNextEntry(); if (entry != null) { return new DefaultArchiveEntry(entry.getName(), entry.getSize(), entry.getModTime().getTime()); } } catch (IOException e) { LOGGER.error("Failed reading entries in file " + file.getAbsolutePath(), e); } return null; }