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


Java TarInputStream.close方法代码示例

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


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

示例1: setup

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
/**
 * @throws IOException
 */
@Before
public void setup() throws IOException {
	hadoopCommand = "-i %s -om %s -ro %s";
	final TarInputStream tin = new TarInputStream(new GZIPInputStream(
			CorrelationModeTest.class.getResourceAsStream("/org/openimaj/hadoop/tools/twitter/dfidf.out.tar.gz")));
	TarEntry entry = null;
	output = folder.newFile("results.out");
	output.delete();
	output.mkdir();
	dest = folder.newFile("DFIDF.out");
	dest.delete();
	dest.mkdir();

	while ((entry = tin.getNextEntry()) != null) {
		final File tdst = new File(dest.toString(), entry.getName());
		if (entry.isDirectory()) {
			tdst.mkdir();
		} else {
			final FileOutputStream fout = new FileOutputStream(tdst);
			tin.copyEntryContents(fout);
			fout.close();
		}
	}
	tin.close();
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:29,代码来源:CorrelationModeTest.java

示例2: untar

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
protected void untar (File destDir, InputStream inputStream) throws IOException {
  TarInputStream tin = new TarInputStream (inputStream);
  TarEntry tarEntry = null;

  while ((tarEntry = tin.getNextEntry ()) != null) {
    File destEntry = new File (destDir, tarEntry.getName ());
    File parent = destEntry.getParentFile ();

    if (!parent.exists ()) {
      parent.mkdirs ();
    }

    if (tarEntry.isDirectory ()) {
      destEntry.mkdirs ();
    } else {
      FileOutputStream fout = new FileOutputStream (destEntry);
      try {
        tin.copyEntryContents (fout);
      } finally {
        fout.close ();
      }
    }
  }

  tin.close ();
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:27,代码来源:FileProjectManager.java

示例3: extractTar

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
public boolean extractTar() throws IOException {
	logger.info("Extract prism archive: "+prismArchive);
	InputStream gzStream = prismArchive.openStream();
       TarInputStream tarStream = new TarInputStream(new GZIPInputStream(gzStream));
       TarEntry tarEntry;
       while((tarEntry=tarStream.getNextEntry()) != null) {
		File destPath = new File(prismDestinationDir,tarEntry.getName());
		if (tarEntry.isDirectory()) {
			destPath.mkdir();
			continue;
		}
		FileOutputStream fout = new FileOutputStream(destPath);
		tarStream.copyEntryContents(fout);
		fout.close();
		if(tarEntry.getName().endsWith("install.sh"))
			destPath.setExecutable(true);
	}
	tarStream.close();
	gzStream.close();
	return true;		
}
 
开发者ID:aciancone,项目名称:klapersuite,代码行数:22,代码来源:PrismRunner.java

示例4: unzip

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
public static File unzip(File folder, ByteBuffer buf) throws IOException {
    File outputFolder = new File(folder, Long.toString(System.currentTimeMillis()));
    log.debug("Unzipping into " + outputFolder.getAbsoluteFile().getAbsolutePath());

    if (outputFolder.exists()) {
        throw new IOException(String.format("Folder already exists at %s, please attempt submission again", outputFolder.getAbsoluteFile().getAbsolutePath()));
    } else {
        boolean folderCreated = outputFolder.mkdir();
        if (!folderCreated) {
            throw new IOException(String.format("Folder for submission could not be created at %s", outputFolder.getAbsoluteFile().getAbsolutePath()));
        }
    }

    TarInputStream tar = new TarInputStream(new GZIPInputStream(new ByteArrayInputStream(buf.array())));
    TarEntry entry = tar.getNextEntry();

    while (entry != null) {
        String fileName = entry.getName();
        File newFile = new File(outputFolder, fileName);

        //create all non exists folders
        //else you will hit FileNotFoundException for compressed folder
        new File(newFile.getParent()).mkdirs();

        if (!entry.isDirectory()) {
            FileOutputStream fos = new FileOutputStream(newFile);
            tar.copyEntryContents(fos);
            fos.close();
        }
        entry = tar.getNextEntry();
    }

    tar.close();
    return outputFolder;
}
 
开发者ID:ezbake,项目名称:ezbake-azkaban-submitter,代码行数:36,代码来源:UnzipUtil.java

示例5: extract

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
/**
 * Extract the <code>archive</code> to the <code>dest</code> 
 * directory.<br><br>
 *  
 * @param archive
 * 			The archive to be extract.
 * @param dest
 * 			The destination directory extract to.
 * @since	
 * 			1.0.2  
 * @throws IOException
 * 			Any kind of I/O Errors.
 * @throws IllegalArgumentException
 * 			If the <code>dest</code> is not a directory.
 * @return true if the operations run successfully.	
 */

public boolean extract(File archive, File dest) throws IOException{
	super.extract(archive, dest);
	BufferedInputStream bis = new BufferedInputStream(
		new FileInputStream(archive));
	TarInputStream tis = new TarInputStream(bis);
	
	int count = 0;
	for (;; count++) {
		TarEntry entry = tis.getNextEntry();
				
		if (entry == null) {				
			break;
		}			
		
		String name = entry.getName();
		name = name.replace('/', File.separatorChar);
		File destFile = new File(dest, name);
		if (entry.isDirectory()) {
			if (!destFile.exists()) {
				if (!destFile.mkdirs()) {
					throw new IOException(
						"Error making directory path :"
					   + destFile.getPath());
				}
			}
		} else {
			File subDir = new File(destFile.getParent());
			if (!subDir.exists()) {
				if (!subDir.mkdirs()) {
					throw new IOException(
						"Error making directory path :"
					   + subDir.getPath());
				}
			}	
			
			FileOutputStream out = new FileOutputStream(destFile);
			// FIXME: TUNE PLACE
			byte[] rdbuf = new byte[32 * 1024];
			for (;;){
				int numRead = tis.read(rdbuf);
				if (numRead == -1)
					break;						
				out.write(rdbuf, 0, numRead);
			}
			out.close();
		}
	}
	// For gc
	tis.close(); tis = null;
	bis.close(); bis = null;
	// NO FILE EXTRACTED, throw IOException
	if (count == 0)
		throw new IOException("At least one file should be a TAR.");
		
	return true;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:74,代码来源:ArchiverTar.java

示例6: listAsFile

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
/**
 * List the files inside the <code>archive</code>.<br>
 * 
 * This operation is quite slow and pending to optimize.
 * 
 * @param archive
 * 			The archive to be listed.
 * @since	
 * 			1.0.2 
 * @return
 * 			A list of java.io.File object that represents
 * 			each entry in the archive. 
 */
public List listAsFile(File archive) throws IOException{
	TarInputStream tarInStream = new TarInputStream(new FileInputStream(archive));
	
	TarEntry entry = null;
	ArrayList list = new ArrayList();
	while((entry = tarInStream.getNextEntry())!=null){
		list.add(entry.getFile());
	}
	tarInStream.close();
	return list;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:25,代码来源:ArchiverTar.java

示例7: listAsFilename

import org.apache.tools.tar.TarInputStream; //导入方法依赖的package包/类
/**
 * List the files inside the <code>archive</code>. 
 * 
 * @param archive
 * 			The archive to be listed.
 * @since	
 * 			1.0.2 
 * @return
 * 			A list of String objects that represents
 * 			the filename of each entry in the 
 * 			archive. 
 */
public List listAsFilename(File archive) throws IOException{
	TarInputStream tarInStream = new TarInputStream(new FileInputStream(archive));
	
	TarEntry entry = null;
	ArrayList list = new ArrayList();
	while((entry = tarInStream.getNextEntry())!=null){
		list.add(entry.getName());
	}
	tarInStream.close();
	return list;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:24,代码来源:ArchiverTar.java


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