Commit | Line | Data |
---|---|---|
7c62be2f MAL |
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. Inspired from TarEntry. | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace; | |
14 | ||
15 | /** | |
16 | * GZip entry | |
17 | */ | |
18 | public class GzipEntry { | |
8c18ab35 MK |
19 | private static final int MILLIS_PER_SECOND = 1000; |
20 | private static final int READ_WRITE_USER_READ_GROUP = 0644; | |
7c62be2f MAL |
21 | private static final String ROOT_DIR = "/"; //$NON-NLS-1$ |
22 | private final String fName; | |
23 | private final long fMode; | |
24 | private final long fTime; | |
25 | private final int fType; | |
26 | ||
27 | /** | |
28 | * Entry type for normal files. This is the only valid type for Gzip | |
29 | * entries. | |
30 | */ | |
31 | public static final int FILE = '0'; | |
32 | ||
33 | /** | |
34 | * Entry type for directories. This doesn't really exist in a Gzip but it's | |
35 | * useful to represent the root of the archive. | |
36 | */ | |
37 | public static final int DIRECTORY = '5'; | |
38 | ||
39 | /** | |
40 | * Create a new Root GzipEntry | |
41 | */ | |
42 | public GzipEntry() { | |
43 | fName = ROOT_DIR; | |
8c18ab35 | 44 | fMode = READ_WRITE_USER_READ_GROUP; |
7c62be2f | 45 | fType = DIRECTORY; |
8c18ab35 | 46 | fTime = System.currentTimeMillis() / MILLIS_PER_SECOND; |
7c62be2f MAL |
47 | } |
48 | ||
49 | /** | |
50 | * Create a new GzipEntry for a file of the given name at the given position | |
51 | * in the file. | |
52 | * | |
53 | * @param name | |
54 | * filename | |
55 | */ | |
56 | public GzipEntry(String name) { | |
57 | fName = name; | |
8c18ab35 | 58 | fMode = READ_WRITE_USER_READ_GROUP; |
7c62be2f | 59 | fType = FILE; |
8c18ab35 | 60 | fTime = System.currentTimeMillis() / MILLIS_PER_SECOND; |
7c62be2f MAL |
61 | } |
62 | ||
63 | /** | |
64 | * Returns the type of this file, can only be FILE for a real Gzip entry. | |
65 | * DIRECTORY can be specified to represent a "dummy root" in the archive. | |
66 | * | |
67 | * @return file type | |
68 | */ | |
69 | public int getFileType() { | |
70 | return fType; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Returns the mode of the file in UNIX permissions format. | |
75 | * | |
76 | * @return file mode | |
77 | */ | |
78 | public long getMode() { | |
79 | return fMode; | |
80 | } | |
81 | ||
82 | /** | |
83 | * Returns the name of the file. | |
84 | * | |
85 | * @return filename | |
86 | */ | |
87 | public String getName() { | |
88 | return fName; | |
89 | } | |
90 | ||
91 | /** | |
92 | * Returns the modification time of the file in seconds since January 1st | |
93 | * 1970. | |
94 | * | |
95 | * @return time | |
96 | */ | |
97 | public long getTime() { | |
98 | return fTime; | |
99 | } | |
100 | } |