How do I decompress a string in java?

The string is compressed with zip and is encoded base64.
I decocoded the string, I copied the string to a zip file and I tryed to decompress using the sample script(class UnZip2) from here: http://java.sun.com/developer/technicalArticles/Programming/compression/.
The error is
java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at UnZip2.main(UnZip2.java:12)
Decompression works with other archives.
I know the string is ok because the server where I send it makes a succesful decompression.

user10878887 wrote:
The string is compressed with zip and is encoded base64.
I decocoded the string, I copied the string to a zip file Expanding on the other reply...
It is likely that the problem is that the contents of the file incorrect.
Your statement suggests that you wrote the base64 string to the file. That would be wrong.
You needed to decode from base64 and then write the bytes to the file.

Similar Messages

  • How do I compress a string with  java.util.zip - not a file ?

    How do I compress a string with java.util.zip?
    Is possible to compress something else except a file?

    Of course, compression works on bytes, not some higher level constructs like Strings or files.
    You can use the ZipOutputStream or DeflaterOutputStream for compression.
    And the javadoc for Deflater even has a code example of compressing a String.
    Edited by: Kayaman on May 22, 2011 5:04 PM

  • How to convert number to string in java

    hi how can i convert number to string in java
    something like
    public void Discription(Number ownerName){
    String.valueOf(ownerName);Edited by: adf009 on 2013/04/08 7:14 PM

    Yet another way of doing it is: ownerName.toString().
    If you are working in and IDE such as Netbeans or Eclipse, type a period after the object name. Wait a second or so. Eclipse/Netbeans Intellisense will show you a list of functions that object provides that you can choose from. toString() is one of them.

  • How can I decompress lzh file in Java?

    I got an lzh file, and i want to decompress it in my Java program.
    How can I do it?
    Thanks.

    I don't know if any software exists for this in Java. It is certainly not part of the JDK.
    The LZH format is described here: http://www.osirusoft.com/joejared/lzhformat.html
    If you want you could write your own LZH decompressor.
    Jesper

  • How to get String form java JTable row?

    Hello everybody,
    Can anybody tell me how to get value as String form java JTable row?

    I found solution:
            table.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent evt) {
                    if (evt.getClickCount() == 2){
                        int col = table.getSelectedColumn();
                        int row = table.getSelectedRow();
                        String tableUrl = ((String)table.getModel().getValueAt(row, col));
                        ur.openUrl(tableUrl);
            });

  • Compress and decompress in string

    hai
    how to compress the large string in java ? after string (compress string )how to store in database . then the jave prog read string (compress string) form database how to decompressed ?
    pls give me advice
    or useful web like
    with regards
    kumar

    What is wrong with the answer(s) giving in the past thread?
    You could use the StringReader/ByteInputStream + ByteOutpuStream + ( java.util.zip or GZIPOutputStream ).

  • How can i encrypt an ddecrypt a string using java

    hai,
    can anybody know how to encrypt and decrypt a string using java..
    please if anybody help me with a small example and with code
    thanks
    ravi chandra

    hi,
    of course there are better ways to crypt your code, but the following 2 functions do their job....
    as far as i know java has an own api for crypting stuff.
    private String GetEncryptedString(String aCryptedString)
    String result = "";
    String str = aCryptedString;
    int[] asciiArray = new int[str.length()];
    for(int i = 0; i < asciiArray.length; i++)
    asciiArray[i] = (int)str.charAt(i);
    char tempChar = (char)(asciiArray[i]+3);
    result = result+tempChar;
    return result;
    private String GetDecryptedString(String aString)
    String result = "";
    String str = aString;
    int[] asciiArray = new int[str.length()];
    for(int i = 0; i < asciiArray.length; i++)
    asciiArray[i] = (int)str.charAt(i);
    char tempChar = (char)(asciiArray[i]-3);
    result = result+tempChar;
    return result;
    andi

  • How to search for upper/lower case using string using JAVA!!!?

    -I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears.
    -I also have to use a JOptionPane.showMessageDialog() to tell the user how many upper and lower case e's were in the string.
    -This will be repeated until the user types the word "Stop". 
    please help if you can
    what i have so far:
    [code]
    public class Project0 {
    public static void main(String[] args) {
      String[] uppercase = {'E'};
      String[] lowercase = {'e'};
      String isOrIsNot, inputWord;
      while (true) {
       // This line asks the user for input by popping out a single window
       // with text input
       inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
       if ( inputWord.equals("stop") )
        System.exit(0);
       // if the inputWord is contained within uppercase or
       // lowercase return true
       if (wordIsThere(inputWord, lowercase))
        isOrIsNot = "Number of lower case e's: ";
       if (wordIsThere(inputword, uppercase))
         isOrIsNot = "number of upper case e's: ";
       // Output to a JOptionPane window whether the word is on the list or not
       JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
    } //main
    public static boolean wordIsThere(String findMe, String[] theList) {
      for (int i=0; i<theList.length; ++i) {
       if (findMe.equals(theList[i])) return true;
      return false;
    } // wordIsThere
    } // class Lab4Program1
    [/code]

    So what is your question? Do you get any errors? If so, post them. What doesn't work?
    And crossposted: how to search for upper/lower case using string using JAVA!!!?

  • How to deocde a Base64 String in Sun Java ME SDK 3.0(Urgent)

    Hi there, I want to decode a base64 encoded String in Sun Java ME SDK 3.0 , but cant find any solution to this, after doing search related to this I found that it's very easy to decode a Base64 string in Sun Wireless Toolkit 2.5 using following code:
    import com.sun.midp.io.Base64;
    byte[] data = Base64.decode(EncodedString);
    But I found that it's not possible in Java ME SDK as com.sun.midp.io.Base64 is not available there, anyone please give me some alternative of above code so that I can decode a Base64 String in Java ME SDK.
    Eagerly waiting for the possible solution.

    Can you please let us know as how you solved the problem? Since we are developing a blackberry app, we found base64 class for blackberry development. We have plans of doing the same in android, not sure whether they have this. As long as we have generic base64 class that can be used in any client device, that would be great. I did a lot of research and could not fine. Please give us the solution.

  • How to get af:commandbutton id in java code when it is triggered?

    Hi All
    In my application's homepage, I am using 2 af:commandbuttons and each using action attribute to call a method. Both are calling the same method, and based on its id, it should perform different operations. Could anyone please tell me how to get command buttons id in java code, when it is triggered.
    Regards
    Venkat

    Venkat,
    why not call different methods from each button?
    public String actionButton1()
    return doAction("button1");
    public String actionButton2()
    return doAction("button2");
    public String doAction(String aBuuton)
    if ("button1".equalsIgnoreCase(aButton))
    // do work for button 1
    return "abc";
    }else {
    // do work for button 2
    return "abc";
    }Now you user actionbutton1 for the first button and actionButton2 for the second.
    Or you directly implement two different methods in the bean and call each one directly from the button.
    Timo

  • How can i execute Spaces API in java main class?

    Hi
    I am able to execute Spaces API through portal application. However if i try to execute it in java main class, its throwing an exception
    "SEVERE: java.io.FileNotFoundException: .\config\jps-config.xml (The system cannot find the path specified)"
    oracle.wsm.common.sdk.WSMException: WSM-00145 : Keystore location or path can not be null or empty; it must be configured through JPS configuration or policy configuration override.
    How can i set this path, so that i can execute Spaces API from java main class.
    Need this main class to configure in cron job, to schedule a task.
    Regards
    Raj

    Hi Daniel
    Currently i have implemented create functionality in my portal application using Spaces API, which is working fine. Now the requirement is, i need to implement a "Cron Job" to schedule a task, which will execute to create space(for example once in a week). Cron job will execute only the main method. So I have created java main class, in which I have used Spaces API to perform create space operation. Then it was giving exception.
    Later I understood the reason, as I am executing the Space API with a simple JSE client, its failing since a simple java program has no idea of default-keystore.jks, jps-config.xml, Security Policy. Hence i have included those details in main class. Now I am getting new error,
    SEVERE: WSM-06303 The method "registerListener" was not called with required permission "oracle.wsm.policyaccess"
    For your reference i have attached the code below, please help. How can i use Spaces API in java main method(i mean public static void main(String[] args) by giving all required information.
        public static void main(String[] args) throws InstantiationException,
                                                      GroupSpaceWSException,
                                                      SpacesException {
            Class2 class2 = new Class2();
            GroupSpaceWSContext context = new GroupSpaceWSContext();
            FactoryFinder.init(null);
            context.setEndPoint("http://10.161.226.30/webcenter/SpacesWebService");
            context.setSamlIssuerName("www.oracle.com");
            context.setRecipientKeyAlias("orakey");
            Properties systemProps = System.getProperties();
            systemProps.put("java.security.policy","oracle/wss11_saml_or_username_token_with_message_protection_client_policy");
            systemProps.put("javax.net.ssl.trustStore","C:\\Oracle\\Middleware11.1.7\\wlserver_10.3\\server\\lib\\cacerts.jks");
    systemProps.put("oracle.security.jps.config","C:\\Oracle\\Middleware11.1.7\\user_projects\\domains\\workspace\\system11.1.1.7.40.64.93\\DefaultDomain\\config\\fmwconfig\\jps-config.xml");
            systemProps.put("javax.net.ssl.keyStore",C:\\Oracle\\Middleware11.1.7\\user_projects\\domains\\workspace\\system11.1.1.7.40.64.93\\DefaultDomain\\config\\fmwconfig\\consumer.jks");
            systemProps.put("javax.net.ssl.keyStorePassword", "Test12");
            System.setProperties(systemProps);
            GroupSpaceWSClient groupSpaceWSClient;
            try {
                groupSpaceWSClient = new GroupSpaceWSClient(context);
                System.out.println("URL: " +
                                   groupSpaceWSClient.getWebCenterSpacesURL());
                //delete the Space
                List<String> groupSpaces = groupSpaceWSClient.getGroupSpaces(null);
                System.out.println("GroupSpaces:: " + groupSpaces.size());
            } catch (Exception e) {
    Regards
    Raj

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • How to get a global string value to be the value of a JSF output box?

    im useing Jdeveloper 10 i have made a JSF, JSP page i have a backing bean for that page. in there i have made a global value:
    private string test = "TESTING"these codes have been generated:
    public void setTester(HtmlOutputText outputText6) {
    this.tester = outputText6;
    public HtmlOutputText getTester() {
    return tester;
    }now how do i put test as the output text?

    That wouldn't even compile. HtmlOutputText isn't a subclass of String (heck, java.lang.String is a final class).
    Two ways to solve this: 1) use HtmlOutputText#setValue() in the constructor or initialization block of the bean or even by lazy loading in the getter. Just create a String getter and use it in the value attribute of the outputText element in the JSF page.

  • How do I create a Principal in Java

    How can I create a Principal in Java that can later be added to Websphere's Trust Map via a JAAS authentication module?
    Below code is not working as it throws the following exception:
    "Caused by: com.ibm.websphere.security.auth.WSLoginFailedException: javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error...."
    class PrincipalExt implements Principal, java.io.Serializable {
        private String userName;
        public PrincipalExt()
        public PrincipalExt(String userName) {
            setName(userName);
        public void setName(String name)
            this.userName = name;
        public String getName()
            return userName;
    Then, once I have an instance
        public void login() throws LoginException {
            PrincipalExt aPrincipal = new PrincipalExt();
            aPrincipal.setName("someUserID");
            trustMap.put("com.ibm.wsspi.security.common.auth.module.IdentityAssertionLoginModule.trusted", true);
            trustMap.put("com.ibm.wsspi.security.common.auth.module.IdentityAssertionLoginModule.principal", aPrincipal);

    Download JFreeChart and give it a try:
    http://www.object-refinery.com/jfreechart/index.html
    JFreeChart is distributed for free, including the complete source code (subject to the GNU LGPL).
    Regards,
    Dave Gilbert
    JFreeChart Project Leader

  • How to execute a shell command in java?

    here, my environment is redhat 7, jdk 1.5.
    i don't know how to use the shell command in java.
    i want to use this function:
    #include <stdlib.h>
    int system(const char * string);
    please give me some ideas. and Thank you so much if coming with a little demo.

    i know i should use JNI. because i have to use C lib.
    but i have already use JNI to wrapper the original code the cpp code and java code is :
    //: appendixb:UseObjImpl.cpp
    //# Tested with VC++ & BC++. Include path must
    //# be adjusted to find the JNI headers. See
    //# the makefile for this chapter (in the
    //# downloadable source code) for an example.
    #include <jni.h>
    #include <stdlib.h>
    extern "C" JNIEXPORT void JNICALL
    Java_UseObjects_changeObject(
    JNIEnv* env, jobject, jobject obj) {
    jclass cls = env->GetObjectClass(obj);
    jfieldID fid = env->GetFieldID(
    cls, "aValue", "I");
    jmethodID mid = env->GetMethodID(
    cls, "divByTwo", "()V");
    int value = env->GetIntField(obj, fid);
    printf("Native: %d\n", value);
    env->SetIntField(obj, fid, 6);
    env->CallVoidMethod(obj, mid);
    value = env->GetIntField(obj, fid);
    system("preprocess -path sha.c");
    printf("Native: %d\n", value);
    } ///:~
    //: appendixb:UseObjects.java
    // From 'Thinking in Java, 2nd ed.' by Bruce Eckel
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    class MyJavaClass {
    public int aValue;
    public void divByTwo() { aValue /= 2; }
    public class UseObjects {
    private native void
    changeObject(MyJavaClass obj);
    static {
    // System.loadLibrary("UseObjImpl");
    // Linux hack, if you can't get your library
    // path set in your environment:
    System.load(
    "/root/jproj/UseObjImpl.so");
    public static void main(String[] args) {
    UseObjects app = new UseObjects();
    MyJavaClass anObj = new MyJavaClass();
    anObj.aValue = 2;
    app.changeObject(anObj);
    System.out.println("Java: " + anObj.aValue);
    } ///:~
    i modify this two file which is from TIJ-2edition.
    the output is
    Native: 2
    Native: 3
    Java: 3
    but what i want to be executed "preprocess -path sha.c" does not work.
    i have change the command to, such as "df", "ls" etc. but none of them works
    please help me.

Maybe you are looking for