List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveInputStream read
public int read(byte b[]) throws IOException
b
. From source file:com.espringtran.compressor4j.processor.ArProcessor.java
/** * Read from compressed file//from w w w . jav a 2 s. co m * * @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); ArArchiveInputStream ais = new ArArchiveInputStream(bais); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { byte[] buffer = new byte[1024]; int readByte; ArArchiveEntry entry = ais.getNextArEntry(); 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.getNextArEntry(); } } catch (Exception e) { FileCompressor.LOGGER.error("Error on get compressor file", e); } finally { baos.close(); ais.close(); bais.close(); } LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1, System.currentTimeMillis()); }