Java.util.jar.JarEntry class in Java

This class is used to represent a JAR file entry.
Constructors :

  • JarEntry(JarEntry je) : Creates a new JarEntry with fields taken from the specified JarEntry object.
  • JarEntry(String name) : Creates a new JarEntry for the specified JAR file entry name.
  • JarEntry(ZipEntry ze) : Creates a new JarEntry with fields taken from the specified ZipEntry object.

Methods:

  • Attributes getAttributes() : Returns the Manifest Attributes for this entry, or null if none.
    Syntax :public Attributes getAttributes()
                             throws IOException
    Returns:
    the Manifest Attributes for this entry, or null if none
  • Certificate[] getCertificates() : Returns the Certificate objects for this entry, or null if none.
    Syntax :public Certificate[] getCertificates()
    Returns:
    the Certificate objects for this entry, or null if none.
  • CodeSigner[] getCodeSigners() : Returns the CodeSigner objects for this entry, or null if none.
    Syntax :public CodeSigner[] getCodeSigners()
    Returns:
    the CodeSigner objects for this entry, or null if none.

Methods inherited from class java.util.zip.ZipEntry
clone, getComment, getCompressedSize, getCrc, getExtra, getMethod, getName, getSize, getTime, hashCode, isDirectory, setComment, setCompressedSize, setCrc, setExtra, setMethod, setSize, setTime, toString
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait



Note: The programs will not run on online IDE as they are not able to read file
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

//Java program demonstrating JarEntry method
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
class JarEntryDemo
{
    public static void main(String[] args) throws IOException 
    {
        FileInputStream fis = new FileInputStream("codechecker.jar");
        JarInputStream jis = new JarInputStream(fis);
        JarEntry je=jis.getNextJarEntry();
  
        PrintStream out = System.out;
  
        //illustrating getAttributes
        out.println(je.getAttributes());
  
        //illustrating getCodeSigner
        out.println(je.getCodeSigners());
  
        //illustrating getCertificates
        out.println(je.getCertificates());
    }
}

chevron_right


Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

//Java program demonstrating JarEntry method
package java.util.jar;
    
 import java.io.IOException;
 import java.util.zip.ZipEntry;
 import java.security.CodeSigner;
 import java.security.cert.Certificate;
  
 public class JarEntry extends ZipEntry
 {
    Attributes attr;
    Certificate[] certs;
    CodeSigner[] signers;
   
    public JarEntry(String name) 
    {
        super(name);
    }
   
    public JarEntry(ZipEntry ze) 
    {
        super(ze);
    }
    
    public JarEntry(JarEntry je)
    {
        this((ZipEntry)je);
        this.attr = je.attr;
        this.certs = je.certs;
        this.signers = je.signers;
    }
    
    public Attributes getAttributes() throws IOException 
    {
      return attr;
    }
    
    public Certificate[] getCertificates() 
    {
        return certs == null ? null : (Certificate[]) certs.clone();
    }
    
    public CodeSigner[] getCodeSigners() 
      
    {
        return signers == null ? null : (CodeSigner[]) signers.clone();
    }
}

chevron_right


This article is contributed by Nishant Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.