Reading Archives (zip/jar etc)

I am currently trying to figure out the best way to read an XML file and a series of images locally with a J2ME application. Ideally I want these to be read in as a single entity using the file browser on JSR-75 capable devices. I have been looking for ways to implement zip compatibility and have come accross solutions such as the GZIP implementation by TinyLine. The problem is that; as far as I know you can only read in single files within the archive with such solutions.
Does anyone know of any other ways in which I could achieve this? It doesnt matter what type of archive the files are in. The goal is to simply have a single file containing the XML / images.
Thanks,
Dan.

Hi!
Here's a method I use to read images from a JAR-archive:
     * Method to load icons.
     * @param location     The location of the image we want to load.
     * @return icon          The icon we just loaded.
    public ImageIcon loadImage(String location) {
         ClassLoader loader = getClass().getClassLoader();
         // Null url for security
          URL url = null;
          try {
               // Try to load the file
               url = loader.getResource(location);
          } catch(Exception e) {
               e.printStackTrace();
          // Create a image icon from file
          ImageIcon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(url));
          return icon;
     }The parameter location could be: images/MyImage.jpg if you have a directory inside the archive named images and a file called MyImage.jpg.
Hope it helped!
/Andrew

Similar Messages

  • Dynamically loading and registering JDBC driver from an archive (zip - jar)

    I'm programming an JDBC driver tester.
    I have to load dynamically any driver from an archive (jar or zip) after the user uploaded it.
    I think i did it well with my ClassLoader, i can get an instance of the driver and use any method like (getMinorVersion()) but when i registering it fail.
    There is no error but the driver is not registered.
    I rode the DriverManager log (with his logwriter) and he says :
    skipping: driver[className=oracle.jdbc.driver.OracleDriver,oracle.jdbc.driver.OracleDriver@5439fe]
    skipping: driver[className=oracle.jdbc.driver.OracleDriver,oracle.jdbc.driver.OracleDriver@2b7db1]
    (two times, it looks curious isn't it ?)
    This is a part of my code :
    Driver pilote = (Driver)Class.forName(driverClass.getName(), true,this).newInstance();
    System.out.println("Minor Version = "+ pilote.getMinorVersion());
    PrintWriter printwriter = new PrintWriter(new OutputStreamWriter(System.out));
    DriverManager.setLogWriter(printwriter);
    DriverManager.registerDriver(pilote);
    System.out.println("Driver registered\n");

    I have made a simple test :
    public static void main(String[] param)
    System.out.println("Loading Driver from JAR ...");
    try
    File jar = new File("c://mbm//drivers//oracle.jar");
    URL aurl[] = {jar.toURL()};
    URLClassLoader urlclassloader = new URLClassLoader(aurl, ClassLoader.getSystemClassLoader());
    Class.forName("oracle.jdbc.driver.OracleDriver", true, urlclassloader);
    PrintWriter printwriter = new PrintWriter(new OutputStreamWriter(System.out));
    DriverManager.setLogWriter(printwriter);
    Enumeration listDriver = DriverManager.getDrivers();
    System.out.println("[---------Drivers-----------]");
    while (listDriver.hasMoreElements())
    Driver driver = (Driver) listDriver.nextElement();
    System.out.println("->> "+driver.getClass().getName());
    catch (MalformedURLException e)
    e.printStackTrace();
    catch (ClassNotFoundException e)
    e.printStackTrace();
    This displays that :
    Loading Driver from JAR ...
    skipping: driver[className=oracle.jdbc.driver.OracleDriver,oracle.jdbc.driver.OracleDriver@9ec21d67]
    [---------Drivers-----------]
    D:\www\tomcat\webapps\mbm\WEB-INF\classes>
    I think there is in this case only one instance

  • NetBeans mount archive (.zip, .jar) won't finish

    Trying to mount src.zip from J2SE so I can step into the code during a debugging session, but it's not working:
    1. Select Mount Filesystem
    2. Select 'Archive'
    3. Browse to C:\Program Files\j2sdk_nb\j2sdk1.4.2
    4. Select src.zip, which is then plugged into the archive name text area
    5. The 'Finish' button remains greyed out.
    Using NetBeans V3.51 on Win98 SE. Any solutions? Thanks in advance.

    OK, I figured it out. Even though NetBeans says it supports .zip files for mounting, but it doesn't. Renamed src.zip to src.jar and everything fine.
    I should be able to reward myself with the 10 Duke Dollars, eh lol

  • How do I protect my JNLP, my JARs etc. (with Basic Authentication)???

    hi all,
    i know that there is a FAQ ( [see here|http://lopica.sourceforge.net/faq.html#obfuscate] ) answering a related question with "You can use an obfuscator...". ok, but is there really no other solution?
    this is the simplified folder structure of my application on the server:
    [application]
      [etc]
        xyz.xml
      [jars]
        myapp.jar
      launch.jnlp
    website.jsp
    initial start and basic authentication:*
    my first idea was to secure everything underneath "application" with basic authentication via my web.xml (yes, i'm aware of the security concerns). this means everybody can access my website (here: website.jsp) which contains a start button that links to "launch.jnlp". as soon as the user clicks on it, the browser opens its standard authentication dialog since launch.jsp is in a protected area. after entering the correct credentials the jnlp-file is downloaded and java web start takes over control. first of all it seems as it tries to access the same jnlp-file again (??? --> probably in order to check for changes in the jnlp file --> this is certainly not the case for the initial startup) and then wants to download the relevant jar (myapp.jar). because both resources are protected jws opens its own basic authentication dialog where i have to enter the same credentials the second time. as far as i know, there is no solution to pass the credentials between the browser and the jvm.
    second start and basic authentication:*
    if the user starts my application for the 2nd, 3rd, ... time via desktop-link (set in jnlp-file) there is no need for accessing my website with a browser. therefore only the authentication dialog of jws gets displayed. so far, so good!
    and now the actual problem:*
    during runtime my application (signed with verisign certificate and having all permissions) uses commons-vfs and commons-httpclient to access resources on the same server (e.g. etc/xyz.xml). since they're underneath the protected "application" directory as well, my application needs the same credentials the user already entered in the authentication dialog of jws. now i could retrieve these credentials by calling Authenticator.requestPasswordAuthentication() within my application and passing them to vfs and httpclient. however, doing so opens up jws' authentication dialog again. grrr!!! is there a way to prevent this?
    related thougts:*
    i know i could disable jws' default Authenticatior and set my own Authenticator which might be able to return already entered credentials without opening the dialog a second time. however, it seems that even with <property name="javaws.cfg.jauthenticator" value="none" /> jws still opens its own dialog when acessing the JNLP file and the relevant JARs during the startup/download phase. of course, who else if not jws could handle that phase? my application might not even be downloaded at this point. so i guess setting my own Authenticator would not be a solution either (at least not if i want to secure my jnlp and my jars, too). quite the contrary, it would have to open another dialog... :-(
    my current solution:*
    for the moment i use jws' default Authenticatior which allows me to easily protect all my stuff on the server side (jnlp, jar, etc). i can live with the two login dialogs at the initial startup. and instead of querying the credentials from jws' default Authenticatior at runtime, i set two system properties for username and password in the (protected) jnlp-file, query them at runtime and hand it to vfs and httpclient. this prevents the 2nd (or 3rd) dialog but is definitely not a great solution. most of all i'm not happy with the fact that this somehow "destroys" the container-based security advantage of easily configuring authorized users via a separate mechanism e.g. tomcat-users.xml. now there has to be one master-password that has to be set in the jnlp-file! grrr!
    a possible alternative:*
    i'm not sure but would it be better to secure everything with form-based authentication on the website, and dynamically generate username and password into the jnlp-file? but what happens when the admin changes the password on the server and the user starts its application via desktop-link??? in case of basic authentication i think jws would popup the login dialog again. however, if i use the old username and password generated into the jnlp it won't work. i think the user then has to access the website again. this is not good at all! :-(
    the only real solution:*
    should i write a small application which can be downloaded by everybody and on startup queries the user's credentials, validates them with the help of our server, and uses the javax.jnlp-api to download the secured JARs of my real application? this seems so much overkill! does anybody have experiences with this approach? how difficult is it to implement the whole download/update stuff with javax.jnlp?
    WHAT HAVE I MISSED???
    AM I COMPLETELY WRONG???
    WHAT IS THE EASIEST WAY???
    AND WHAT IS THE BEST WAY???
    thank you so much,
    stephan

    Not sure, whether I understood correctly, what you wanna do - but up to now I can't see any problem.
    if you have a structure like this:
    /ctxroot/
           launch.jnlp
           /app/
               *.jar
               *.whateveryou may use in your web.xml:
         <servlet>
              <servlet-name>JnlpDownloadServlet</servlet-name>
              <servlet-class>jnlp.sample.servlet.JnlpDownloadServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>JnlpDownloadServlet</servlet-name>
              <url-pattern>*.jnlp</url-pattern>
              <url-pattern>/app/*</url-pattern>
         </servlet-mapping>
         <security-constraint>
              <web-resource-collection>
                   <web-resource-name>Application</web-resource-name>
                   <url-pattern>/app/*</url-pattern>
                   <http-method>GET</http-method>
                   <http-method>POST</http-method>
              </web-resource-collection>
              <auth-constraint>
                   <role-name>bla</role-name>
                   <role-name>fahsel</role-name>
              </auth-constraint>
              <user-data-constraint>
                   <transport-guarantee>CONFIDENTIAL</transport-guarantee>
              </user-data-constraint>
         </security-constraint>
         <security-constraint>
              <web-resource-collection>
                   <web-resource-name>Subscription</web-resource-name>
                   <url-pattern>*.jnlp</url-pattern>
              </web-resource-collection>
              <user-data-constraint>
                   <transport-guarantee>CONFIDENTIAL</transport-guarantee>
              </user-data-constraint>
         </security-constraint>
         <login-config>
              <auth-method>BASIC</auth-method>
              <realm-name>whatever-realm</realm-name>
         </login-config>
         <security-role><role-name>bla</role-name></security-role>
         <security-role><role-name>fahsel</role-name></security-role>
    ...Than you may use the Service stuff like:
         BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
         URL codeBase = bs.getCodeBase();
         URL pu = new URL(codeBase.toString() + "whatever.bla");
         HttpURLConnection res = (HttpURLConnection) pu.openConnection();
         res.setInstanceFollowRedirects(true);
         res.setRequestMethod("GET");
         res.setConnectTimeout(10 * 60 * 1000);
         res.connect();
         String enc = res.getContentType();
    ...Where is the problem? If you wanna intercept certain "calls" to an app resource, just use a filter, which decides, whether to answer the request directly by itself or to pass it to the JnlpDownloadServlet ...

  • ERROR:Could not read archive file - during Processing Base System Part 2

    Hi there,
    What I have:
    * I have problem with installation of the Mac OS X Panther v10.3 on iMac.
    * I have 3 original CDs (black with silver X).
    What I did:
    * I made new 1 partition and formated disk as Mac OS Extended (Journaled) over the Disk Utility in the first CD as normal without additional options (if I tried to format disk with zero all data and 8 way random write format after 3 days computer freeze)
    * I verified disk over this utility - that was ok - HFS volume verifed.
    * Then I restarted the computer and ran installation from this first CD
    What happened:
    * installation did not finish, because there were some problems during installation process.
    * i tried to customize installation just for essential work (without other languages support, printers etc), but it was still the same problem
    Installation log:
    After I choosed installation type, there was first error, but it did not look like important.. - root: bootstraplookup(): unknown error code
    Checking your installation disk - OK
    Preparing disk - OK
    Preparing base 1 and 2 - OK
    Other preparing.. - OK
    Processing Base System Part 1 - OK
    Processing Base System Part 2
    ==
    ERROR:Could not read archive file. - pax: Invalid header, starting valid header search.
    ERROR:Could not read archive file. - pax: Invalid header, starting valid header search.
    last message repeated 2 times
    ERROR:Could not write file. - pax: WARNING! These patterns were not matched:
    Some files for Essentials may not have been writen correctly.
    root: Installer[108] Exception raised during posting of notification. Ignored. exception: Some files for Essentials may not have been written correctly. (code 1)
    Install Failed
    Error detected
    Name: NSGenericException
    Reason: Some files for Essentials may not nave been written correctly. (code 1)
    ==
    It seems like a problem with reading some data from the CD, but during the installation checking of disk was ok.. maybe it can be problem with the cd-rom..? Or problem with data on cd-rom - I mean bad archive file..? But it is original CD.. What do you think??
    Thank you!

    Tomas,
    On THIS Page, locate your iMac model.
    From the Documents column, click on the appropriate number link.
    Using the info in the document that opens, locate the serial number of your iMac.
    On THIS Page, in the text field for Search Tech Specs, enter that serial number.
    Click on the model of iMac that appears.
    Post a link to the page that opens, or post the info requested below.
    Exactly which model iMac is it?
    What is the Processor speed?
    What size is the Hard Drive?
    How much Memory is installed?
    What type of internal Optical Drive does it have?
    Which version of OS, was the original Installed Software?
    ali b

  • Flash player won't work or download. It says it no longer supports power pcs. I am running 10.5.8 on my ibook G4. Seem to have tried everything. i.e. chrome, firebird, archived flash players, etc. All not supported. Any insight???

    Flash player won't work or download. It says it no longer supports power pcs. I am running 10.5.8 on my ibook G4. Seem to have tried everything. i.e. chrome, firebird, archived flash players, etc. All not supported. Any insight??? It started when I tried to upgrade current flash player and it said I needed to uninstall current version, which I did, and then it wouldn't download the current one giving me the not supported story! Please help!!!!!!

    Hi Andy, that is correct, they don't support PPC Macs anymore.
    You should first uninstall any previous version of Flash Player, using the uninstaller from here (make sure you use the correct one!):
    http://kb2.adobe.com/cps/865/cpsid_86551.html#prob1=uninst,os=m10.6,
    Download this if you haven't...
    http://fpdownload.macromedia.com/get/flashplayer/installers/archive/fp10.1.102.6 4_and_9.0.289.0archive.zip
    Once downloaded if it doesn't unzip automatically the double click on that file.
    Look for the fp10.1.102.64_and_9.0.289.0archive folder, open it, look for the Flash Player 10.1.102.64 folder & open and look for 101r10264 folder & open it, double click on the flashplayer101r102_64_ubmac.dmg file, choose the Install Adobe Flash Player file to install... they don't make it easy!
    Or smaller here...
    http://dl.dropbox.com/u/450421/flashplayer10_1r82_76_ub_mac%20copy.dmg.zip
    Stand alone player...
    http://dl.dropbox.com/u/450421/LastFlashPPC.zip
    Or free 3rd party...
    http://www.wimpyplayer.com/products/wimpy_standalone_flv_player.html

  • OBIEE Dev VM Install Issue:Cannot open archive "ARCHIVE.zip" as archive

    All,
    I downloaded all eleven files for the OBIEE 11.1.1.6.2 BP1 - Sample Application (V207).
    I checked the MD5 Sum of the first two files and the MD5 Sums match, however when I use 7zip to extract the files, I get an error that says: Cannot open archive "ARCHIVE.zip" as archive
    Has anyone encountered this issue? I verified that the files are not read-only and that they are not "blocked" by Windows.
    I am running 64-bit Windows 7 Home Edition on a Dell laptop.
    I encountered this error on two separate archives with correct MD5 Sums.
    Any help would be appreciated! Thanks!
    Nathan

    Hi,
    I got the same problem. Have you found any solution for this? Thanks.

  • Permission to open archived, .zip files

    What Application or utility allows a "user" to open an archived .zip file that they have made themselves. I can open an archived .zip file as the administrator but my user that has limitations cannot open one that they have made so I want to give them the "permission" to open the archived file.
    Thank you, Linda

    Hi Joe, and a warm welcome to the forums!
    It's quite acceptable to start a new topic of your own, feel free to start a new topic to attract more helpers to your particular situation, as not many helpers look at Solved/Answered Topics for people needing help, here's a link if as is often the case, it's hard to find out where to do it...
    http://discussions.apple.com/post!default.jspa?forumID=748
    Do you mean Keychain Password?

  • Error When reading Archived XML Message

    I am having the next issue reading the archived messages (error msg: Could not find message in archive).
    can anybody help me.
    my problem is the same that this topic.
    Problems with reading archived Messages
    Any suguest please?
    Regards
    RP.

    Hi Sudharshan/Cornelius,
    Thanks for your support. I am glad that my inputs were helpful.
    Shudarshan, what do you mean by the process?
    If you are talking about the arhiving process, then it is very huge topic
    in itself. You can find that in help.sap.com.
    But in this specifc case, what happens is that to made archiving possible,
    there are different objects involved. e.g Archiving object, read write methods, Infostructures etc. In our case, the infostructure objects is in "inactive" state. Which seems to be a mistake from the SAP side. All we need to do is activate that object. And we are done.
    Actually I also had the same issue, and I found this thread with few threads with no answer :-(.  Then I just went deep into it and I found this "mistake"
    It is just yesterday, when I cracked this issue by myself. I decided to put in the thread.
    again I am happy my efforts were useful to you people.
    Thanks and Regards,
    Arundeep Singh
    001-416-828-1307

  • Applet archive=my.jar

    I have an applet with a number of inner classes and some resource files. When I run the applet with all the .class files and the resources in the same directory, all runs fine. My applet html includes:
    <applet>
    code="MyApplet.class" archive="myJar.jar"
    </applet>
    When I package the class files and the resource files into myJar.jar, all as one flat directory, and the jar is in the same directory as the MYApplet.html file, I get a ClassNotFound exception when I load the applet.
    My classpath includes theAppletDirectory\myJar.jar. Many hours of restarting tomcat, repackaging the jar, and resetting the classpath have not yielded results. Any hints?

    http://forum.java.sun.com/thread.jsp?forum=421&thread=485003
    I posted this question more appropriately to the applet forum; sorry for the cross post.

  • How to block unnecessary page pop up like mac keeper, zip cloud etc?

    how to block unnecessary page pop up like mac keeper, zip cloud etc?

    Hi. if you see these pop ups this may be the symptom of adware. Download, open adwaremedic dmg file ,  and run it by clicking “Scan for Adware” button  to remove adware.
    Once done, quit AdwareMedic and restart your mac: http://www.adwaremedic.com/
    Install adblock for your browser: https://adblockplus.org/

  • Bt Cloud only downloading 22 Byte Archive zips?

    I've got a few largish files stored on BT Cloud - everything has been fine until today.
    Now, on clicking a file to download... I only get a 22 byte archive zip file - not the file in question?
    Is this a known bug, that's just surfaced?
    Many thanks in advance,
    Bizarreo

    Hi bizarreo,
    Did you manage to get this sorted? If you need any help please use the 'contact the mods' link in my forum profile under the 'about me' section to send in your details and we can raise an issue with the Cloud team.  You can find the link by clicking on my username.
    Thanks
    Neil
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)
    If someone answers your question correctly please let other members know by clicking on ’Mark as Accepted Solution’.

  • Read a zip file from Application server.

    Hi,
    Is there a way to read a zip file from the applicatoin server to internal table in ABAP program?  The operation system is running MS windows server.  The zip file contains only 1 text file.  I tried to use open dataset 'uncompress', and use read dataset, but read dataset gave me sy-subrc = 4.  Any feedback is greatly appreciated.
    Thanks.

    hi,
    to convert xstring to text you can use this:
    DATA unzipped_data TYPE xstring.
    DATA text_data TYPE string.
    DATA conv_x2c TYPE REF TO cl_abap_conv_in_ce.
    conv_x2c = cl_abap_conv_in_ce=>create( ).
    conv_x2c->convert( EXPORTING input = unzipped_data IMPORTING data = text_data ).
    moreover, if you want to split your text at "end of line" (CR LF in microsoft windows) into lines:
    DATA text_lines TYPE TABLE OF string.
    SPLIT text_data AT cl_abap_char_utilities=>cr_lf INTO TABLE text_lines.

  • OIM 11g R1 Unable to read third part jars

    Hi All,
    Please help me as i'm having tough time in reading(instantiating classes from third party jar) the third party jars withing my code. I have created an adapter, which will send message to a remote JMS queue and for which i need to establish connection with the JMS queue (i use com.ibm.mqjms.jar ). I have placed this com.ibm.mqjms.jar Jar in /server/ThirdParty folder and the classes were not picked up. I have placed my adapter jars in the Java tasks folder and it reads perfectly.
    but,t eh problem is in reading this ThirdPart Jars. I have tried by placing the jar in ThirdParty folder and it did not work. then, i removed the jar from Third party folder and uploaded the jar using UploadJars utility as ThirdParty jar. It still have issue reading this.
    I have performed PurgeCache.sh ALL and also restarted the managed server many times.
    Please help as i'm clueless and my environment is OIM 11g R1 in Linux OS.
    Thanks,
    Srini

    can you rejar this .jar file and then import it in MDS. see if the NoClassDefFoundError still occurs

  • How to Read Archived Messages in XI

    HI
    I am facing problem in reading archived XI messages.
    i am trying to read messages archived in November. Can please anyone explain me how to read this.
    Thanks in Advance
    Regards
    Swapnil

    Hi Swapnil,
    >>I am facing problem in reading archived XI messages.
    please let me know the Exact problem what u r facing?
    i felt that, u are unable to findout the output file in the month of novmber which was archived.
    while configuring the adapter we have Archive mode.
    once u select the archive mode,
    asking for the archive directory and followed by ADD time stamp.
    it mean's the output file as well as archived file generated with the following name.
    i.e filename+Timestamp(yyyymmdd-hh:mm:ss-msec).
      eg: XI_ouput20080118-190544-843
    award the points if it really help to you.
    Reagrds
    Mahesh.

Maybe you are looking for

  • CTI OS desktop client freezes after release of transferred call

    Using CTI OS desktop v7.5(9), UCCE 7.5(9), Endpoint is CIPC 8.6.3 on CUCM 7.1.3 ACD call received by Agent 1 on ext 1111 Agent 1 transfers to 1112 Agent 2 answers transferred call on 1112 using answer call button. Agent 2 disconnects using Release Ca

  • I want to login as administrator but I have for got my password how to I fine it

    I want to login as administrator on my mac book pro but I have forgot my password how do I fine it'? I want to down load  so x Maverick can a anyone help me thank you Kath

  • Create Group Email Account in OIM

    Hi, I have a requirement to create Group Email Account in AD from OIM. I am able to create Group Accounts in AD using the OOB Resource Object "AD Group". Though I am not sure how to mail enable the group Account from OIM. Please give me ur valuable s

  • IDVD Project Archive portability

    I just had occasion to update a DVD that I had originally created with iDVD 3 in 2003. I had saved the original project and all associated files on an external Firewire hard drive. I had no problems opening the project in iDVD 4 (I did have to point

  • Every iPhone update fails and send phone into recovery mode

    I'm getting extremely frustrated, and I know I'm not the only one after searching Google, that every time an update is released for the iPhone mine fails and goes into recovery mode then works the second time. It has happened on every release of iPho