| 1 | /******************************************************************************* | 
| 2 |  * Copyright (c) 2008, 2009 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 |  *******************************************************************************/ | 
| 11 | package org.eclipse.pde.api.tools.internal.util; | 
| 12 |   | 
| 13 | /** | 
| 14 |  * Representation of a file in a tar archive. | 
| 15 |  */ | 
| 16 | public class TarEntry implements Cloneable { | 
| 17 |         private String name; | 
| 18 |         private long mode, time, size; | 
| 19 |         private int type; | 
| 20 |         int filepos; | 
| 21 |   | 
| 22 |         /** | 
| 23 |          * Entry type for normal files. | 
| 24 |          */ | 
| 25 |         public static final int FILE = '0'; | 
| 26 |   | 
| 27 |         /** | 
| 28 |          * Entry type for directories. | 
| 29 |          */ | 
| 30 |         public static final int DIRECTORY = '5'; | 
| 31 |          | 
| 32 |         /** | 
| 33 |          * Create a new TarEntry for a file of the given name at the | 
| 34 |          * given position in the file. | 
| 35 |          *  | 
| 36 |          * @param name filename | 
| 37 |          * @param pos position in the file in bytes | 
| 38 |          */ | 
| 39 |         TarEntry(String name, int pos) { | 
| 40 |                 this.name = name; | 
| 41 |                 mode = 0644; | 
| 42 |                 type = FILE; | 
| 43 |                 filepos = pos; | 
| 44 |                 time = System.currentTimeMillis() / 1000; | 
| 45 |         } | 
| 46 |   | 
| 47 |         /** | 
| 48 |          * Create a new TarEntry for a file of the given name. | 
| 49 |          *  | 
| 50 |          * @param name filename | 
| 51 |          */ | 
| 52 |         public TarEntry(String name) { | 
| 53 |                 this(name, -1); | 
| 54 |         } | 
| 55 |   | 
| 56 |         /* (non-Javadoc) | 
| 57 |          * @see java.lang.Object#clone() | 
| 58 |          */ | 
| 59 |         public Object clone() { | 
| 60 |                 TarEntry entry = new TarEntry(this.name, this.filepos); | 
| 61 |                 entry.setFileType(this.type); | 
| 62 |                 entry.setMode(this.mode); | 
| 63 |                 entry.setSize(this.size); | 
| 64 |                 entry.setTime(this.time); | 
| 65 |                 return entry; | 
| 66 |         } | 
| 67 |   | 
| 68 |         /** | 
| 69 |          * Returns the type of this file, one of FILE, LINK, SYM_LINK, | 
| 70 |          * CHAR_DEVICE, BLOCK_DEVICE, DIRECTORY or FIFO. | 
| 71 |          *  | 
| 72 |          * @return file type | 
| 73 |          */ | 
| 74 |         public int getFileType() { | 
| 75 |                 return type; | 
| 76 |         } | 
| 77 |   | 
| 78 |         /** | 
| 79 |          * Returns the mode of the file in UNIX permissions format. | 
| 80 |          *  | 
| 81 |          * @return file mode | 
| 82 |          */ | 
| 83 |         public long getMode() { | 
| 84 |                 return mode; | 
| 85 |         } | 
| 86 |   | 
| 87 |         /** | 
| 88 |          * Returns the name of the file. | 
| 89 |          *  | 
| 90 |          * @return filename | 
| 91 |          */ | 
| 92 |         public String getName() { | 
| 93 |                 return name; | 
| 94 |         } | 
| 95 |   | 
| 96 |         /** | 
| 97 |          * Returns the size of the file in bytes. | 
| 98 |          *  | 
| 99 |          * @return size | 
| 100 |          */ | 
| 101 |         public long getSize() { | 
| 102 |                 return size; | 
| 103 |         } | 
| 104 |   | 
| 105 |         /** | 
| 106 |          * Returns the modification time of the file in seconds since January | 
| 107 |          * 1st 1970. | 
| 108 |          *  | 
| 109 |          * @return time | 
| 110 |          */ | 
| 111 |         public long getTime() { | 
| 112 |                 return time; | 
| 113 |         } | 
| 114 |   | 
| 115 |         /** | 
| 116 |          * Sets the type of the file, one of FILE, LINK, SYMLINK, CHAR_DEVICE, | 
| 117 |          * BLOCK_DEVICE, or DIRECTORY. | 
| 118 |          *  | 
| 119 |          * @param type | 
| 120 |          */ | 
| 121 |         public void setFileType(int type) { | 
| 122 |                 this.type = type; | 
| 123 |         } | 
| 124 |   | 
| 125 |         /** | 
| 126 |          * Sets the mode of the file in UNIX permissions format. | 
| 127 |          *  | 
| 128 |          * @param mode | 
| 129 |          */ | 
| 130 |         public void setMode(long mode) { | 
| 131 |                 this.mode = mode; | 
| 132 |         } | 
| 133 |   | 
| 134 |         /** | 
| 135 |          * Sets the size of the file in bytes. | 
| 136 |          *  | 
| 137 |          * @param size | 
| 138 |          */ | 
| 139 |         public void setSize(long size) { | 
| 140 |                 this.size = size; | 
| 141 |         } | 
| 142 |   | 
| 143 |         /** | 
| 144 |          * Sets the modification time of the file in seconds since January | 
| 145 |          * 1st 1970. | 
| 146 |          *  | 
| 147 |          * @param time | 
| 148 |          */ | 
| 149 |         public void setTime(long time) { | 
| 150 |                 this.time = time; | 
| 151 |         } | 
| 152 |         public String toString() { | 
| 153 |                 return this.getName(); | 
| 154 |         } | 
| 155 | } |