當前位置: 首頁>>代碼示例>>Java>>正文


Java ArchiveInputStream.close方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.ArchiveInputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ArchiveInputStream.close方法的具體用法?Java ArchiveInputStream.close怎麽用?Java ArchiveInputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.ArchiveInputStream的用法示例。


在下文中一共展示了ArchiveInputStream.close方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeOnlyUnZip

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public static void makeOnlyUnZip() throws ArchiveException, IOException{
		final InputStream is = new FileInputStream("D:/中文名字.zip");
		ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
		ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
		
		String dir = "D:/cnname";
		File filedir = new File(dir);
		if(!filedir.exists()){
			filedir.mkdir();
		}
//		OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
		OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
		IOUtils.copy(in, out);
		out.close();
		in.close();
	}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:17,代碼來源:CompressExample.java

示例2: testApache

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public void testApache() throws IOException, ArchiveException {
	log.debug("testApache()");
	File zip = File.createTempFile("apache_", ".zip");
	
	// Create zip
	FileOutputStream fos = new FileOutputStream(zip);
	ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
	aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
	aos.closeArchiveEntry();
	aos.close();
	
	// Read zip
	FileInputStream fis = new FileInputStream(zip);
	ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
	ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
	assertEquals(zae.getName(), "coñeta");
	ais.close();
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:19,代碼來源:ZipTest.java

示例3: unarchive

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private static List<File> unarchive(File inputFile, File outputDir)
        throws Throwable {
    InputStream is = new BufferedInputStream(new FileInputStream(inputFile));
    ArchiveInputStream ais = null;
    List<File> ofs = new ArrayList<File>();
    try {
        ais = new ArchiveStreamFactory().createArchiveInputStream(is);
        ArchiveEntry ae = ais.getNextEntry();
        while (ae != null) {
            if (!ae.isDirectory()) {
                File of = new File(outputDir, ae.getName());
                OutputStream os = new FileOutputStream(of);
                try {
                    IOUtils.copy(ais, os);
                } finally {
                    os.close();
                }
                ofs.add(of);
            }
            ae = ais.getNextEntry();
        }
    } catch (Throwable e) {
        // failed to extract
    } finally {
        is.close();
        if (ais != null) {
            ais.close();
        }
    }
    if (ofs.isEmpty()) {
        return null;
    } else {
        return ofs;
    }
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:36,代碼來源:DarisTranscodeImpl.java

示例4: extract

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
/**
 * Extract the file and create directories accordingly.
 *
 * @param is        pass the stream, because the stream is different for various file types
 * @param targetDir target directory
 * @throws IOException
 */
private static void extract(ArchiveInputStream is, File targetDir) throws IOException {
    try {
        if (targetDir.exists()) {
            FileUtils.forceDelete(targetDir);
        }
        createDirectory(targetDir);
        ArchiveEntry entry = is.getNextEntry();
        while (entry != null) {
            String name = entry.getName();
            name = name.substring(name.indexOf("/") + 1);
            File file = new File(targetDir, name);
            if (entry.isDirectory()) {
                createDirectory(file);
            } else {
                createDirectory(file.getParentFile());
                OutputStream os = new FileOutputStream(file);
                try {
                    IOUtils.copy(is, os);
                } finally {
                    IOUtils.closeQuietly(os);
                }
            }
            entry = is.getNextEntry();
        }
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            logger.warn("Error occurred while closing the stream", e);
        }
    }
}
 
開發者ID:wso2,項目名稱:carbon-kernel,代碼行數:40,代碼來源:ArchiveExtractor.java

示例5: read_rpm

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private List<JavaClass> read_rpm(File rpm) throws IOException,
        InterruptedException {

  ArchiveInputStream rpm_is = new RpmArchiveInputStream(rpm);
  ArchiveEntry rpm_ent;

  List<JavaClass> list = new ArrayList<JavaClass>();
  while ((rpm_ent = rpm_is.getNextEntry()) != null) {
    if (rpm_ent.isDirectory() || !rpm_ent.getName().endsWith(".jar"))
      continue;
    list.addAll(read_jar(rpm_is));
  }
  rpm_is.close();
  return list;
}
 
開發者ID:mizdebsk,項目名稱:java-deptools,代碼行數:16,代碼來源:FedoraPackage.java

示例6: extract

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private void extract(ArchiveInputStream is, File targetDir) throws IOException {
    try {
        if (targetDir.exists()) {
            FileUtils.forceDelete(targetDir);
        }
        targetDir.mkdirs();
        ArchiveEntry entry = is.getNextEntry();
        while (entry != null) {
            String name = entry.getName();
            name = name.substring(name.indexOf("/") + 1);
            File file = new File(targetDir, name);
            if (entry.isDirectory()) {
                file.mkdirs();
            } else {
                file.getParentFile().mkdirs();
                OutputStream os = new FileOutputStream(file);
                try {
                    IOUtils.copy(is, os);
                } finally {
                    IOUtils.closeQuietly(os);
                }
            }
            entry = is.getNextEntry();
        }
    } finally {
        is.close();
    }
}
 
開發者ID:openengsb-labs,項目名稱:labs-endtoend,代碼行數:29,代碼來源:DistributionExtractor.java

示例7: unCompress

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public static void unCompress (String zip_file, String output_folder)
      throws IOException, CompressorException, ArchiveException
{
   ArchiveInputStream ais = null;
   ArchiveStreamFactory asf = new ArchiveStreamFactory ();

   FileInputStream fis = new FileInputStream (new File (zip_file));

   if (zip_file.toLowerCase ().endsWith (".tar"))
   {
      ais = asf.createArchiveInputStream (
            ArchiveStreamFactory.TAR, fis);
   }
   else if (zip_file.toLowerCase ().endsWith (".zip"))
   {
      ais = asf.createArchiveInputStream (
            ArchiveStreamFactory.ZIP, fis);
   }
   else if (zip_file.toLowerCase ().endsWith (".tgz") ||
         zip_file.toLowerCase ().endsWith (".tar.gz"))
   {
      CompressorInputStream cis = new CompressorStreamFactory ().
            createCompressorInputStream (CompressorStreamFactory.GZIP, fis);
      ais = asf.createArchiveInputStream (new BufferedInputStream (cis));
   }
   else
   {
      try
      {
         fis.close ();
      }
      catch (IOException e)
      {
         LOGGER.warn ("Cannot close FileInputStream:", e);
      }
      throw new IllegalArgumentException (
            "Format not supported: " + zip_file);
   }

   File output_file = new File (output_folder);
   if (!output_file.exists ()) output_file.mkdirs ();

   // copy the existing entries
   ArchiveEntry nextEntry;
   while ((nextEntry = ais.getNextEntry ()) != null)
   {
      File ftemp = new File (output_folder, nextEntry.getName ());
      if (nextEntry.isDirectory ())
      {
         ftemp.mkdir ();
      }
      else
      {
         FileOutputStream fos = FileUtils.openOutputStream (ftemp);
         IOUtils.copy (ais, fos);
         fos.close ();
      }
   }
   ais.close ();
   fis.close ();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:62,代碼來源:UnZip.java

示例8: decompress

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
static void decompress(File inputFile, File outputDir) throws IOException {
    log.log(LogLevel.DEBUG, "Decompressing '" + inputFile + "' into '" + outputDir + "'");
    ArchiveInputStream ais = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(inputFile)));
    decompress(ais, outputDir);
    ais.close();
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:7,代碼來源:CompressedFileReference.java

示例9: extract

import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
protected void extract(ArchiveInputStream arcInStream) throws IOException {
ArchiveEntry entry = null;

/** Read the tar entries using the getNextEntry method **/

while ((entry = (ArchiveEntry) arcInStream.getNextEntry()) != null) {

    System.out.println("Extracting: " + entry.getName());

    /** If the entry is a directory, create the directory. **/

    if (entry.isDirectory()) {

	File f = new File(getDestDirectory()
		+ SystemUtils.FILE_SEPARATOR + entry.getName());
	f.mkdirs();
    }
    /**
     * If the entry is a file,write the decompressed file to the disk
     * and close destination stream.
     **/
    else {
	int count;
	byte data[] = new byte[BUFFER];

	FileOutputStream fos = new FileOutputStream(getDestDirectory()
		+ SystemUtils.FILE_SEPARATOR + entry.getName());
	BufferedOutputStream dest = new BufferedOutputStream(fos,
		BUFFER);
	while ((count = arcInStream.read(data, 0, BUFFER)) != -1) {
	    dest.write(data, 0, count);
	}
	dest.close();
    }
}

/** Close the input stream **/

arcInStream.close();
System.out.println("untar completed successfully!!");
   }
 
開發者ID:blindio,項目名稱:Prospero,代碼行數:42,代碼來源:AbstractUnarchiver.java


注:本文中的org.apache.commons.compress.archivers.ArchiveInputStream.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。