本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveEntry.setMode方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveEntry.setMode方法的具体用法?Java TarArchiveEntry.setMode怎么用?Java TarArchiveEntry.setMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveEntry
的用法示例。
在下文中一共展示了TarArchiveEntry.setMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyInfo
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static void applyInfo ( final TarArchiveEntry entry, final EntryInformation entryInformation, TimestampProvider timestampProvider )
{
if ( entryInformation == null )
{
return;
}
if ( entryInformation.getUser () != null )
{
entry.setUserName ( entryInformation.getUser () );
}
if ( entryInformation.getGroup () != null )
{
entry.setGroupName ( entryInformation.getGroup () );
}
entry.setMode ( entryInformation.getMode () );
entry.setModTime ( timestampProvider.getModTime () );
}
示例2: addControlContent
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void addControlContent ( final TarArchiveOutputStream out, final String name, final ContentProvider content, final int mode ) throws IOException
{
if ( content == null || !content.hasContent () )
{
return;
}
final TarArchiveEntry entry = new TarArchiveEntry ( name );
if ( mode >= 0 )
{
entry.setMode ( mode );
}
entry.setUserName ( "root" );
entry.setGroupName ( "root" );
entry.setSize ( content.getSize () );
entry.setModTime ( this.getTimestampProvider ().getModTime () );
out.putArchiveEntry ( entry );
try ( InputStream stream = content.createInputStream () )
{
ByteStreams.copy ( stream, out );
}
out.closeArchiveEntry ();
}
示例3: tar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static void tar(Path inputPath, Path outputPath) throws IOException {
if (!Files.exists(inputPath)) {
throw new FileNotFoundException("File not found " + inputPath);
}
try (TarArchiveOutputStream tarArchiveOutputStream = buildTarStream(outputPath.toFile())) {
if (!Files.isDirectory(inputPath)) {
TarArchiveEntry tarEntry = new TarArchiveEntry(inputPath.toFile().getName());
if (inputPath.toFile().canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
putTarEntry(tarArchiveOutputStream, tarEntry, inputPath);
} else {
Files.walkFileTree(inputPath,
new TarDirWalker(inputPath, tarArchiveOutputStream));
}
tarArchiveOutputStream.flush();
}
}
示例4: applyInfo
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static void applyInfo ( final TarArchiveEntry entry, final EntryInformation entryInformation )
{
if ( entryInformation == null )
{
return;
}
if ( entryInformation.getUser () != null )
{
entry.setUserName ( entryInformation.getUser () );
}
if ( entryInformation.getGroup () != null )
{
entry.setGroupName ( entryInformation.getGroup () );
}
entry.setMode ( entryInformation.getMode () );
}
示例5: addControlContent
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void addControlContent ( final TarArchiveOutputStream out, final String name, final ContentProvider content, final int mode, final Supplier<Instant> timestampSupplier ) throws IOException
{
if ( content == null || !content.hasContent () )
{
return;
}
final TarArchiveEntry entry = new TarArchiveEntry ( name );
if ( mode >= 0 )
{
entry.setMode ( mode );
}
entry.setUserName ( "root" );
entry.setGroupName ( "root" );
entry.setSize ( content.getSize () );
entry.setModTime ( timestampSupplier.get ().toEpochMilli () );
out.putArchiveEntry ( entry );
try ( InputStream stream = content.createInputStream () )
{
IOUtils.copy ( stream, out );
}
out.closeArchiveEntry ();
}
示例6: compressTar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static void compressTar(String parent, Resource source,TarArchiveOutputStream tos, int mode) throws IOException {
if(source.isFile()) {
//TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new TarEntry(parent);
TarArchiveEntry entry = new TarArchiveEntry(parent);
entry.setName(parent);
// mode
//100777 TODO ist das so ok?
if(mode>0) entry.setMode(mode);
else if((mode=source.getMode())>0) entry.setMode(mode);
entry.setSize(source.length());
entry.setModTime(source.lastModified());
tos.putArchiveEntry(entry);
try {
IOUtil.copy(source,tos,false);
}
finally {
tos.closeArchiveEntry();
}
}
else if(source.isDirectory()) {
compressTar(parent, source.listResources(),tos,mode);
}
}
示例7: tar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* Recursively tar file
*
* @param inputPath
* file path can be directory
* @param outputPath
* where to put the archived file
* @param childrenOnly
* if inputPath is directory and if childrenOnly is true, the archive will contain all of its children, else the archive
* contains unique entry which is the inputPath itself
* @param gZipped
* compress with gzip algorithm
*/
public static void tar(Path inputPath, Path outputPath, boolean gZipped, boolean childrenOnly) throws IOException {
if (!Files.exists(inputPath)) {
throw new FileNotFoundException("File not found " + inputPath);
}
FileUtils.touch(outputPath.toFile());
try (TarArchiveOutputStream tarArchiveOutputStream = buildTarStream(outputPath, gZipped)) {
if (!Files.isDirectory(inputPath)) {
TarArchiveEntry tarEntry = new TarArchiveEntry(inputPath.getFileName().toString());
if (inputPath.toFile().canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
putTarEntry(tarArchiveOutputStream, tarEntry, inputPath);
} else {
Path sourcePath = inputPath;
if (!childrenOnly) {
// In order to have the dossier as the root entry
sourcePath = inputPath.getParent();
}
Files.walkFileTree(inputPath, new TarDirWalker(sourcePath, tarArchiveOutputStream));
}
tarArchiveOutputStream.flush();
}
}
示例8: archiveTARFiles
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static File archiveTARFiles(File base, Iterable<File> files, String archiveNameWithOutExtension)
throws IOException {
File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar");
tarFile.deleteOnExit();
try (TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(
new FileOutputStream(tarFile))))) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (File file : files) {
TarArchiveEntry tarEntry = new TarArchiveEntry(file);
tarEntry.setName(relativize(base, file));
if (!file.isDirectory() && file.canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
tos.putArchiveEntry(tarEntry);
if (!file.isDirectory()) {
FileUtils.copyFile(file, tos);
}
tos.closeArchiveEntry();
}
}
return tarFile;
}
示例9: getDefaultEntry
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
protected TarArchiveEntry getDefaultEntry(ArchiveContext context, String name, long size) {
StringBuilder entryName = new StringBuilder(context.getRequest().getItemName());
entryName.append("-").append(context.getVersion());
if ( ! name.startsWith(File.separator) ) {
entryName.append(File.separator);
}
entryName.append(name);
TarArchiveEntry entry = new TarArchiveEntry(entryName.toString());
entry.setUserName("root");
entry.setGroupName("root");
entry.setMode(0644);
entry.setSize(size);
entry.setModTime(new Date(System.currentTimeMillis()-(60*60*24*1000)));
return entry;
}
示例10: visitFile
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
TarArchiveEntry tarEntry = new TarArchiveEntry(basePath.relativize(file).toFile());
tarEntry.setSize(attrs.size());
if (file.toFile().canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
ArchiveUtil.putTarEntry(tarArchiveOutputStream, tarEntry, file);
return FileVisitResult.CONTINUE;
}
示例11: recursiveTar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void recursiveTar(String entryFilename, String rootPath, String itemPath, TarArchiveOutputStream tarArchive) {
try {
final File sourceFile = new File(itemPath).getCanonicalFile(); // e.g. /foo/bar/baz
final File sourceRootFile = new File(rootPath).getCanonicalFile(); // e.g. /foo
final String relativePathToSourceFile = sourceRootFile.toPath().relativize(sourceFile.toPath()).toFile().toString(); // e.g. /bar/baz
final TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, entryFilename + "/" + relativePathToSourceFile); // entry filename e.g. /xyz/bar/baz
// TarArchiveEntry automatically sets the mode for file/directory, but we can update to ensure that the mode is set exactly (inc executable bits)
tarEntry.setMode(getUnixFileMode(itemPath));
tarArchive.putArchiveEntry(tarEntry);
if (sourceFile.isFile()) {
Files.copy(sourceFile.toPath(), tarArchive);
}
// a directory entry merely needs to exist in the TAR file - there is no data stored yet
tarArchive.closeArchiveEntry();
final File[] children = sourceFile.listFiles();
if (children != null) {
// recurse into child files/directories
for (final File child : children) {
recursiveTar(entryFilename, sourceRootFile.getCanonicalPath(), child.getCanonicalPath(), tarArchive);
}
}
} catch (IOException e) {
log.error("Error when copying TAR file entry: {}", itemPath, e);
throw new UncheckedIOException(e); // fail fast
}
}
示例12: transferTo
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* transfer content of this Transferable to the output stream. <b>Must not</b> close the stream.
*
* @param tarArchiveOutputStream stream to output
* @param destination
*/
default void transferTo(TarArchiveOutputStream tarArchiveOutputStream, final String destination) {
TarArchiveEntry tarEntry = new TarArchiveEntry(destination);
tarEntry.setSize(getSize());
tarEntry.setMode(getFileMode());
try {
tarArchiveOutputStream.putArchiveEntry(tarEntry);
IOUtils.write(getBytes(), tarArchiveOutputStream);
tarArchiveOutputStream.closeArchiveEntry();
} catch (IOException e) {
throw new RuntimeException("Can't transfer " + getDescription(), e);
}
}
示例13: afterContainerCreate
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
@Override
public void afterContainerCreate(DockerClient client, String containerId) throws IOException {
// upload archive
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
TarArchiveOutputStream tarOut = new TarArchiveOutputStream(byteArrayOutputStream)) {
// @see hudson.model.Slave.JnlpJar.getURL()
// byte[] slavejar = IOUtils.toByteArray(Jenkins.getInstance().servletContext.getResourceAsStream("/WEB-INF/slave.jar"));
// if (isNull(null)) {
// // during the development this path doesn't have the files.
// slavejar = Files.readAllBytes(Paths.get("./target/jenkins/WEB-INF/slave.jar"));
// }
byte[] slaveJar = new Slave.JnlpJar("slave.jar").readFully();
TarArchiveEntry entry = new TarArchiveEntry("slave.jar");
entry.setSize(slaveJar.length);
entry.setMode(0664);
tarOut.putArchiveEntry(entry);
tarOut.write(slaveJar);
tarOut.closeArchiveEntry();
tarOut.close();
try (InputStream is = new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
client.copyArchiveToContainerCmd(containerId)
.withTarInputStream(is)
.withRemotePath("/tmp")
.exec();
}
}
}
示例14: visitFile
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
TarArchiveEntry tarEntry = new TarArchiveEntry(FilePathUtil.relativize(basePath, file));
if (file.toFile().canExecute()) {
tarEntry.setMode(tarEntry.getMode() | 0755);
}
CompressArchiveUtil.putTarEntry(tarArchiveOutputStream, tarEntry, file);
return FileVisitResult.CONTINUE;
}
示例15: beforeContainerStarted
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
@Override
public void beforeContainerStarted(DockerAPI api, String workdir, String containerId) throws IOException, InterruptedException {
final String key = sshKeyStrategy.getInjectedKey();
if (key != null) {
String AuthorizedKeysCommand = "#!/bin/sh\n"
+ "[ \"$1\" = \"" + sshKeyStrategy.getUser() + "\" ] "
+ "&& echo '" + key + "'"
+ "|| :";
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
TarArchiveOutputStream tar = new TarArchiveOutputStream(bos)) {
TarArchiveEntry entry = new TarArchiveEntry("authorized_key");
entry.setSize(AuthorizedKeysCommand.getBytes().length);
entry.setMode(0700);
tar.putArchiveEntry(entry);
tar.write(AuthorizedKeysCommand.getBytes());
tar.closeArchiveEntry();
tar.close();
try (InputStream is = new ByteArrayInputStream(bos.toByteArray())) {
api.getClient().copyArchiveToContainerCmd(containerId)
.withTarInputStream(is)
.withRemotePath("/root")
.exec();
}
}
}
}