AsiExtraFieldpublic class AsiExtraField extends Object implements ZipExtraField, Cloneable, UnixStatAdds Unix file permission and UID/GID fields as well as symbolic
link handling.
This class uses the ASi extra field in the format:
Value Size Description
----- ---- -----------
(Unix3) 0x756e Short tag for this extra block type
TSize Short total data size for this block
CRC Long CRC-32 of the remaining data
Mode Short file permissions
SizDev Long symlink'd size OR major/minor dev num
UID Short user ID
GID Short group ID
(var.) variable symbolic link filename
taken from appnote.iz (Info-ZIP note, 981119) found at ftp://ftp.uu.net/pub/archiving/zip/doc/
Short is two bytes and Long is four bytes in big endian byte and
word order, device numbers are currently not supported. |
Fields Summary |
---|
private static final ZipShort | HEADER_ID | private int | modeStandard Unix stat(2) file mode. | private int | uidUser ID. | private int | gidGroup ID. | private String | linkFile this entry points to, if it is a symbolic link.
empty string - if entry is not a symbolic link. | private boolean | dirFlagIs this an entry for a directory? | private CRC32 | crcInstance used to calculate checksums. |
Constructors Summary |
---|
public AsiExtraField()Constructor for AsiExtraField.
|
Methods Summary |
---|
public byte[] | getCentralDirectoryData()Delegate to local file data.
return getLocalFileDataData();
| public ZipShort | getCentralDirectoryLength()Delegate to local file data.
return getLocalFileDataLength();
| public int | getGroupId()Get the group id.
return gid;
| public ZipShort | getHeaderId()The Header-ID.
return HEADER_ID;
| public java.lang.String | getLinkedFile()Name of linked file
return link;
| public byte[] | getLocalFileDataData()The actual data to put into local file data - without Header-ID
or length specifier.
// CRC will be added later
byte[] data = new byte[getLocalFileDataLength().getValue() - 4];
System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2);
byte[] linkArray = getLinkedFile().getBytes();
System.arraycopy(ZipLong.getBytes(linkArray.length),
0, data, 2, 4);
System.arraycopy(ZipShort.getBytes(getUserId()),
0, data, 6, 2);
System.arraycopy(ZipShort.getBytes(getGroupId()),
0, data, 8, 2);
System.arraycopy(linkArray, 0, data, 10, linkArray.length);
crc.reset();
crc.update(data);
long checksum = crc.getValue();
byte[] result = new byte[data.length + 4];
System.arraycopy(ZipLong.getBytes(checksum), 0, result, 0, 4);
System.arraycopy(data, 0, result, 4, data.length);
return result;
| public ZipShort | getLocalFileDataLength()Length of the extra field in the local file data - without
Header-ID or length specifier.
return new ZipShort(4 // CRC
+ 2 // Mode
+ 4 // SizDev
+ 2 // UID
+ 2 // GID
+ getLinkedFile().getBytes().length);
| public int | getMode()File mode of this file.
return mode;
| protected int | getMode(int mode)Get the file mode for given permissions with the correct file type.
int type = FILE_FLAG;
if (isLink()) {
type = LINK_FLAG;
} else if (isDirectory()) {
type = DIR_FLAG;
}
return type | (mode & PERM_MASK);
| public int | getUserId()Get the user id.
return uid;
| public boolean | isDirectory()Is this entry a directory?
return dirFlag && !isLink();
| public boolean | isLink()Is this entry a symbolic link?
return getLinkedFile().length() != 0;
| public void | parseFromLocalFileData(byte[] data, int offset, int length)Populate data from this array as if it was in local file data.
long givenChecksum = ZipLong.getValue(data, offset);
byte[] tmp = new byte[length - 4];
System.arraycopy(data, offset + 4, tmp, 0, length - 4);
crc.reset();
crc.update(tmp);
long realChecksum = crc.getValue();
if (givenChecksum != realChecksum) {
throw new ZipException("bad CRC checksum "
+ Long.toHexString(givenChecksum)
+ " instead of "
+ Long.toHexString(realChecksum));
}
int newMode = ZipShort.getValue(tmp, 0);
byte[] linkArray = new byte[(int) ZipLong.getValue(tmp, 2)];
uid = ZipShort.getValue(tmp, 6);
gid = ZipShort.getValue(tmp, 8);
if (linkArray.length == 0) {
link = "";
} else {
System.arraycopy(tmp, 10, linkArray, 0, linkArray.length);
link = new String(linkArray);
}
setDirectory((newMode & DIR_FLAG) != 0);
setMode(newMode);
| public void | setDirectory(boolean dirFlag)Indicate whether this entry is a directory.
this.dirFlag = dirFlag;
mode = getMode(mode);
| public void | setGroupId(int gid)Set the group id.
this.gid = gid;
| public void | setLinkedFile(java.lang.String name)Indicate that this entry is a symbolic link to the given filename.
link = name;
mode = getMode(mode);
| public void | setMode(int mode)File mode of this file.
this.mode = getMode(mode);
| public void | setUserId(int uid)Set the user id.
this.uid = uid;
|
|