public void testExplicitFileEntry() throws Exception {
File[] tmp = createTempDirAndFile();
File archive = null;
TarArchiveOutputStream tos = null;
TarArchiveInputStream tis = null;
FileInputStream fis = null;
try {
archive = File.createTempFile("test.", ".tar", tmp[0]);
archive.deleteOnExit();
tos = new TarArchiveOutputStream(new FileOutputStream(archive));
TarArchiveEntry in = new TarArchiveEntry("foo");
in.setModTime(tmp[1].lastModified());
in.setSize(tmp[1].length());
tos.putArchiveEntry(in);
byte[] b = new byte[(int) tmp[1].length()];
fis = new FileInputStream(tmp[1]);
while (fis.read(b) > 0) {
tos.write(b);
}
fis.close();
fis = null;
tos.closeArchiveEntry();
tos.close();
tos = null;
tis = new TarArchiveInputStream(new FileInputStream(archive));
TarArchiveEntry out = tis.getNextTarEntry();
tis.close();
tis = null;
assertNotNull(out);
assertEquals("foo", out.getName());
assertEquals(tmp[1].length(), out.getSize());
assertEquals(tmp[1].lastModified() / 1000,
out.getLastModifiedDate().getTime() / 1000);
assertFalse(out.isDirectory());
} finally {
if (tis != null) {
tis.close();
}
if (tos != null) {
tos.close();
}
tryHardToDelete(archive);