final long file2Length = file2.length();
{
final OutputStream out = new FileOutputStream(output);
final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("cpio", out);
CpioArchiveEntry entry = new CpioArchiveEntry("test1.xml", file1Length);
entry.setMode(CpioConstants.C_ISREG);
os.putArchiveEntry(entry);
IOUtils.copy(new FileInputStream(file1), os);
os.closeArchiveEntry();
entry = new CpioArchiveEntry("test2.xml", file2Length);
entry.setMode(CpioConstants.C_ISREG);
os.putArchiveEntry(entry);
IOUtils.copy(new FileInputStream(file2), os);
os.closeArchiveEntry();
os.finish();
os.close();
out.close();
}
// Unarchive Operation
final File input = output;
final InputStream is = new FileInputStream(input);
final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("cpio", is);
Map<String, File> result = new HashMap<String, File>();
ArchiveEntry entry = null;
while ((entry = in.getNextEntry()) != null) {
File cpioget = new File(dir, entry.getName());
final OutputStream out = new FileOutputStream(cpioget);
IOUtils.copy(in, out);
out.close();
result.put(entry.getName(), cpioget);
}
in.close();
is.close();
File t = result.get("test1.xml");