Commit | Line | Data |
---|---|---|
5d5f933e MAL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2004, 2015 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | * Marc-Andre Laperle <marc-andre.laperle@ericsson.com> - Copied to Trace Compass to work around bug 501379 | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace; | |
13 | ||
14 | /** | |
15 | * Representation of a file in a tar archive. | |
16 | */ | |
17 | public class TarEntry implements Cloneable | |
18 | { | |
19 | private String name; | |
20 | private long mode, time, size; | |
21 | private int type; | |
22 | int filepos; | |
23 | ||
24 | /** | |
25 | * Entry type for normal files. | |
26 | */ | |
27 | public static final int FILE = '0'; | |
28 | ||
29 | /** | |
30 | * Entry type for directories. | |
31 | */ | |
32 | public static final int DIRECTORY = '5'; | |
33 | ||
34 | /** | |
35 | * Create a new TarEntry for a file of the given name at the | |
36 | * given position in the file. | |
37 | * | |
38 | * @param name filename | |
39 | * @param pos position in the file in bytes | |
40 | */ | |
41 | TarEntry(String name, int pos) { | |
42 | this.name = name; | |
43 | mode = 0644; | |
44 | type = FILE; | |
45 | filepos = pos; | |
46 | time = System.currentTimeMillis() / 1000; | |
47 | } | |
48 | ||
49 | /** | |
50 | * Create a new TarEntry for a file of the given name. | |
51 | * | |
52 | * @param name filename | |
53 | */ | |
54 | public TarEntry(String name) { | |
55 | this(name, -1); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Returns the type of this file, one of FILE, LINK, SYM_LINK, | |
60 | * CHAR_DEVICE, BLOCK_DEVICE, DIRECTORY or FIFO. | |
61 | * | |
62 | * @return file type | |
63 | */ | |
64 | public int getFileType() { | |
65 | return type; | |
66 | } | |
67 | ||
68 | /** | |
69 | * Returns the mode of the file in UNIX permissions format. | |
70 | * | |
71 | * @return file mode | |
72 | */ | |
73 | public long getMode() { | |
74 | return mode; | |
75 | } | |
76 | ||
77 | /** | |
78 | * Returns the name of the file. | |
79 | * | |
80 | * @return filename | |
81 | */ | |
82 | public String getName() { | |
83 | return name; | |
84 | } | |
85 | ||
86 | /** | |
87 | * Returns the size of the file in bytes. | |
88 | * | |
89 | * @return filesize | |
90 | */ | |
91 | public long getSize() { | |
92 | return size; | |
93 | } | |
94 | ||
95 | /** | |
96 | * Returns the modification time of the file in seconds since January | |
97 | * 1st 1970. | |
98 | * | |
99 | * @return time | |
100 | */ | |
101 | public long getTime() { | |
102 | return time; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Sets the type of the file, one of FILE, LINK, SYMLINK, CHAR_DEVICE, | |
107 | * BLOCK_DEVICE, or DIRECTORY. | |
108 | * | |
109 | * @param type the file type | |
110 | */ | |
111 | public void setFileType(int type) { | |
112 | this.type = type; | |
113 | } | |
114 | ||
115 | /** | |
116 | * Sets the mode of the file in UNIX permissions format. | |
117 | * | |
118 | * @param mode the mode | |
119 | */ | |
120 | public void setMode(long mode) { | |
121 | this.mode = mode; | |
122 | } | |
123 | ||
124 | /** | |
125 | * Sets the size of the file in bytes. | |
126 | * | |
127 | * @param size the file size | |
128 | */ | |
129 | public void setSize(long size) { | |
130 | this.size = size; | |
131 | } | |
132 | ||
133 | /** | |
134 | * Sets the modification time of the file in seconds since January | |
135 | * 1st 1970. | |
136 | * | |
137 | * @param time the modification time | |
138 | */ | |
139 | public void setTime(long time) { | |
140 | this.time = time; | |
141 | } | |
142 | } |