public class CpioArchiveEntry extends java.lang.Object implements CpioConstants, ArchiveEntry
The old binary format is limited to 16 bits for user id, group id, device, and inode numbers. It is limited to 4 gigabyte file sizes. The old ASCII format is limited to 18 bits for the user id, group id, device, and inode numbers. It is limited to 8 gigabyte file sizes. The new ASCII format is limited to 4 gigabyte file sizes. CPIO 2.5 knows also about tar, but it is not recognized here.
Each file has a 76 (ascii) / 26 (binary) byte header, a variable length, NUL terminated filename, and variable length file data. A header for a filename "TRAILER!!!" indicates the end of the archive.
All the fields in the header are ISO 646 (approximately ASCII) strings of octal numbers, left padded, not NUL terminated.
FIELDNAME NOTES c_magic The integer value octal 070707. This value can be used to deter- mine whether this archive is written with little-endian or big- endian integers. c_dev Device that contains a directory entry for this file c_ino I-node number that identifies the input file to the file system c_mode The mode specifies both the regular permissions and the file type. c_uid Numeric User ID of the owner of the input file c_gid Numeric Group ID of the owner of the input file c_nlink Number of links that are connected to the input file c_rdev For block special and character special entries, this field contains the associated device number. For all other entry types, it should be set to zero by writers and ignored by readers. c_mtime[2] Modification time of the file, indicated as the number of seconds since the start of the epoch, 00:00:00 UTC January 1, 1970. The four-byte integer is stored with the most-significant 16 bits first followed by the least-significant 16 bits. Each of the two 16 bit values are stored in machine-native byte order. c_namesize Length of the path name, including the terminating null byte c_filesize[2] Length of the file in bytes. This is the length of the data section that follows the header structure. Must be 0 for FIFOs and directories All fields are unsigned short fields with 16-bit integer values apart from c_mtime and c_filesize which are 32-bit integer values
If necessary, the filename and file data are padded with a NUL byte to an even length
Special files, directories, and the trailer are recorded with the h_filesize field equal to 0.
In the ASCII version of this format, the 16-bit entries are represented as 6-byte octal numbers, and the 32-bit entries are represented as 11-byte octal numbers. No padding is added.
Each file has a 110 byte header, a variable length, NUL terminated filename, and variable length file data. A header for a filename "TRAILER!!!" indicates the end of the archive. All the fields in the header are ISO 646 (approximately ASCII) strings of hexadecimal numbers, left padded, not NUL terminated.
FIELDNAME NOTES c_magic[6] The string 070701 for new ASCII, the string 070702 for new ASCII with CRC c_ino[8] c_mode[8] c_uid[8] c_gid[8] c_nlink[8] c_mtim[8] c_filesize[8] must be 0 for FIFOs and directories c_maj[8] c_min[8] c_rmaj[8] only valid for chr and blk special files c_rmin[8] only valid for chr and blk special files c_namesize[8] count includes terminating NUL in pathname c_check[8] 0 for "new" portable format; for CRC format the sum of all the bytes in the file
New ASCII Format The "new" ASCII format uses 8-byte hexadecimal fields for all numbers and separates device numbers into separate fields for major and minor numbers.
The pathname is followed by NUL bytes so that the total size of the fixed header plus pathname is a multiple of four. Likewise, the file data is padded to a multiple of four bytes.
This class uses mutable fields and is not considered to be threadsafe.
Based on code from the jRPM project (http://jrpm.sourceforge.net).
The MAGIC numbers and other constants are defined in CpioConstants
N.B. does not handle the cpio "tar" format
BLOCK_SIZE, C_IRGRP, C_IROTH, C_IRUSR, C_ISBLK, C_ISCHR, C_ISDIR, C_ISFIFO, C_ISGID, C_ISLNK, C_ISNWK, C_ISREG, C_ISSOCK, C_ISUID, C_ISVTX, C_IWGRP, C_IWOTH, C_IWUSR, C_IXGRP, C_IXOTH, C_IXUSR, CPIO_TRAILER, FORMAT_NEW, FORMAT_NEW_CRC, FORMAT_NEW_MASK, FORMAT_OLD_ASCII, FORMAT_OLD_BINARY, FORMAT_OLD_MASK, MAGIC_NEW, MAGIC_NEW_CRC, MAGIC_OLD_ASCII, MAGIC_OLD_BINARY, S_IFMT
SIZE_UNKNOWN
Constructor and Description |
---|
CpioArchiveEntry(java.io.File inputFile,
java.lang.String entryName)
Creates a CpioArchiveEntry with a specified name for a
specified file.
|
CpioArchiveEntry(short format)
Creates a CpioArchiveEntry with a specified format.
|
CpioArchiveEntry(short format,
java.io.File inputFile,
java.lang.String entryName)
Creates a CpioArchiveEntry with a specified name for a
specified file.
|
CpioArchiveEntry(short format,
java.lang.String name)
Creates a CpioArchiveEntry with a specified name.
|
CpioArchiveEntry(short format,
java.lang.String name,
long size)
Creates a CpioArchiveEntry with a specified name.
|
CpioArchiveEntry(java.lang.String name)
Creates a CpioArchiveEntry with a specified name.
|
CpioArchiveEntry(java.lang.String name,
long size)
Creates a CpioArchiveEntry with a specified name.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
int |
getAlignmentBoundary()
Get the alignment boundary for this CPIO format
|
long |
getChksum()
Get the checksum.
|
int |
getDataPadCount()
Get the number of bytes needed to pad the data to the alignment boundary.
|
long |
getDevice()
Get the device id.
|
long |
getDeviceMaj()
Get the major device id.
|
long |
getDeviceMin()
Get the minor device id
|
short |
getFormat()
Get the format for this entry.
|
long |
getGID()
Get the group id.
|
int |
getHeaderPadCount()
Deprecated.
This method doesn't properly work for multi-byte encodings. And
creates corrupt archives. Use
getHeaderPadCount(Charset)
or getHeaderPadCount(long) in any case. |
int |
getHeaderPadCount(java.nio.charset.Charset charset)
Get the number of bytes needed to pad the header to the alignment boundary.
|
int |
getHeaderPadCount(long namesize)
Get the number of bytes needed to pad the header to the alignment boundary.
|
int |
getHeaderSize()
Get the header size for this CPIO format
|
long |
getInode()
Set the inode.
|
java.util.Date |
getLastModifiedDate()
Gets the last modified date of this entry.
|
long |
getMode()
Get the mode of this entry (e.g.
|
java.lang.String |
getName()
Get the name.
|
long |
getNumberOfLinks()
Get the number of links.
|
long |
getRemoteDevice()
Get the remote device id.
|
long |
getRemoteDeviceMaj()
Get the remote major device id.
|
long |
getRemoteDeviceMin()
Get the remote minor device id.
|
long |
getSize()
Get the filesize.
|
long |
getTime()
Get the time in seconds.
|
long |
getUID()
Get the user id.
|
int |
hashCode() |
boolean |
isBlockDevice()
Check if this entry represents a block device.
|
boolean |
isCharacterDevice()
Check if this entry represents a character device.
|
boolean |
isDirectory()
Check if this entry represents a directory.
|
boolean |
isNetwork()
Check if this entry represents a network device.
|
boolean |
isPipe()
Check if this entry represents a pipe.
|
boolean |
isRegularFile()
Check if this entry represents a regular file.
|
boolean |
isSocket()
Check if this entry represents a socket.
|
boolean |
isSymbolicLink()
Check if this entry represents a symbolic link.
|
void |
setChksum(long chksum)
Set the checksum.
|
void |
setDevice(long device)
Set the device id.
|
void |
setDeviceMaj(long maj)
Set major device id.
|
void |
setDeviceMin(long min)
Set the minor device id
|
void |
setGID(long gid)
Set the group id.
|
void |
setInode(long inode)
Set the inode.
|
void |
setMode(long mode)
Set the mode of this entry (e.g.
|
void |
setName(java.lang.String name)
Set the name.
|
void |
setNumberOfLinks(long nlink)
Set the number of links.
|
void |
setRemoteDevice(long device)
Set the remote device id.
|
void |
setRemoteDeviceMaj(long rmaj)
Set the remote major device id.
|
void |
setRemoteDeviceMin(long rmin)
Set the remote minor device id.
|
void |
setSize(long size)
Set the filesize.
|
void |
setTime(long time)
Set the time in seconds.
|
void |
setUID(long uid)
Set the user id.
|
public CpioArchiveEntry(short format)
format
- The cpio format for this entry.
Possible format values are:
CpioConstants.FORMAT_NEW CpioConstants.FORMAT_NEW_CRC CpioConstants.FORMAT_OLD_BINARY CpioConstants.FORMAT_OLD_ASCII
public CpioArchiveEntry(java.lang.String name)
name
- The name of this entry.public CpioArchiveEntry(short format, java.lang.String name)
format
- The cpio format for this entry.name
- The name of this entry.
Possible format values are:
CpioConstants.FORMAT_NEW CpioConstants.FORMAT_NEW_CRC CpioConstants.FORMAT_OLD_BINARY CpioConstants.FORMAT_OLD_ASCII
public CpioArchiveEntry(java.lang.String name, long size)
name
- The name of this entry.size
- The size of this entrypublic CpioArchiveEntry(short format, java.lang.String name, long size)
format
- The cpio format for this entry.name
- The name of this entry.size
- The size of this entry
Possible format values are:
CpioConstants.FORMAT_NEW CpioConstants.FORMAT_NEW_CRC CpioConstants.FORMAT_OLD_BINARY CpioConstants.FORMAT_OLD_ASCII
public CpioArchiveEntry(java.io.File inputFile, java.lang.String entryName)
inputFile
- The file to gather information from.entryName
- The name of this entry.public CpioArchiveEntry(short format, java.io.File inputFile, java.lang.String entryName)
format
- The cpio format for this entry.inputFile
- The file to gather information from.entryName
- The name of this entry.
Possible format values are:
CpioConstants.FORMAT_NEW CpioConstants.FORMAT_NEW_CRC CpioConstants.FORMAT_OLD_BINARY CpioConstants.FORMAT_OLD_ASCII
public long getChksum()
java.lang.UnsupportedOperationException
- if the format is not a new formatpublic long getDevice()
java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with a new
format.public long getDeviceMaj()
java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with an old
format.public long getDeviceMin()
java.lang.UnsupportedOperationException
- if format is not a new formatpublic long getSize()
getSize
in interface ArchiveEntry
ArchiveEntry.getSize()
public short getFormat()
public long getGID()
public int getHeaderSize()
public int getAlignmentBoundary()
@Deprecated public int getHeaderPadCount()
getHeaderPadCount(Charset)
or getHeaderPadCount(long)
in any case.public int getHeaderPadCount(java.nio.charset.Charset charset)
charset
- The character set used to encode the entry name in the stream.public int getHeaderPadCount(long namesize)
namesize
- The length of the name in bytes, as read in the stream.
Without the trailing zero byte.public int getDataPadCount()
public long getInode()
public long getMode()
public java.lang.String getName()
This method returns the raw name as it is stored inside of the archive.
getName
in interface ArchiveEntry
public long getNumberOfLinks()
public long getRemoteDevice()
java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with a new
format.public long getRemoteDeviceMaj()
java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with an old
format.public long getRemoteDeviceMin()
java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with an old
format.public long getTime()
public java.util.Date getLastModifiedDate()
ArchiveEntry
getLastModifiedDate
in interface ArchiveEntry
public long getUID()
public boolean isBlockDevice()
public boolean isCharacterDevice()
public boolean isDirectory()
isDirectory
in interface ArchiveEntry
public boolean isNetwork()
public boolean isPipe()
public boolean isRegularFile()
public boolean isSocket()
public boolean isSymbolicLink()
public void setChksum(long chksum)
chksum
- The checksum to set.public void setDevice(long device)
device
- The device id to set.java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with a new
format.public void setDeviceMaj(long maj)
maj
- The major device id to set.public void setDeviceMin(long min)
min
- The minor device id to set.public void setSize(long size)
size
- The filesize to set.public void setGID(long gid)
gid
- The group id to set.public void setInode(long inode)
inode
- The inode to set.public void setMode(long mode)
mode
- The mode to set.public void setName(java.lang.String name)
name
- The name to set.public void setNumberOfLinks(long nlink)
nlink
- The number of links to set.public void setRemoteDevice(long device)
device
- The remote device id to set.java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with a new
format.public void setRemoteDeviceMaj(long rmaj)
rmaj
- The remote major device id to set.java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with an old
format.public void setRemoteDeviceMin(long rmin)
rmin
- The remote minor device id to set.java.lang.UnsupportedOperationException
- if this method is called for a CpioArchiveEntry with an old
format.public void setTime(long time)
time
- The time to set.public void setUID(long uid)
uid
- The user id to set.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved