当前位置: 首页>>代码示例>>Java>>正文


Java TarArchiveOutputStream.write方法代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveOutputStream.write方法的具体用法?Java TarArchiveOutputStream.write怎么用?Java TarArchiveOutputStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.compress.archivers.tar.TarArchiveOutputStream的用法示例。


在下文中一共展示了TarArchiveOutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addToTar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addToTar (File dir, TarArchiveOutputStream tar, String prefix) throws IOException
{
	for (String file : dir.list())
	{
		File f = new File(dir, file);
		WorkerMain.getLogger().debug(f);
		if (f.isDirectory())
			addToTar(f, tar, prefix + file + "/");
		else
		{
			TarArchiveEntry entry = new TarArchiveEntry(prefix + file);
			entry.setSize(f.length());
			tar.putArchiveEntry(entry);
			FileInputStream in = new FileInputStream(f);
			byte buf[] = new byte[8192];
			int read;
			while ((read = in.read(buf)) > 0)
				tar.write(buf, 0, read);
			in.close();
			tar.closeArchiveEntry();
		}
	}
}
 
开发者ID:Turnierserver,项目名称:Turnierserver,代码行数:24,代码来源:LibraryCache.java

示例2: addFileEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private static void addFileEntry(
    TarArchiveOutputStream tarOut, String entryName, File file, long modTime) throws IOException {
  final TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);
  if (modTime >= 0) {
    tarEntry.setModTime(modTime);
  }
  tarOut.putArchiveEntry(tarEntry);
  try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
    final byte[] buf = new byte[BUF_SIZE];
    int r;
    while ((r = in.read(buf)) != -1) {
      tarOut.write(buf, 0, r);
    }
  }
  tarOut.closeArchiveEntry();
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:TarUtils.java

示例3: compressData

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TarArchiveOutputStream aos = new TarArchiveOutputStream(baos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            TarArchiveEntry entry = new TarArchiveEntry(
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:33,代码来源:TarProcessor.java

示例4: addArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addArchive(File file, TarArchiveOutputStream aos,
		String basepath) throws Exception {
	if (file.exists()) {
		TarArchiveEntry entry = new TarArchiveEntry(basepath + "/"
				+ file.getName());
		entry.setSize(file.length());
		aos.putArchiveEntry(entry);
		BufferedInputStream bis = new BufferedInputStream(
				new FileInputStream(file));
		int count;
		byte data[] = new byte[1024];
		while ((count = bis.read(data, 0, data.length)) != -1) {
			aos.write(data, 0, count);
		}
		bis.close();
		aos.closeArchiveEntry();
	}
}
 
开发者ID:Petasoft,项目名称:Export,代码行数:19,代码来源:ExpProc.java

示例5: populateTgzArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private File populateTgzArchive(File archive, List<FileRef> fileset) throws IOException {
	archive.getParentFile().mkdirs();
	CompressorOutputStream zip = new GzipCompressorOutputStream(new FileOutputStream(archive));
	TarArchiveOutputStream tar = new TarArchiveOutputStream(zip);
	for (FileRef fileRef : fileset) {
		TarArchiveEntry entry = new TarArchiveEntry(new File(fileRef.getRelativeLocation()));
		byte[] bytes = fileRef.getContent().getBytes();
		entry.setSize(bytes.length);
		tar.putArchiveEntry(entry);
		tar.write(bytes);
		tar.closeArchiveEntry();
	}
	tar.close();
	return archive;
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:16,代码来源:MavenDeployer.java

示例6: addTarEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
default void addTarEntry(String path, byte[] content) throws IOException {
    @SuppressWarnings("resource")
    TarArchiveOutputStream tos = getTarArchiveOutputStream();
    TarArchiveEntry entry = new TarArchiveEntry(path);
    entry.setSize(content.length);
    tos.putArchiveEntry(entry);
    tos.write(content);
    tos.closeArchiveEntry();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:10,代码来源:GeneratorContext.java

示例7: addTarEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addTarEntry(TarArchiveOutputStream tos, String path, byte[] content) throws IOException {
    TarArchiveEntry entry = new TarArchiveEntry(path);
    entry.setSize(content.length);
    tos.putArchiveEntry(entry);
    tos.write(content);
    tos.closeArchiveEntry();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:8,代码来源:DefaultProjectGenerator.java

示例8: createTarFile

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
static LocalResource createTarFile(FileContext files, Path p, int len,
    Random r, LocalResourceVisibility vis) throws IOException,
    URISyntaxException {
  byte[] bytes = new byte[len];
  r.nextBytes(bytes);

  File archiveFile = new File(p.toUri().getPath() + ".tar");
  archiveFile.createNewFile();
  TarArchiveOutputStream out = new TarArchiveOutputStream(
      new FileOutputStream(archiveFile));
  TarArchiveEntry entry = new TarArchiveEntry(p.getName());
  entry.setSize(bytes.length);
  out.putArchiveEntry(entry);
  out.write(bytes);
  out.closeArchiveEntry();
  out.close();

  LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
  ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
      + ".tar")));
  ret.setSize(len);
  ret.setType(LocalResourceType.ARCHIVE);
  ret.setVisibility(vis);
  ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".tar"))
      .getModificationTime());
  return ret;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestFSDownload.java

示例9: createTgzFile

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
static LocalResource createTgzFile(FileContext files, Path p, int len,
    Random r, LocalResourceVisibility vis) throws IOException,
    URISyntaxException {
  byte[] bytes = new byte[len];
  r.nextBytes(bytes);

  File gzipFile = new File(p.toUri().getPath() + ".tar.gz");
  gzipFile.createNewFile();
  TarArchiveOutputStream out = new TarArchiveOutputStream(
      new GZIPOutputStream(new FileOutputStream(gzipFile)));
  TarArchiveEntry entry = new TarArchiveEntry(p.getName());
  entry.setSize(bytes.length);
  out.putArchiveEntry(entry);
  out.write(bytes);
  out.closeArchiveEntry();
  out.close();

  LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
  ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
      + ".tar.gz")));
  ret.setSize(len);
  ret.setType(LocalResourceType.ARCHIVE);
  ret.setVisibility(vis);
  ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".tar.gz"))
      .getModificationTime());
  return ret;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestFSDownload.java

示例10: archiveFile

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * 数据归档
 *
 * @param data
 *            待归档数据
 * @param path
 *            归档数据的当前路径
 * @param name
 *            归档文件名
 * @param taos
 *            TarArchiveOutputStream
 * @throws Exception
 */
private static void archiveFile(File file, TarArchiveOutputStream taos,
                                String dir) throws Exception {

    /**
     * 归档内文件名定义
     *
     * <pre>
     * 如果有多级目录,那么这里就需要给出包含目录的文件名
     * 如果用WinRAR打开归档包,中文名将显示为乱码
     * </pre>
     */
    TarArchiveEntry entry = new TarArchiveEntry(dir + file.getName());

    entry.setSize(file.length());

    taos.putArchiveEntry(entry);

    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
            file));
    int count;
    byte data[] = new byte[BUFFER];
    while ((count = bis.read(data, 0, BUFFER)) != -1) {
        taos.write(data, 0, count);
    }

    bis.close();

    taos.closeArchiveEntry();
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:43,代码来源:TarUtils.java

示例11: sendMetadataCompressed

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
@Override
protected void sendMetadataCompressed(String fileName, byte[] content, long lastModified,
    TarArchiveOutputStream container) throws IOException {
    TarArchiveEntry entry = new TarArchiveEntry(fileName);
    entry.setModTime(lastModified);
    entry.setSize(content.length);
    container.putArchiveEntry(entry);
    container.write(content);
    container.closeArchiveEntry();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRTarServlet.java

示例12: addTarEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
default void addTarEntry(String path, byte[] content) throws IOException {
    TarArchiveOutputStream tos = getTarArchiveOutputStream();
    TarArchiveEntry entry = new TarArchiveEntry(path);
    entry.setSize(content.length);
    tos.putArchiveEntry(entry);
    tos.write(content);
    tos.closeArchiveEntry();
}
 
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:9,代码来源:GeneratorContext.java

示例13: addTarEntry

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addTarEntry(TarArchiveOutputStream tos, String path, byte[] content) throws IOException {

        TarArchiveEntry entry = new TarArchiveEntry(path);
        entry.setSize(content.length);
        tos.putArchiveEntry(entry);
        tos.write(content);
        tos.closeArchiveEntry();
    }
 
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:9,代码来源:DefaultProjectGenerator.java

示例14: compressTar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
@SuppressWarnings("resource")
private void compressTar(ByteArrayOutputStream out) throws IOException { 
	TarArchiveOutputStream wrapperOS = new TarArchiveOutputStream(out);
	TarArchiveEntry entry = new TarArchiveEntry(ArchiveStreamFactory.TAR);
	entry.setSize(data.length);
	wrapperOS.putArchiveEntry(entry);
	wrapperOS.write(data);
	wrapperOS.closeArchiveEntry();
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:10,代码来源:Tar.java

示例15: addEntryToTar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
private void addEntryToTar(File source, String entryName, byte[] buffer, int length) throws IOException, ArchiveException {
    File tmpTar = File.createTempFile(source.getName(), null, parentDir);
    tmpTar.delete();
    if (!source.renameTo(tmpTar)) {
        throw new IOException("Cannot create temp file: " + source.getName());
    }

    FileInputStream fis = new FileInputStream(tmpTar);
    TarArchiveInputStream tin = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, fis);
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(source));
    tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
    tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);

    // copy the existing entries    
    ArchiveEntry nextEntry;
    while ((nextEntry = tin.getNextEntry()) != null) {
        tos.putArchiveEntry(nextEntry);
        IOUtils.copy(tin, tos);
        tos.closeArchiveEntry();
    }

    // Create new entry
    TarArchiveEntry entry = new TarArchiveEntry(entryName);
    entry.setSize(length);
    tos.putArchiveEntry(entry);
    tos.write(buffer, 0, length);
    tos.closeArchiveEntry();

    IOHelper.close(fis, tin, tos);
    LOG.trace("Deleting temporary file: {}", tmpTar);
    FileUtil.deleteFile(tmpTar);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:TarAggregationStrategy.java


注:本文中的org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。