Results 1 to 2 of 2

Thread: Encoding issue

  1. #1
    gabel8 is offline Member
    Join Date
    Jan 2014
    Rep Power

    Default Encoding issue

    I have a swing application that sends/receives information to a tomcat server via a servlet. I am compressing the string and yet I receive errors some of the time. When I test the application it works fine, but I notice occasionally it produces an error. I posted my utility class that I am using to do the compression and decompressions along with a partial stack trace from a couple of the errors.

    Compession code:
    Java Code:
    public static String compressAndEncodeBase64(String data) throws IOException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length());
            GZIPOutputStream gzip = new GZIPOutputStream(bos);
            byte[] compressed = bos.toByteArray();
            String encoded = Base64.encodeBase64String(compressed);
            return encoded;
    Decompression code:
    Java Code:
    public static String decompressAndDecodeBase64(String compressed) throws IOException {
            byte [] byteArray = Base64.decodeBase64(compressed);
            ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
            GZIPInputStream gis = new GZIPInputStream(bis);
            BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
            StringBuilder sb = new StringBuilder();
            String line;
            while((line = br.readLine()) != null) {
            return sb.toString();
    Stack-trace error I get on the server when sending a request using the following call:
    Java Code:
    String decompressedString = CompressionUtil.decompressAndDecodeBase64(stringXmlDoc); Not in GZIP format
    at com.mcmcllc.objects.util.CompressionUtil.decompres sAndDecodeBase64(

    Stack-trace error I get on the client when receiving the response:
    Java Code:
    String responseBody = IOUtils.toString(method.getResponseBodyAsStream());
    String decompressedString = CompressionUtil.decompressAndDecodeBase64(responseBody);
    Caused by: Not in GZIP format
    at Source)
    at<init>(Unknown Source)
    at<init>(Unknown Source)
    at com.mcmcllc.objects.util.CompressionUtil.decompres sAndDecodeBase64(

    I don't understand why this only occasionally happens and not all of the time. Thanks in advance for the help.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Encoding issue

    Is that Java 8?
    In other words, what Base64 encoder is that?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Postgresql with JDBC - Client encoding issue
    By preethi.raj in forum New To Java
    Replies: 4
    Last Post: 10-16-2012, 01:29 PM
  2. Encoding issue
    By kerimabdullah in forum New To Java
    Replies: 1
    Last Post: 03-08-2012, 08:03 PM
  3. Url encoding
    By RaviGupta0709 in forum Web Frameworks
    Replies: 0
    Last Post: 08-23-2011, 09:02 AM
  4. javamail > subject encoding issue?
    By litpuvn in forum Advanced Java
    Replies: 7
    Last Post: 10-25-2010, 12:37 PM
  5. encoding issue in jsp
    By sams11 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-25-2008, 08:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts