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


Java TarArchiveInputStream.read方法代碼示例

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


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

示例1: untar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void untar(InputStream in, File targetDir) throws IOException {
  final TarArchiveInputStream tarIn = new TarArchiveInputStream(in);
  byte[] b = new byte[BUF_SIZE];
  TarArchiveEntry tarEntry;
  while ((tarEntry = tarIn.getNextTarEntry()) != null) {
    final File file = new File(targetDir, tarEntry.getName());
    if (tarEntry.isDirectory()) {
      if (!file.mkdirs()) {
        throw new IOException("Unable to create folder " + file.getAbsolutePath());
      }
    } else {
      final File parent = file.getParentFile();
      if (!parent.exists()) {
        if (!parent.mkdirs()) {
          throw new IOException("Unable to create folder " + parent.getAbsolutePath());
        }
      }
      try (FileOutputStream fos = new FileOutputStream(file)) {
        int r;
        while ((r = tarIn.read(b)) != -1) {
          fos.write(b, 0, r);
        }
      }
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:TarUtils.java

示例2: unTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private boolean unTar(TarArchiveInputStream tarIn, String outputDir) throws IOException {
	ArchiveEntry entry;
	boolean newFile = false;
	while ((entry = tarIn.getNextEntry()) != null) {
		File tmpFile = new File(outputDir + "/" + entry.getName());
		newFile = tmpFile.createNewFile();
		OutputStream out = new FileOutputStream(tmpFile);
		int length;
		byte[] b = new byte[2048];
		while ((length = tarIn.read(b)) != -1)
			out.write(b, 0, length);
		out.close();
	}
	tarIn.close();
	return newFile;
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:17,代碼來源:DockerOperator.java

示例3: addFile

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * @deprecated see {@link PLP5ProjectParser#parse(File)}
 */
private static void addFile(TarArchiveInputStream plpInputStream,
		TarArchiveEntry entry, File assembleFile, List<ASMFile> projectFiles)
		throws IOException
{
	byte[] content = new byte[(int) entry.getSize()];
	int currentIndex = 0;
	while (currentIndex < entry.getSize())
	{
		plpInputStream.read(content, currentIndex, content.length - currentIndex);
		currentIndex++;
	}
	if (entry.getName().endsWith(".asm"))
	{
		ASMFile asmFile = new SimpleASMFile(null, entry.getName());
		asmFile.setContent(new String(content));
		projectFiles.add(asmFile);
	}
}
 
開發者ID:dhawal9035,項目名稱:WebPLP,代碼行數:22,代碼來源:FileUtil.java

示例4: untar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static List<String> untar(FileInputStream input, String targetPath) throws IOException {
    TarArchiveInputStream tarInput = new TarArchiveInputStream(input);
    ArrayList<String> result = new ArrayList<String>();

    ArchiveEntry  entry;
    while ((entry = tarInput.getNextEntry()) != null) {
        File destPath=new File(targetPath,entry.getName());
        result.add(destPath.getPath());
        if (!entry.isDirectory()) {
            FileOutputStream fout=new FileOutputStream(destPath);
            final byte[] buffer=new byte[8192];
            int n=0;
            while (-1 != (n=tarInput.read(buffer))) {
                fout.write(buffer,0,n);
            }
            fout.close();
        }
        else {
            destPath.mkdir();
        }
    }
    tarInput.close();
    return result;
}
 
開發者ID:BloomBooks,項目名稱:BloomReader,代碼行數:25,代碼來源:IOUtilities.java

示例5: untarFile

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void untarFile(File file) throws IOException {
    FileInputStream fileInputStream = null;
    String currentDir = file.getParent();
    try {
        fileInputStream = new FileInputStream(file);
        GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
        TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gzipInputStream);

        TarArchiveEntry tarArchiveEntry;

        while (null != (tarArchiveEntry = tarArchiveInputStream.getNextTarEntry())) {
            if (tarArchiveEntry.isDirectory()) {
                FileUtils.forceMkdir(new File(currentDir + File.separator + tarArchiveEntry.getName()));
            } else {
                byte[] content = new byte[(int) tarArchiveEntry.getSize()];
                int offset = 0;
                tarArchiveInputStream.read(content, offset, content.length - offset);
                FileOutputStream outputFile = new FileOutputStream(currentDir + File.separator + tarArchiveEntry.getName());
                org.apache.commons.io.IOUtils.write(content, outputFile);
                outputFile.close();
            }
        }
    } catch (FileNotFoundException e) {
        throw new IOException(e.getStackTrace().toString());
    }
}
 
開發者ID:foundation-runtime,項目名稱:jenkins-openstack-deployment-plugin,代碼行數:27,代碼來源:CompressUtils.java

示例6: unzipTAREntry

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private void unzipTAREntry(@NonNull final Context context, TarArchiveInputStream zipFileStream, TarArchiveEntry entry,
                           String outputDir) throws IOException {
    String name = entry.getName();
    if (entry.isDirectory()) {
        FileUtil.mkdir(new File(outputDir, name), context);
        return;
    }
    File outputFile = new File(outputDir, name);
    if (!outputFile.getParentFile().exists()) {
        FileUtil.mkdir(outputFile.getParentFile(), context);
    }

    BufferedOutputStream outputStream = new BufferedOutputStream(
            FileUtil.getOutputStream(outputFile, context, entry.getRealSize()));
    try {
        int len;
        byte buf[] = new byte[GenericCopyUtil.DEFAULT_BUFFER_SIZE];
        while ((len = zipFileStream.read(buf)) > 0) {

            outputStream.write(buf, 0, len);
            ServiceWatcherUtil.POSITION += len;
        }
    } finally {
        outputStream.close();
    }
}
 
開發者ID:TeamAmaze,項目名稱:AmazeFileManager,代碼行數:27,代碼來源:ExtractService.java

示例7: extract

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Unpack the contents of a tarball (.tar.gz)
 *
 * @param tarball The source tarbal
 */
public static void extract(File tarball) throws IOException {

  TarArchiveInputStream tarIn = new TarArchiveInputStream(
      new GzipCompressorInputStream(
          new BufferedInputStream(
              new FileInputStream(tarball))));

  TarArchiveEntry tarEntry = tarIn.getNextTarEntry();

  while (tarEntry != null) {
    File entryDestination = new File(tarball.getParent(), tarEntry.getName());
    FileUtils.forceMkdirParent(entryDestination);

    if (tarEntry.isDirectory()) {
      FileUtils.forceMkdir(entryDestination);
    } else {
      entryDestination.createNewFile();

      BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(entryDestination));
      byte[] buffer = new byte[1024];
      int len;

      while ((len = tarIn.read(buffer)) != -1) {
        outputStream.write(buffer, 0, len);
      }

      outputStream.close();
    }

    tarEntry = tarIn.getNextTarEntry();
  }

  tarIn.close();
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:40,代碼來源:TarArchiveUtils.java

示例8: extract

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public void extract(File dir ) throws IOException {
    File listDir[] = dir.listFiles();
    if (listDir.length!=0){
        for (File i:listDir){
    /*  Warning! this will try and extract all files in the directory
        if other files exist, a for loop needs to go here to check that
        the file (i) is an archive file before proceeding */
            if (i.isDirectory()){
                break;
            }
            String fileName = i.toString();
            String tarFileName = fileName +".tar";
            FileInputStream instream= new FileInputStream(fileName);
            GZIPInputStream ginstream =new GZIPInputStream(instream);
            FileOutputStream outstream = new FileOutputStream(tarFileName);
            byte[] buf = new byte[1024];
            int len;
            while ((len = ginstream.read(buf)) > 0)
            {
                outstream.write(buf, 0, len);
            }
            ginstream.close();
            outstream.close();
            //There should now be tar files in the directory
            //extract specific files from tar
            TarArchiveInputStream myTarFile=new TarArchiveInputStream(new FileInputStream(tarFileName));
            TarArchiveEntry entry = null;
            int offset;
            FileOutputStream outputFile=null;
            //read every single entry in TAR file
            while ((entry = myTarFile.getNextTarEntry()) != null) {
                //the following two lines remove the .tar.gz extension for the folder name
                fileName = i.getName().substring(0, i.getName().lastIndexOf('.'));
                fileName = fileName.substring(0, fileName.lastIndexOf('.'));
                File outputDir =  new File(i.getParent() + "/" + fileName + "/" + entry.getName());
                if(! outputDir.getParentFile().exists()){
                    outputDir.getParentFile().mkdirs();
                }
                //if the entry in the tar is a directory, it needs to be created, only files can be extracted
                if(entry.isDirectory()){
                    outputDir.mkdirs();
                }else{
                    byte[] content = new byte[(int) entry.getSize()];
                    offset=0;
                    myTarFile.read(content, offset, content.length - offset);
                    outputFile=new FileOutputStream(outputDir);
                    IOUtils.write(content,outputFile);
                    outputFile.close();
                }
            }
            //close and delete the tar files, leaving the original .tar.gz and the extracted folders
            myTarFile.close();
            File tarFile =  new File(tarFileName);
            tarFile.delete();
        }
    }
}
 
開發者ID:SamaGames,項目名稱:Hydroangeas,代碼行數:58,代碼來源:ResourceManager.java

示例9: unpackEntries

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private static void unpackEntries(TarArchiveInputStream tis,
    TarArchiveEntry entry, File outputDir) throws IOException {
  if (entry.isDirectory()) {
    File subDir = new File(outputDir, entry.getName());
    if (!subDir.mkdirs() && !subDir.isDirectory()) {
      throw new IOException("Mkdirs failed to create tar internal dir "
          + outputDir);
    }

    for (TarArchiveEntry e : entry.getDirectoryEntries()) {
      unpackEntries(tis, e, subDir);
    }

    return;
  }

  File outputFile = new File(outputDir, entry.getName());
  if (!outputFile.getParentFile().exists()) {
    if (!outputFile.getParentFile().mkdirs()) {
      throw new IOException("Mkdirs failed to create tar internal dir "
          + outputDir);
    }
  }

  int count;
  byte data[] = new byte[2048];
  BufferedOutputStream outputStream = new BufferedOutputStream(
      new FileOutputStream(outputFile));

  while ((count = tis.read(data)) != -1) {
    outputStream.write(data, 0, count);
  }

  outputStream.flush();
  outputStream.close();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:37,代碼來源:FileUtil.java

示例10: dearchiveFile

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * 文件解歸檔
 *
 * @param destFile
 *            目標文件
 * @param tais
 *            TarArchiveInputStream
 * @throws Exception
 */
private static void dearchiveFile(File destFile, TarArchiveInputStream tais)
        throws Exception {

    BufferedOutputStream bos = new BufferedOutputStream(
            new FileOutputStream(destFile));

    int count;
    byte data[] = new byte[BUFFER];
    while ((count = tais.read(data, 0, BUFFER)) != -1) {
        bos.write(data, 0, count);
    }

    bos.close();
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:24,代碼來源:TarUtils.java

示例11: extractTar

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void extractTar(String fileName) throws Exception {
    if (!fileName.toLowerCase().endsWith(TAR)) {
        return;
    }
    File file = new File(fileName);

    if (file.isDirectory()) {
        return;
    }

    TarArchiveInputStream myTarFile = new TarArchiveInputStream(new FileInputStream(fileName));
    TarArchiveEntry entry;
    int offset;
    FileOutputStream outputFile;
    //read every single entry in TAR file
    while ((entry = myTarFile.getNextTarEntry()) != null) {
        //the following two lines remove the .tar.gz extension for the folder name
        String fName = file.getName().substring(0, file.getName().lastIndexOf('.'));
        if (fName.lastIndexOf('.') != -1) {
            fName = fName.substring(0, fName.lastIndexOf('.'));
        }
        File outputDir = new File(file.getParent() + File.separator + entry.getName());
        if (!outputDir.getParentFile().exists()) {
            outputDir.getParentFile().mkdirs();
        }
        //if the entry in the tar is a directory, it needs to be created, only files can be extracted
        if (entry.isDirectory()) {
            outputDir.mkdirs();
        } else {
            byte[] content = new byte[(int) entry.getSize()];
            offset = 0;
            myTarFile.read(content, offset, content.length - offset);
            outputFile = new FileOutputStream(outputDir);
            IOUtils.write(content, outputFile);
            outputFile.close();
        }
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:39,代碼來源:LaunchUtil.java

示例12: extractTarGz

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
public static void extractTarGz(InputStream inputTarGzStream, String outDir,
    boolean logging) {
  try {
    GzipCompressorInputStream gzIn = new GzipCompressorInputStream(
        inputTarGzStream);
    TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn);

    // read Tar entries
    TarArchiveEntry entry = null;
    while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) {
      if (logging) {
        LOG.info("Extracting: " + outDir + File.separator + entry.getName());
      }
      if (entry.isDirectory()) { // create directory
        File f = new File(outDir + File.separator + entry.getName());
        f.mkdirs();
      } else { // decompress file
        int count;
        byte data[] = new byte[EXTRACT_BUFFER_SIZE];

        FileOutputStream fos = new FileOutputStream(outDir + File.separator
            + entry.getName());
        BufferedOutputStream dest = new BufferedOutputStream(fos,
            EXTRACT_BUFFER_SIZE);
        while ((count = tarIn.read(data, 0, EXTRACT_BUFFER_SIZE)) != -1) {
          dest.write(data, 0, count);
        }
        dest.close();
      }
    }

    // close input stream
    tarIn.close();

  } catch (IOException e) {
    LOG.error("IOException: " + e.getMessage());
  }
}
 
開發者ID:millecker,項目名稱:senti-storm,代碼行數:39,代碼來源:IOUtils.java

示例13: unpackEntries

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private static void unpackEntries(TarArchiveInputStream tis,
    TarArchiveEntry entry, File outputDir) throws IOException {
  if (entry.isDirectory()) {
    File subDir = new File(outputDir, entry.getName());
    if (!subDir.mkdir() && !subDir.isDirectory()) {
      throw new IOException("Mkdirs failed to create tar internal dir "
          + outputDir);
    }

    for (TarArchiveEntry e : entry.getDirectoryEntries()) {
      unpackEntries(tis, e, subDir);
    }

    return;
  }

  File outputFile = new File(outputDir, entry.getName());
  if (!outputDir.exists()) {
    if (!outputDir.mkdirs()) {
      throw new IOException("Mkdirs failed to create tar internal dir "
          + outputDir);
    }
  }

  int count;
  byte data[] = new byte[2048];
  BufferedOutputStream outputStream = new BufferedOutputStream(
      new FileOutputStream(outputFile));

  while ((count = tis.read(data)) != -1) {
    outputStream.write(data, 0, count);
  }

  outputStream.flush();
  outputStream.close();
}
 
開發者ID:ict-carch,項目名稱:hadoop-plus,代碼行數:37,代碼來源:FileUtil.java

示例14: unzipTAREntry

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
private void unzipTAREntry(int id, TarArchiveInputStream zipfile, TarArchiveEntry entry, String outputDir,String string)
        throws IOException, RarException {
    String name=entry.getName();
    if (entry.isDirectory()) {
        createDir(new File(outputDir, name));
        return;
    }
    File outputFile = new File(outputDir, name);
    if (!outputFile.getParentFile().exists()) {
        createDir(outputFile.getParentFile());
    }
    //	Log.i("Amaze", "Extracting: " + entry);

    BufferedOutputStream outputStream = new BufferedOutputStream(
            new FileOutputStream(outputFile));
    try {
        int len;
        byte buf[] = new byte[20480];
        while ((len = zipfile.read(buf)) > 0) {
            //System.out.println(id + " " + hash.get(id));
            if (hash.get(id)) {
                outputStream.write(buf, 0, len);
                copiedbytes=copiedbytes+len;
                int p=(int) ((copiedbytes / (float) totalbytes) * 100);
                if(p!=lastpercent || lastpercent==0){
                    publishResults(string,p,id,totalbytes,copiedbytes,false);
                    publishResults(true);}
                lastpercent=p;
            } else {
                publishResults(string, 100, id, totalbytes, copiedbytes, true);
                publishResults(false);
                stopSelf(id);
            }
        }
    }finally {
        outputStream.close();

    }
}
 
開發者ID:DeFuture,項目名稱:AmazeFileManager-master,代碼行數:40,代碼來源:ExtractService.java

示例15: read

import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入方法依賴的package包/類
/**
 * Read from compressed file
 * 
 * @param srcPath
 *            path of compressed file
 * @param fileCompressor
 *            FileCompressor object
 * @throws Exception
 */
@Override
public void read(String srcPath, FileCompressor fileCompressor)
        throws Exception {
    long t1 = System.currentTimeMillis();
    byte[] data = FileUtil.convertFileToByte(srcPath);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    GzipCompressorInputStream cis = new GzipCompressorInputStream(bais);
    TarArchiveInputStream ais = new TarArchiveInputStream(cis);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        byte[] buffer = new byte[1024];
        int readByte;
        TarArchiveEntry entry = ais.getNextTarEntry();
        while (entry != null && entry.getSize() > 0) {
            long t2 = System.currentTimeMillis();
            baos = new ByteArrayOutputStream();
            readByte = ais.read(buffer);
            while (readByte != -1) {
                baos.write(buffer, 0, readByte);
                readByte = ais.read(buffer);
            }
            BinaryFile binaryFile = new BinaryFile(entry.getName(),
                    baos.toByteArray());
            fileCompressor.addBinaryFile(binaryFile);
            LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
                    System.currentTimeMillis());
            entry = ais.getNextTarEntry();
        }
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on get compressor file", e);
    } finally {
        baos.close();
        ais.close();
        cis.close();
        bais.close();
    }
    LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
            System.currentTimeMillis());
}
 
開發者ID:espringtran,項目名稱:compressor4j,代碼行數:49,代碼來源:TarGzProcessor.java


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