tmf: Use Apache Common Compress for importing from archive
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / wizards / importtrace / ZipFileSystemObject.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URI;
18
19 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.core.runtime.URIUtil;
23
24 /**
25 * The "Zip" implementation of an IFileSystemObject
26 */
27 class ZipFileSystemObject implements IFileSystemObject {
28
29 private ZipArchiveEntry fFileSystemObject;
30 private String fArchivePath;
31
32 ZipFileSystemObject(ZipArchiveEntry fileSystemObject, String archivePath) {
33 fFileSystemObject = fileSystemObject;
34 fArchivePath = archivePath;
35 }
36
37 @Override
38 public String getName() {
39 return new Path(fFileSystemObject.getName()).lastSegment();
40 }
41
42 @Override
43 public String getAbsolutePath() {
44 throw new UnsupportedOperationException();
45 }
46
47 @Override
48 public boolean exists() {
49 return true;
50 }
51
52 @Override
53 public String getSourceLocation() {
54 File file = new File(fArchivePath);
55 try {
56 file = file.getCanonicalFile();
57 } catch (IOException e) {
58 // Will still work but might have extra ../ in the path
59 }
60 URI uri = file.toURI();
61 IPath entryPath = new Path(fFileSystemObject.getName());
62
63 URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath);
64 return URIUtil.toUnencodedString(jarURI);
65 }
66
67 @Override
68 public Object getRawFileSystemObject() {
69 return fFileSystemObject;
70 }
71
72 @Override
73 public boolean isDirectory() {
74 return fFileSystemObject.isDirectory();
75 }
76 }
This page took 0.046264 seconds and 5 git commands to generate.