FileDocCategorySizeDatePackage
ZipEntry.javaAPI DocJava SE 6 API8941Tue Jun 10 00:26:00 BST 2008java.util.zip

ZipEntry

public class ZipEntry extends Object implements ZipConstants, Cloneable
This class is used to represent a ZIP file entry.
version
1.40, 11/17/05
author
David Connelly

Fields Summary
String
name
long
time
long
crc
long
size
long
csize
int
method
byte[]
extra
String
comment
public static final int
STORED
Compression method for uncompressed entries.
public static final int
DEFLATED
Compression method for compressed (deflated) entries.
Constructors Summary
public ZipEntry(String name)
Creates a new zip entry with the specified name.

param
name the entry name
exception
NullPointerException if the entry name is null
exception
IllegalArgumentException if the entry name is longer than 0xFFFF bytes


     
	/* Zip library is loaded from System.initializeSystemClass */
	initIDs();
    
	if (name == null) {
	    throw new NullPointerException();
	}
	if (name.length() > 0xFFFF) {
	    throw new IllegalArgumentException("entry name too long");
	}
	this.name = name;
    
public ZipEntry(ZipEntry e)
Creates a new zip entry with fields taken from the specified zip entry.

param
e a zip Entry object

	name = e.name;
	time = e.time;
	crc = e.crc;
	size = e.size;
	csize = e.csize;
	method = e.method;
	extra = e.extra;
	comment = e.comment;
    
ZipEntry(String name, long jzentry)

	this.name = name;
	initFields(jzentry);
    
ZipEntry(long jzentry)

	initFields(jzentry);
    
Methods Summary
public java.lang.Objectclone()
Returns a copy of this entry.

	try {
	    ZipEntry e = (ZipEntry)super.clone();
	    e.extra = (extra == null ? null : (byte[])extra.clone());
	    return e;
	} catch (CloneNotSupportedException e) {
	    // This should never happen, since we are Cloneable
	    throw new InternalError();
	}
    
private static longdosToJavaTime(long dtime)

	Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80),
			  (int)(((dtime >> 21) & 0x0f) - 1),
			  (int)((dtime >> 16) & 0x1f),
			  (int)((dtime >> 11) & 0x1f),
			  (int)((dtime >> 5) & 0x3f),
			  (int)((dtime << 1) & 0x3e));
	return d.getTime();
    
public java.lang.StringgetComment()
Returns the comment string for the entry, or null if none.

return
the comment string for the entry, or null if none
see
#setComment(String)

	return comment;
    
public longgetCompressedSize()
Returns the size of the compressed entry data, or -1 if not known. In the case of a stored entry, the compressed size will be the same as the uncompressed size of the entry.

return
the size of the compressed entry data, or -1 if not known
see
#setCompressedSize(long)

	return csize;
    
public longgetCrc()
Returns the CRC-32 checksum of the uncompressed entry data, or -1 if not known.

return
the CRC-32 checksum of the uncompressed entry data, or -1 if not known
see
#setCrc(long)

	return crc;
    
public byte[]getExtra()
Returns the extra field data for the entry, or null if none.

return
the extra field data for the entry, or null if none
see
#setExtra(byte[])

	return extra;
    
public intgetMethod()
Returns the compression method of the entry, or -1 if not specified.

return
the compression method of the entry, or -1 if not specified
see
#setMethod(int)

	return method;
    
public java.lang.StringgetName()
Returns the name of the entry.

return
the name of the entry

	return name;
    
public longgetSize()
Returns the uncompressed size of the entry data, or -1 if not known.

return
the uncompressed size of the entry data, or -1 if not known
see
#setSize(long)

	return size;
    
public longgetTime()
Returns the modification time of the entry, or -1 if not specified.

return
the modification time of the entry, or -1 if not specified
see
#setTime(long)

	return time != -1 ? dosToJavaTime(time) : -1;
    
public inthashCode()
Returns the hash code value for this entry.

	return name.hashCode();
    
private native voidinitFields(long jzentry)

private static native voidinitIDs()

public booleanisDirectory()
Returns true if this is a directory entry. A directory entry is defined to be one whose name ends with a '/'.

return
true if this is a directory entry

	return name.endsWith("/");
    
private static longjavaToDosTime(long time)

	Date d = new Date(time);
	int year = d.getYear() + 1900;
	if (year < 1980) {
	    return (1 << 21) | (1 << 16);
	}
	return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
               d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
               d.getSeconds() >> 1;
    
public voidsetComment(java.lang.String comment)
Sets the optional comment string for the entry.

param
comment the comment string
exception
IllegalArgumentException if the length of the specified comment string is greater than 0xFFFF bytes
see
#getComment()

	if (comment != null && comment.length() > 0xffff/3
                    && ZipOutputStream.getUTF8Length(comment) > 0xffff) {
	    throw new IllegalArgumentException("invalid entry comment length");
	}
	this.comment = comment;
    
public voidsetCompressedSize(long csize)
Sets the size of the compressed entry data.

param
csize the compressed size to set to
see
#getCompressedSize()

	this.csize = csize;
    
public voidsetCrc(long crc)
Sets the CRC-32 checksum of the uncompressed entry data.

param
crc the CRC-32 value
exception
IllegalArgumentException if the specified CRC-32 value is less than 0 or greater than 0xFFFFFFFF
see
#getCrc()

	if (crc < 0 || crc > 0xFFFFFFFFL) {
	    throw new IllegalArgumentException("invalid entry crc-32");
	}
	this.crc = crc;
    
public voidsetExtra(byte[] extra)
Sets the optional extra field data for the entry.

param
extra the extra field data bytes
exception
IllegalArgumentException if the length of the specified extra field data is greater than 0xFFFF bytes
see
#getExtra()

	if (extra != null && extra.length > 0xFFFF) {
	    throw new IllegalArgumentException("invalid extra field length");
	}
	this.extra = extra;
    
public voidsetMethod(int method)
Sets the compression method for the entry.

param
method the compression method, either STORED or DEFLATED
exception
IllegalArgumentException if the specified compression method is invalid
see
#getMethod()

	if (method != STORED && method != DEFLATED) {
	    throw new IllegalArgumentException("invalid compression method");
	}
	this.method = method;
    
public voidsetSize(long size)
Sets the uncompressed size of the entry data.

param
size the uncompressed size in bytes
exception
IllegalArgumentException if the specified size is less than 0 or greater than 0xFFFFFFFF bytes
see
#getSize()

	if (size < 0 || size > 0xFFFFFFFFL) {
	    throw new IllegalArgumentException("invalid entry size");
	}
	this.size = size;
    
public voidsetTime(long time)
Sets the modification time of the entry.

param
time the entry modification time in number of milliseconds since the epoch
see
#getTime()

	this.time = javaToDosTime(time);
    
public java.lang.StringtoString()
Returns a string representation of the ZIP entry.

	return getName();