/** * If this entry represents a file, and the file is a directory, return * an array of TarEntries for this entry's children. * * @return An array of TarEntry's for this entry's children. */ public TarEntry[] getDirectoryEntries() { if (file == null || !file.isDirectory()) { return new TarEntry[0]; } String[] list = file.list(); TarEntry[] result = new TarEntry[list.length]; for (int i = 0; i < list.length; ++i) { result[i] = new TarEntry(new File(file, list[i])); } return result; }
TarEntry pex = new TarEntry(name, TarConstants.LF_PAX_EXTENDED_HEADER_LC); transferModTime(entry, pex);
this.currEntry = null; } else { this.currEntry = new TarEntry(headerBuf);
new TarEntry(TarConstants.GNU_LONGLINK, linkType);
TarEntry longLinkEntry = new TarEntry(TarConstants.GNU_LONGLINK, TarConstants.LF_GNUTYPE_LONGNAME);
currEntry = new TarEntry(headerBuf, encoding); } catch (IllegalArgumentException e) { throw new IOException("Error detected parsing the header", e);
final TarEntry te = new TarEntry(vPath, preserveLeadingSlashes); te.setModTime(r.getLastModified());
TarEntry tarEntry = new TarEntry(new File("<path to file>"),"MyFolder/MyFile.zip");
@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++; }
@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++; }
@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++; }
@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++; }
public void storeRecord(String path, InputStream data, long size) throws IOException { path = path.replaceAll("/+", "/").replace("\\", "/"); if(exportedFiles.contains(path)) { log.debug(String.format("Skipping already stored entry '%s'", path)); return; } TarEntry ze = new TarEntry(path); ze.setSize(size); outputStream.putNextEntry(ze); copyStream(data, outputStream, true, false); outputStream.closeEntry(); exportedFiles.add(path); }
// Output file stream FileOutputStream dest = new FileOutputStream( "c:/test/test.tar" ); // Create a TarOutputStream TarOutputStream out = new TarOutputStream( new BufferedOutputStream( dest ) ); // Files to tar File[] filesToTar=new File[2]; filesToTar[0]=new File("c:/test/myfile1.txt"); filesToTar[1]=new File("c:/test/myfile2.txt"); for(File f:filesToTar){ out.putNextEntry(new TarEntry(f, f.getName())); BufferedInputStream origin = new BufferedInputStream(new FileInputStream( f )); int count; byte data[] = new byte[2048]; while((count = origin.read(data)) != -1) { out.write(data, 0, count); } out.flush(); origin.close(); } out.close();
public void visit(File file, String relativePath) throws IOException { if(Functions.isWindows()) relativePath = relativePath.replace('\\','/'); if(file.isDirectory()) relativePath+='/'; TarEntry te = new TarEntry(relativePath); te.setModTime(file.lastModified()); if(!file.isDirectory()) te.setSize(file.length()); tar.putNextEntry(te); if (!file.isDirectory()) { FileInputStream in = new FileInputStream(file); try { int len; while((len=in.read(buf))>=0) tar.write(buf,0,len); } finally { in.close(); } } tar.closeEntry(); entriesWritten++; }
private void visitDir(FileCopyDetails dirDetails) { try { // Trailing slash on name indicates entry is a directory TarEntry archiveEntry = new TarEntry(dirDetails.getRelativePath().getPathString() + '/'); archiveEntry.setModTime(getArchiveTimeFor(dirDetails)); archiveEntry.setMode(UnixStat.DIR_FLAG | dirDetails.getMode()); tarOutStr.putNextEntry(archiveEntry); tarOutStr.closeEntry(); } catch (Exception e) { throw new GradleException(String.format("Could not add %s to TAR '%s'.", dirDetails, tarFile), e); } } }
private void visitFile(FileCopyDetails fileDetails) { try { TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString()); archiveEntry.setModTime(getArchiveTimeFor(fileDetails)); archiveEntry.setSize(fileDetails.getSize()); archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode()); tarOutStr.putNextEntry(archiveEntry); fileDetails.copyTo(tarOutStr); tarOutStr.closeEntry(); } catch (Exception e) { throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e); } }
protected int putFileContent(Launcher launcher, String containerId, String path, String filename, byte[] content, Integer mode) throws IOException, InterruptedException { TarEntry entry = new TarEntry(filename); entry.setUserId(0); entry.setGroupId(0); entry.setSize(content.length); if (mode != null) { entry.setMode(mode); } ByteArrayOutputStream out = new ByteArrayOutputStream(); TarOutputStream tar = new TarOutputStream(out); tar.putNextEntry(entry); tar.write(content); tar.closeEntry(); tar.close(); ArgumentListBuilder args = new ArgumentListBuilder() .add("cp", "-", containerId + ":" + path); return launchDockerCLI(launcher, args) .stdin(new ByteArrayInputStream(out.toByteArray())) .stderr(launcher.getListener().getLogger()).join(); }
protected int putFileContent(Launcher launcher, String containerId, String path, String filename, byte[] content, Integer mode) throws IOException, InterruptedException { TarEntry entry = new TarEntry(filename); entry.setUserId(0); entry.setGroupId(0); entry.setSize(content.length); if (mode != null) { entry.setMode(mode); } ByteArrayOutputStream out = new ByteArrayOutputStream(); TarOutputStream tar = new TarOutputStream(out); tar.putNextEntry(entry); tar.write(content); tar.closeEntry(); tar.close(); ArgumentListBuilder args = new ArgumentListBuilder() .add("cp", "-", containerId + ":" + path); return launchDockerCLI(launcher, args) .stdin(new ByteArrayInputStream(out.toByteArray())) .stderr(launcher.getListener().getLogger()).join(); }