Package org.apache.commons.compress.archivers.tar

Examples of org.apache.commons.compress.archivers.tar.TarArchiveEntry


    }
   
    private static void compressTar(String parent, Resource source,TarArchiveOutputStream tos, int mode) throws IOException {
      if(source.isFile()) {
        //TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new TarEntry(parent);
        TarArchiveEntry entry = new TarArchiveEntry(parent);
           
            entry.setName(parent);
           
            // mode
            //100777 TODO ist das so ok?
            if(mode>0entry.setMode(mode);
            else if((mode=source.getMode())>0entry.setMode(mode);
           
            entry.setSize(source.length());
            entry.setModTime(source.lastModified());
            tos.putArchiveEntry(entry);
            try {
              IOUtil.copy(source,tos,false);
            }
            finally {
View Full Code Here


    InputStream is = null;
    TarArchiveInputStream debInputStream = null;
    try {
      is = new FileInputStream(inFile);
      debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
      TarArchiveEntry entry;
      while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
        final File outputFile = new File(outputDir, entry.getName());
        if (entry.isDirectory()) {
          if (!outputFile.exists()) {
            if (!outputFile.mkdirs()) {
              throw new IllegalStateException(String.format("Couldn't create directory %s.",
                  outputFile.getAbsolutePath()));
            }
View Full Code Here

   * @param tarStream TarArchive outputStream
   * @param path      path to append
   * @throws IOException thrown when having IO problem.
   */
  public static void addFolderToTar(TarArchiveOutputStream tarStream, String path) throws IOException {
    TarArchiveEntry archiveEntry = new TarArchiveEntry(path);
    archiveEntry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE);
    tarStream.putArchiveEntry(archiveEntry);
    tarStream.closeArchiveEntry();
  }
View Full Code Here

   * @param mode        mode for this entry
   * @throws IOException thrown when having IO problem.
   */
  public static void addInputStreamToTar(TarArchiveOutputStream tarStream, InputStream inputStream, String path,
                                         long size, int mode) throws IOException {
    TarArchiveEntry entry = new TarArchiveEntry(path);
    entry.setSize(size);
    entry.setMode(mode);
    try {
      tarStream.putArchiveEntry(entry);
      IOUtils.copy(inputStream, tarStream);
    } catch (IOException e) {
      throw processException("Error while adding File to Tar file", e);
View Full Code Here

   * @param path      relative path to append
   * @param mode      mode for this entry
   * @throws IOException thrown when having IO problem.
   */
  public static void addFileToTar(TarArchiveOutputStream tarStream, File file, String path, int mode) throws IOException {
    TarArchiveEntry entry = new TarArchiveEntry(path);
    entry.setSize(file.length());
    entry.setMode(mode);
    BufferedInputStream bis = null;
    try {
      tarStream.putArchiveEntry(entry);
      bis = new BufferedInputStream(new FileInputStream(file));
      IOUtils.copy(bis, tarStream);
View Full Code Here

    public void testWriteJar() throws Exception {
        ArchiveEntry entry = new JarArchiveEntry("dummy");
        compareWrites("jar", entry);
    }
    public void testWriteTar() throws Exception {
        TarArchiveEntry entry = new TarArchiveEntry("dummy");
        entry.setSize(bytesToTest);
        compareWrites("tar", entry);
    }
View Full Code Here

        try {
            archive = File.createTempFile("test.", ".tar", tmp[0]);
            archive.deleteOnExit();
            tos = new TarArchiveOutputStream(new FileOutputStream(archive));
            long beforeArchiveWrite = tmp[0].lastModified();
            TarArchiveEntry in = new TarArchiveEntry("foo/");
            in.setModTime(beforeArchiveWrite);
            tos.putArchiveEntry(in);
            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(0, out.getSize());
            assertEquals(beforeArchiveWrite / 1000,
                         out.getLastModifiedDate().getTime() / 1000);
            assertTrue(out.isDirectory());
        } finally {
            if (tis != null) {
                tis.close();
            }
            if (tos != null) {
View Full Code Here

        FileInputStream fis = null;
        try {
            archive = File.createTempFile("test.", ".tar", tmp[0]);
            archive.deleteOnExit();
            tos = new TarArchiveOutputStream(new FileOutputStream(archive));
            TarArchiveEntry in = new TarArchiveEntry(tmp[1], "foo");
            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) {
View Full Code Here

        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) {
View Full Code Here

public class ChainingTestCase extends AbstractTestCase {

    public void testTarGzip() throws Exception {
        File file = new File("src/test/resources/bla.tgz");
        final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));
        final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry();
        assertNotNull(entry);
        assertEquals("test1.xml", entry.getName());
        is.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.tar.TarArchiveEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.