Search in sources :

Example 11 with TarFile

use of org.eclipse.ui.internal.wizards.datatransfer.TarFile in project tmdm-studio-se by Talend.

the class MDMImportItemUtilTest method testBuildUnzippedTempFile.

@Test
public void testBuildUnzippedTempFile() {
    assertNull(MDMImportItemUtil.buildUnzippedTempFile(null));
    File unzippedTempFile = null;
    // test file
    File tempFile = createTempFile();
    if (tempFile != null) {
        unzippedTempFile = MDMImportItemUtil.buildUnzippedTempFile(tempFile);
        assertNotNull(unzippedTempFile);
        assertEquals(tempFile.getName(), unzippedTempFile.getName());
        // ////
        FilesUtils.deleteFile(unzippedTempFile.getParentFile(), true);
    }
    // test folder with file
    tempFile = tempFile.getParentFile();
    unzippedTempFile = MDMImportItemUtil.buildUnzippedTempFile(tempFile);
    assertNotNull(unzippedTempFile);
    assertEquals(1, unzippedTempFile.list().length);
    assertEquals(tempFile.getName(), unzippedTempFile.getName());
    assertTrue(unzippedTempFile.isDirectory());
    assertTrue(unzippedTempFile.list().length > 0);
    // ////
    FilesUtils.deleteFile(tempFile, true);
    // ////
    FilesUtils.deleteFile(unzippedTempFile.getParentFile(), true);
    // test tar file
    File tempFolder = IOUtil.getTempFolder();
    // $NON-NLS-1$
    String tarfile = tempFolder.getAbsolutePath() + File.separator + "test.tar";
    createTarFile(tarfile);
    File unzippedTempTarFile;
    try {
        unzippedTempTarFile = MDMImportItemUtil.buildUnzippedTempFile(new TarFile(tarfile));
        assertNotNull(unzippedTempTarFile);
        // $NON-NLS-1$
        assertEquals("test.txt", unzippedTempTarFile.getName());
        FilesUtils.deleteFile(tempFolder, true);
        FilesUtils.deleteFile(unzippedTempTarFile.getParentFile(), true);
        // test zip file
        tempFile = createTempFile();
        tempFolder = IOUtil.getTempFolder();
        // $NON-NLS-1$
        String destZipfile = tempFolder.getAbsolutePath() + File.separator + "test.zip";
        createZipFile(tempFile, destZipfile);
        unzippedTempTarFile = MDMImportItemUtil.buildUnzippedTempFile(new ZipFile(new File(destZipfile)));
        assertNotNull(unzippedTempFile);
        // $NON-NLS-1$
        assertEquals("test.txt", unzippedTempTarFile.getName());
        FilesUtils.deleteFile(tempFile.getParentFile(), true);
        FilesUtils.deleteFile(tempFolder, true);
        FilesUtils.deleteFile(unzippedTempTarFile.getParentFile(), true);
    } catch (Exception e) {
        // 
        log.error(e.getMessage(), e);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)11 ZipFile (java.util.zip.ZipFile)10 File (java.io.File)9 TarLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider)6 ZipLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Iterator (java.util.Iterator)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 FileOutputStream (java.io.FileOutputStream)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 ZipToFile (org.talend.mdm.commmon.util.workbench.ZipToFile)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1