要幸福 2013-04-23 17:28
浏览 276
已采纳

求java解析tar.Z? 另附上java对zip、tar.gz、 tar.bz、 tar的解压。

       使用java代码解tar.Z文件,程序最终跑在windows上面,不排除以后客户迁移,所以不能使用java调用系统命令的方式解压,只能通过代码来解压。java内部支持解压格式太少,后来使用apache.commons.compress解压了zip、tar.gz、 tar.bz、 tar。但是还是没有找到tar.Z怎么解压,求教高手,帮忙解答。下面是zip、tar.gz、 tar.bz、 tar几种格式的解压。       

 

public List<String> list(InputStream inputStream, boolean isCloseStream) throws IOException {
        List<String> list = new ArrayList<String>();
        ArchiveInputStream in = null;
        try {
            in = new ArchiveStreamFactory().createArchiveInputStream("tar", new BufferedInputStream(inputStream));
            TarArchiveEntry entry = null;
            while ((entry = (TarArchiveEntry) in.getNextEntry()) != null) {
                list.addAll(FileFach.parserEveryFile(entry.getName().replaceAll("\\\\", "/"), in));
            }
        } catch (ArchiveException e) {
            throw new ExtractorException(ErrorType.UNSUPPORTED_FILE_TYPE, e);
        } finally {
            if (isCloseStream) {
                IOUtils.closeQuietly(in);
                IOUtils.closeQuietly(inputStream);
            }
        }
        return list;
    }
public List<String> list(InputStream inputStream, boolean isCloseStream) throws IOException {
        List<String> list = new ArrayList<String>();
        ArchiveInputStream in = null;
        GZIPInputStream gis = null;
        try {
            gis = new GZIPInputStream(new BufferedInputStream(inputStream));
            in = new ArchiveStreamFactory().createArchiveInputStream("tar", gis);            
            TarArchiveEntry entry = null;

            while ((entry = (TarArchiveEntry) in.getNextEntry()) != null) {
                list.addAll(FileFach.parserEveryFile(entry.getName().replaceAll("\\\\", "/"), in));
            }
            entry = null;
        } catch (ArchiveException e) {
            throw new ExtractorException(ErrorType.UNSUPPORTED_FILE_TYPE, e);
        } finally {
            if (isCloseStream) {
                IOUtils.closeQuietly(gis);
                IOUtils.closeQuietly(inputStream);
                IOUtils.closeQuietly(in);
            }
        }
        return list;
    }
public List<String> list(InputStream inputStream, boolean isCloseStream) throws IOException {

        List<String> list = new ArrayList<String>();
        ArchiveInputStream in = null;
        try {
            in = new ArchiveStreamFactory().createArchiveInputStream("tar", new BZip2CompressorInputStream(inputStream));
            TarArchiveEntry entry = null;
            while ((entry = (TarArchiveEntry) in.getNextEntry()) != null) {
                list.addAll(FileFach.parserEveryFile(entry.getName().replaceAll("\\\\", "/"), in));
            }
        } catch (ArchiveException e) {
            throw new ExtractorException(ErrorType.UNSUPPORTED_FILE_TYPE, e);
        } finally {
            if (isCloseStream) {
                IOUtils.closeQuietly(in);
                IOUtils.closeQuietly(inputStream);
            }
        }
        return list;
    }
public List<String> list(InputStream inputStream, boolean isCloseStream) throws IOException {
        List<String> list = new ArrayList<String>();
        ArchiveInputStream in = null;
        try {
            in = new ArchiveStreamFactory().createArchiveInputStream("zip", new BufferedInputStream(inputStream));
            ZipArchiveEntry entry = null;
            while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) {
                list.addAll(FileFach.parserEveryFile(entry.getName().replaceAll("\\\\", "/"), in));
            }
        } catch (ArchiveException e) {
            throw new ExtractorException(ErrorType.UNSUPPORTED_FILE_TYPE, e);
        } finally {
            if (isCloseStream) {
                IOUtils.closeQuietly(inputStream);
                IOUtils.closeQuietly(in);
            }
        }
        return list;
    }
  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用