本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveEntry.setName方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveEntry.setName方法的具体用法?Java TarArchiveEntry.setName怎么用?Java TarArchiveEntry.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveEntry
的用法示例。
在下文中一共展示了TarArchiveEntry.setName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: addDirToArchive
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* adds a directory to a gzip file, recursively
*
* @param tos TarArchiveOutputStream
* @param srcFile File
*/
private void addDirToArchive(TarArchiveOutputStream tos, File srcFile) {
File[] files = srcFile.listFiles();
for (File file : files) {
if (file.isDirectory()) {
addDirToArchive(tos, file);
continue;
}
try {
logger.debug("Adding file: " + file.getPath());
TarArchiveEntry entry = new TarArchiveEntry(file.getPath());
entry.setName(repository.toURI().relativize(file.toURI()).getPath());
entry.setSize(file.length());
tos.putArchiveEntry(entry);
IOUtils.copy(new FileInputStream(file), tos);
tos.closeArchiveEntry();
} catch (IOException ioe) {
logger.error("can not add to gzip file. " + ioe.getMessage());
}
}
}
示例3: addDirToArchive
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* adds a directory to a zip file, recursively
*
* @param tos TarArchiveOutputStream
* @param srcFile File
*/
private void addDirToArchive(TarArchiveOutputStream tos, File srcFile) {
File[] files = srcFile.listFiles();
for (File file : files) {
if (file.isDirectory()) {
addDirToArchive(tos, file);
continue;
}
try {
logger.debug("Adding file: " + file.getPath());
TarArchiveEntry entry = new TarArchiveEntry(file.getPath());
entry.setName(repository.toURI().relativize(file.toURI()).getPath());
entry.setSize(file.length());
tos.putArchiveEntry(entry);
IOUtils.copy(new FileInputStream(file), tos);
tos.closeArchiveEntry();
} catch (IOException ioe) {
logger.error("can not add to tar file. " + ioe.getMessage());
}
}
}
示例4: 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;
}
示例5: addToImage
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
protected void addToImage(final TarArchiveOutputStream imageOutputStream, final TarArchiveEntry entry,
Optional<InputStream> inputStream) throws IOException {
if (entry.getName().startsWith("/")) {
entry.setName(ROOTFS_PREFIX + entry.getName());
} else {
entry.setName(ROOTFS_PREFIX + "/" + entry.getName());
}
imageOutputStream.putArchiveEntry(entry);
if (inputStream.isPresent()) {
IOUtils.copy(inputStream.get(), imageOutputStream);
}
imageOutputStream.closeArchiveEntry();
}