Package org.zeroturnaround.zip.extra
Class AsiExtraField
- java.lang.Object
-
- org.zeroturnaround.zip.extra.AsiExtraField
-
- All Implemented Interfaces:
java.lang.Cloneable,ZipExtraField
public class AsiExtraField extends java.lang.Object implements ZipExtraField, java.lang.Cloneable
This is a class that has been made significantly smaller (deleted a bunch of methods) and originally is from the Apache Ant Project (http://ant.apache.org), org.apache.tools.zip package. All license and other documentation is intact. Adds 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 filenametaken 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.
Since the documentation this class is based upon doesn't mention the character encoding of the file name at all, it is assumed that it uses the current platform's default encoding.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.zip.CRC32crcInstance used to calculate checksums.(package private) intDEFAULT_DIR_PERMDefault permissions for directories.(package private) intDEFAULT_FILE_PERMDefault permissions for plain files.(package private) intDEFAULT_LINK_PERMDefault permissions for symbolic links.(package private) intDIR_FLAGIndicates directories.private booleandirFlagIs this an entry for a directory?(package private) intFILE_FLAGIndicates plain files.private intgidGroup ID.private static ZipShortHEADER_IDprivate java.lang.StringlinkFile this entry points to, if it is a symbolic link.(package private) intLINK_FLAGIndicates symbolic links.private intmodeStandard Unix stat(2) file mode.(package private) intPERM_MASKBits used for permissions (and sticky bit)private intuidUser ID.private static intWORD
-
Constructor Summary
Constructors Constructor Description AsiExtraField()Constructor for AsiExtraField.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()byte[]getCentralDirectoryData()Delegate to local file data.ZipShortgetCentralDirectoryLength()Delegate to local file data.intgetGroupId()Get the group id.ZipShortgetHeaderId()The Header-ID.java.lang.StringgetLinkedFile()Name of linked filebyte[]getLocalFileDataData()The actual data to put into local file data - without Header-ID or length specifier.ZipShortgetLocalFileDataLength()Length of the extra field in the local file data - without Header-ID or length specifier.intgetMode()File mode of this file.protected intgetMode(int mode)Get the file mode for given permissions with the correct file type.intgetUserId()Get the user id.booleanisDirectory()Is this entry a directory?booleanisLink()Is this entry a symbolic link?voidparseFromLocalFileData(byte[] data, int offset, int length)Populate data from this array as if it was in local file data.voidsetDirectory(boolean dirFlag)Indicate whether this entry is a directory.voidsetGroupId(int gid)Set the group id.voidsetLinkedFile(java.lang.String name)Indicate that this entry is a symbolic link to the given filename.voidsetMode(int mode)File mode of this file.voidsetUserId(int uid)Set the user id.
-
-
-
Field Detail
-
PERM_MASK
final int PERM_MASK
Bits used for permissions (and sticky bit)- Since:
- 1.1
- See Also:
- Constant Field Values
-
LINK_FLAG
final int LINK_FLAG
Indicates symbolic links.- Since:
- 1.1
- See Also:
- Constant Field Values
-
FILE_FLAG
final int FILE_FLAG
Indicates plain files.- Since:
- 1.1
- See Also:
- Constant Field Values
-
DIR_FLAG
final int DIR_FLAG
Indicates directories.- Since:
- 1.1
- See Also:
- Constant Field Values
-
DEFAULT_LINK_PERM
final int DEFAULT_LINK_PERM
Default permissions for symbolic links.- Since:
- 1.1
- See Also:
- Constant Field Values
-
DEFAULT_DIR_PERM
final int DEFAULT_DIR_PERM
Default permissions for directories.- Since:
- 1.1
- See Also:
- Constant Field Values
-
DEFAULT_FILE_PERM
final int DEFAULT_FILE_PERM
Default permissions for plain files.- Since:
- 1.1
- See Also:
- Constant Field Values
-
HEADER_ID
private static final ZipShort HEADER_ID
-
WORD
private static final int WORD
- See Also:
- Constant Field Values
-
mode
private int mode
Standard Unix stat(2) file mode.- Since:
- 1.1
-
uid
private int uid
User ID.- Since:
- 1.1
-
gid
private int gid
Group ID.- Since:
- 1.1
-
link
private java.lang.String link
File this entry points to, if it is a symbolic link.empty string - if entry is not a symbolic link.
- Since:
- 1.1
-
dirFlag
private boolean dirFlag
Is this an entry for a directory?- Since:
- 1.1
-
crc
private java.util.zip.CRC32 crc
Instance used to calculate checksums.- Since:
- 1.1
-
-
Method Detail
-
getHeaderId
public ZipShort getHeaderId()
The Header-ID.- Specified by:
getHeaderIdin interfaceZipExtraField- Returns:
- the value for the header id for this extrafield
- Since:
- 1.1
-
getLocalFileDataLength
public ZipShort getLocalFileDataLength()
Length of the extra field in the local file data - without Header-ID or length specifier.- Specified by:
getLocalFileDataLengthin interfaceZipExtraField- Returns:
- a
ZipShortfor the length of the data of this extra field - Since:
- 1.1
-
getCentralDirectoryLength
public ZipShort getCentralDirectoryLength()
Delegate to local file data.- Specified by:
getCentralDirectoryLengthin interfaceZipExtraField- Returns:
- the centralDirectory length
- Since:
- 1.1
-
getLocalFileDataData
public byte[] getLocalFileDataData()
The actual data to put into local file data - without Header-ID or length specifier.- Specified by:
getLocalFileDataDatain interfaceZipExtraField- Returns:
- get the data
- Since:
- 1.1
-
getCentralDirectoryData
public byte[] getCentralDirectoryData()
Delegate to local file data.- Specified by:
getCentralDirectoryDatain interfaceZipExtraField- Returns:
- the local file data
- Since:
- 1.1
-
setUserId
public void setUserId(int uid)
Set the user id.- Parameters:
uid- the user id- Since:
- 1.1
-
getUserId
public int getUserId()
Get the user id.- Returns:
- the user id
- Since:
- 1.1
-
setGroupId
public void setGroupId(int gid)
Set the group id.- Parameters:
gid- the group id- Since:
- 1.1
-
getGroupId
public int getGroupId()
Get the group id.- Returns:
- the group id
- Since:
- 1.1
-
setLinkedFile
public void setLinkedFile(java.lang.String name)
Indicate that this entry is a symbolic link to the given filename.- Parameters:
name- Name of the file this entry links to, empty String if it is not a symbolic link.- Since:
- 1.1
-
getLinkedFile
public java.lang.String getLinkedFile()
Name of linked file- Returns:
- name of the file this entry links to if it is a symbolic link, the empty string otherwise.
- Since:
- 1.1
-
isLink
public boolean isLink()
Is this entry a symbolic link?- Returns:
- true if this is a symbolic link
- Since:
- 1.1
-
setMode
public void setMode(int mode)
File mode of this file.- Parameters:
mode- the file mode- Since:
- 1.1
-
getMode
public int getMode()
File mode of this file.- Returns:
- the file mode
- Since:
- 1.1
-
setDirectory
public void setDirectory(boolean dirFlag)
Indicate whether this entry is a directory.- Parameters:
dirFlag- if true, this entry is a directory- Since:
- 1.1
-
isDirectory
public boolean isDirectory()
Is this entry a directory?- Returns:
- true if this entry is a directory
- Since:
- 1.1
-
parseFromLocalFileData
public void parseFromLocalFileData(byte[] data, int offset, int length) throws java.util.zip.ZipExceptionPopulate data from this array as if it was in local file data.- Specified by:
parseFromLocalFileDatain interfaceZipExtraField- Parameters:
data- an array of bytesoffset- the start offsetlength- the number of bytes in the array from offset- Throws:
java.util.zip.ZipException- on error- Since:
- 1.1
-
getMode
protected int getMode(int mode)
Get the file mode for given permissions with the correct file type.- Parameters:
mode- the mode- Returns:
- the type with the mode
- Since:
- 1.1
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
-