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 ).

Similar Messages

  • Compressing and decompressing a  string list

    Hi All,
    i need a help:
    i have an string list say,
    String sample="test";
    String sample1="test1";
    String sample2="test3";
    i want to compress this sample,sample1,sample2 and store that compressed results into another string variable.
    Ex:
    compressedSample=sample;
    compressedSample1=sample1;
    compressedSample2=sample2;
    similarly how can i uncompress the compressedSample,compressedSample1,compressedSample2 variables.
    Thanks in advance

    Try something like this :
    Compressing :
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    GZIPOutputStream gos = new GZIPOutputStream(aos);
    byte[] ba = "the_string_to_compress".getBytes();
    gos.write(ba,0,ba.length);
    gos.flush();
    String compressed_string = aos.toString();
    gos.close();
    Decompressing :
    GZIPInputStream zin = new GZIPInputStream( new ByteArrayInputStream( compressed_string.getBytes() ) );
    StringBuffer dat = new StringBuffer();
    byte[] buf = new Byte[128];
    for(int r; (r=zin.read(buf))!=-1;) dat.append( new String(buf,0,r) );
    zin.close();
    String org_string = dat.toString();

  • How to compress and decompress a pdf file in java

    I have a PDF file ,
    what i want to do is I need a lossless compression technique to compress and decompress that file,
    Please help me to do so,
    I am always worried about this topic

    Here is a simple program that does the compression bit.
    static void compressFile(String compressedFilePath, String filePathTobeCompressed)
              try
                   ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(compressedFilePath));
                   File file = new File(filePathTobeCompressed);
                   int iSize = (int) file.length();
                   byte[] readBuffer = new byte[iSize];
                   int bytesIn = 0;
                   FileInputStream fileInputStream = new FileInputStream(file);
                   ZipEntry zipEntry = new ZipEntry(file.getPath());
                   zipOutputStream.putNextEntry(zipEntry);
                   while((bytesIn = (fileInputStream.read(readBuffer))) != -1)
                        zipOutputStream.write(readBuffer, 0, bytesIn);
                   fileInputStream.close();
                   zipOutputStream.close();
              catch (FileNotFoundException e)
              catch (IOException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         }

  • Compressing and decompressing a PDF file

    Dear Gurus,
    Anyone who can assist with the code to compress and decompress PDF file so that I can send it in an email.
    Thanks

    1) you should go to ABAP Printing forum where this problem has been discussed many times (for example remove the coloring to reduce the file size etc.). Just in case you would insist on working your way.
    2) You can create some printing "device" like smartform etc. to print your data for you and then convert it to PDF, the result should be smaller then option 1)
    3) the best one: if you want to send a PDF somewhere (or archive it etc.) you should start with Adobe forms, for you purpose Adobe print forms will be suffiscient. You only need to install and configure the ADS component to generate forms from the template for you. If you want to see a brief ovewrview about how to create this thing, start reading somewhere like here (this is not the most simple example!!):
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c2567f2b-0b01-0010-b7b5-977cbf80665d
    Regards Otto

  • Compressed AND  Decompressed  STRING

    i want java porg 2 part
    part 1
    Compress largre string to small size and the compress string stroed in mysql data base
    part 2
    the prog read the compress string from data base then decompress .
    i am beginner lever java programmer
    pls give me code
    pls reply quickly
    with regards
    kumars

    hi everone,
    i have some problems with compress/decompress strings.
    i want to store a serialized php array, witch looks like this
    a:30:{i:0;s:1:"0";i:1;s:1:"1";i:2;s:1:"2";i:3;s:1:"3";i:4;s:1......
    on linux and mac os x it works fine, but not on win32 (winxp)
    i always get this error:
    java.io.IOException: Corrupt GZIP trailer
            at java.util.zip.GZIPInputStream.readTrailer(Unknown Source)
            at java.util.zip.GZIPInputStream.read(Unknown Source)
            at StringZip.decompress(StringZip.java:57)
            at StringZip.main(StringZip.java:84)is my test string too long ??
    maybe anyone can try this sample..
    much thx :D
    import java.io.*;
    import java.util.zip.*;
    public class StringZip {
         private static final int BLOCKSIZE = 1024;
         public static String compress( String data ) {          
              ByteArrayOutputStream zipbos = new ByteArrayOutputStream();
              ByteArrayInputStream zipbis = null;
              zipbis = new ByteArrayInputStream(data.getBytes());          
             GZIPOutputStream gzos = null;
             // now try to zip
             try {
                  gzos = new GZIPOutputStream(zipbos);
                  byte[] buffer = new byte[ BLOCKSIZE ];
                  // write into the zip stream
                  for ( int length; (length = zipbis.read(buffer, 0, BLOCKSIZE)) != -1; )
                      gzos.write( buffer, 0, length );
             } catch ( IOException e ) {
                  System.err.println( "Error: Couldn't compress" );
                  e.printStackTrace();
             } finally {
                  if ( zipbis != null )
                      try { zipbis.close(); } catch ( IOException e ) { e.printStackTrace(); }
                  if ( gzos != null )
                      try { gzos.close(); } catch ( IOException e ) { e.printStackTrace(); }
             // return the zipped string
             return zipbos.toString();
         public static String decompress( String data ) {
              ByteArrayInputStream zipbis = null;
              zipbis = new ByteArrayInputStream(data.getBytes());
              ByteArrayOutputStream zipbos = new ByteArrayOutputStream();
              GZIPInputStream gzis = null;
              try {
                   gzis = new GZIPInputStream( zipbis );
                   byte[] buffer = new byte[ BLOCKSIZE ];
                   // write the decompressed data into the stream
                   for ( int length; (length = gzis.read(buffer, 0, BLOCKSIZE)) != -1; )
                        zipbos.write( buffer, 0, length );
              } catch ( IOException e ) {
                   System.err.println( "Error: Couldn't decompress" );               
                   e.printStackTrace();
              } finally {
                   if ( zipbos != null )
                      try { zipbos.close(); } catch ( IOException e ) { e.printStackTrace(); }
                  if ( gzis != null )
                      try { gzis.close(); } catch ( IOException e ) { e.printStackTrace(); }
              return zipbos.toString();
         public static void main(String[] args) {
               String test = "a:30:{i:0;s:1:\"0\";i:1;s:1:\"1\";i:2;s:1:\"2\";i:3;s:1:\"3\";i:4;s:1:\"4\";i:5;s:1:\"5\";i:6;s:1:\"6\";i:7;s:1:\"7\";i:8;s:1:\"8\";i:9;s:1:\"9\";i:10;s:2:\"10\";i:11;s:2:\"11\";i:12;s:2:\"12\";i:13;s:2:\"13\";i:14;s:2:\"14\";i:15;i:15;i:16;i:16;i:17;i:17;i:18;i:18;i:19;i:19;i:20;i:20;i:21;i:21;i:22;i:22;i:23;i:23;i:24;i:24;i:25;i:25;i:26;i:26;i:27;i:27;i:28;i:28;i:29;i:29;}";
               String test_compressed   = compress(test);
               String test_decompressed = decompress(test_compressed);
               System.out.println(test);
               System.out.println(test_decompressed);
    }Message was edited by: antiben
    // edit
    ok, found a workaround
    seems to be a windows only problem :/

  • Compressiong And Decompression

    Hi,
    I do have an issue with compression and decompression.
    I have used following program to compress and decompress a file...
    I don't have any issue in compression. But when same file is tried to
    decompress I am getting some exception
    <code>
    public class Zipper {
         public static void main(String args[]) {
         try{
              Zipper zipper = new Zipper();
              if(args.length <= 0)
                   throw new IllegalArgumentException("Please provide file name for compression");
              String compressedFileName = zipper.compress(args[0]);
              String deCompressedFileName = zipper.deCompress(compressedFileName);
    }catch(Exception e){
              e.printStackTrace();
              //e.getCause().printStackTrace();
    /*                                        INFLATER METHODS                                             */
         private String compress(String fileName)throws Exception{
              String outputName = fileName+".zipped";
              File inputFile = new File(fileName);
              File zippedFile = new File(outputName);
              //FileInputStream fips = new FileInputStream(inputFile);
              RandomAccessFile raf = new RandomAccessFile(inputFile,"r");
              //FileOutputStream fops = new FileOutputStream(zippedFile);
              RandomAccessFile rafOut = new RandomAccessFile(zippedFile,"rw");
              Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION);
              byte[] buf = new byte[1000];
              byte[] out = new byte[50];
              int intialCount = 0;
              int zippedSize = 0;
              int count = 0;
              String tempString = null;
              while( (count = raf.read(buf)) != -1){
                   intialCount += count;
                   compresser.setInput(buf);
                   compresser.finish();
                   count = compresser.deflate(out);
                   zippedSize += count;
                   //tempString = new String(out);
                   //tempString.trim();
                   //fops.write(tempString.getBytes("UTF-8"));
                   rafOut.write(out);
                   compresser.reset();
              //fops.close();
              //fips.close();
              rafOut.close();
              System.out.println("Intial File Size "+intialCount);
              System.out.println("Zipped File Size "+zippedSize);
              return outputName;
         private String deCompress(String fileName)throws Exception{
              String outputName = fileName+".unzipped";
              File inputFile = new File(fileName);
              File zippedFile = new File(outputName);
              //FileInputStream fips = new FileInputStream(inputFile);
              RandomAccessFile raf = new RandomAccessFile(inputFile,"r");
              FileOutputStream fops = new FileOutputStream(zippedFile);
              Inflater deCompresser = new Inflater();
              byte[] buf = new byte[100];
              byte[] out = new byte[1000];
              int intialCount = 0;
              int unZippedSize = 0;
              int count = 0;
              String tempString = null;
              while( (count = raf.read(buf)) != -1){
                   System.out.println("Count = "+count);
                   intialCount += count;
                   deCompresser.setInput(buf);
                   count = deCompresser.inflate(out);
                   unZippedSize += count;
                   //tempString = new String(out);
                   //tempString.trim();
                   //fops.write(tempString.getBytes("UTF-8"));
                   fops.write(out);
                   deCompresser.reset();
              fops.close();
              raf.close();
              //fips.close();
              System.out.println("Intial File Size "+intialCount);
              System.out.println("UnZipped File Size "+unZippedSize);
              return outputName;
    </code>
    Exception I got is
    Intial File Size 125952
    Zipped File Size 4938
    Count = 100
    java.util.zip.DataFormatException: invalid bit length repeat
    at java.util.zip.Inflater.inflateBytes(Native Method)
    at java.util.zip.Inflater.inflate(Unknown Source)
    at java.util.zip.Inflater.inflate(Unknown Source)
    at Zipper.deCompress(Zipper.java:213)
    at Zipper.main(Zipper.java:29)

    How about some google?
    Ans try this one: http://www.tinyline.com/utils/index.html

  • Differnce between null string and an empty string??

    what is the major difference between null string and an empty string??
    I wrote the following simple program and I could see some different output.
    Other than that, any other differences that we should pay attention to???
    C:\>java TestCode
    Hello
    nullHello
    public class TestCode
         public static void main(String[] s)
         {     String s1 = "";
              String s2 = null;
              System.out.println(s1 + "Hello");
              System.out.println(s2 + "Hello");
    }

    There's a big difference between the two. A null String isn't pointing to an object, but an empty String is. For example, this is perfectly fine:
    public class TestCode
        public static void main(String[] args)
            String s = "";
            System.out.println(s.length());
    } It prints out 0 for the length of the String, just as it should. But this code will give you a NullPointerException:
    public class TestCode
        public static void main(String[] args)
            String s = null;
            System.out.println(s.length());
    } Since s isn't pointing to anything, you can't call its methods.

  • What is the difference between string != null and null !=string ?

    Hi,
    what is the difference between string != null and null != string ?
    which is the best option ?
    Thanks
    user8729783

    Like you've presented it, nothing.  There is no difference and neither is the "better option".

  • I run Dev 6i on Windows 2008 R2 64-bit,the forms are working fine after connection to the database but the reports continue to request for username, password and database connection string every time i try to open a report.

    I receive REP-0501: Unable to connect to specified database. I run developer 6i application on windows 2008 r2. I have applied the nn60.dll and nnb60.dll files to the \BIN directory. The forms are working fine. The reports will only display after the correct user id (username, password and database connection string) is supplied. This is happening to all attempts to open already complied form. Pls, help.

    If you are connecting to an Oracle 11g database, remember that by default the passwords are case sensitive. To disable that, run
    ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = FALSE;

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Find and Replace text string in HTML

    Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
    with "YYYYY"
    I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
    [email protected]

    Hello Phil,
    The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
    questions there.
    If you decide to develop an Outlook macro on your own, the
    Getting Started with VBA in Outlook 2010 article is a good place to start from.

  • String to Int and Int to String

    How can I convert a string to Int & and an Int to String ?
    Say I've
    String abc="234"
    and I want the "int" value of "abc", how do I do it ?
    Pl. help.

    String.valueOf(int) takes an int and returns a string.
    Integer.parseInt(str) takes a string, returns an int.
    For all the others long, double, hex etc. RTFM :)

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

  • Using clobs and ORA-01704: string literal too long

    Hi,
    I am attempting to add oracle support to an existing J2ee application. The issue I am facing is the use of CLOB datatypes and the 4k string literal limitation that Oracle has.
    I have dowloaded the 10.2.0.3 thin driver and am connected to a 9i release 2 database. When I execute a statement such as the following (say the table has one varchar2 field and two clob fields
    Insert into my_table VALUES ('hi','something','pretend this string is 5000 characters')
    I still receive the error
    java.sql.SQLException: ORA-01704: string literal too long
    I have read that the version 10 drivers were supposed to address this limitation. Is there something I am missing or must I change my home grown database layer to use bind variables or clob manipulation in a separate update/insert statement.? I am trying to avoid this situation since the database layer works fine for the situation of MSSQL and text fields which have no such limitation.
    Any advice you have here is greatly appreciated.
    Thanks,
    Joe

    Hi,
    I am attempting to add oracle support to an existing J2ee application. The issue I am facing is the use of CLOB datatypes and the 4k string literal limitation that Oracle has.
    I have dowloaded the 10.2.0.3 thin driver and am connected to a 9i release 2 database. When I execute a statement such as the following (say the table has one varchar2 field and two clob fields
    Insert into my_table VALUES ('hi','something','pretend this string is 5000 characters')
    I still receive the error
    java.sql.SQLException: ORA-01704: string literal too long
    I have read that the version 10 drivers were supposed to address this limitation. Is there something I am missing or must I change my home grown database layer to use bind variables or clob manipulation in a separate update/insert statement.? I am trying to avoid this situation since the database layer works fine for the situation of MSSQL and text fields which have no such limitation.
    Any advice you have here is greatly appreciated.
    Thanks,
    Joe

  • Configuration issue in IE as Document mode: 10 and User agent String: Internet Explorer 8

    Hi,
    I have a telerik rad popup window performing some input operation. The problem is when I use the configuration in IE as Document mode: 10 and User
    agent String: Internet Explorer 8, scroll bars appear in the window from nowhere. It is working fine with every other configuration of IE. I've also used a separate stylesheet for IE 8 but it won't apply in this case. 
    Here are the screen shots of the window.
    Actual view
    With Scorllbar
    Please if anybody could suggest a solution for this weird problem it would be a great help.
    Thanks in advance.
    Neelesh

    Hi,
    It seems we need to talk with the site developers to determine how the sheet would display with different IE user agent string.
    Regarding the user agent string changes, please take a check with the following article:
    Introducing IE9’s User Agent String
    The Internet Explorer 8 User-Agent String (Updated Edition)
    Hope this may help
    Best regards
    Michael Shao
    TechNet Community Support

Maybe you are looking for

  • I need to send a file in word to one of my emails, how do I do this

    I have a file that I maid for my church. I need to email this file to the church and I don't know how to do this. Please help

  • CS3.....using actionscript 2.0.....how do i make a popup window that actually works?

    Iv'e been trying all types of code and am pulling my hair out......how do i go about making a javascript popup window that works in safari, as well as all the other browsers? Im getting this error when i try to use safari: Safari doesn't allow JavaSc

  • Organizational Unit Report

    Need a ZENworks Inventory report (any report) that features the Organizational Unit of the workstation object(s) in question. Need to be able to sort or filter on Organizational Unit; can't find one. Any ideas?

  • Random music with a playlist?

    Hi everyone, Just a simple question... I have been running with my Ipod and Nike+ thing for 2 weeks now, and Inwanted to know if it was possible to have random songs with a playlist I use for my jogging. I don't want random of all my songs, just from

  • Java Certification Books?

    Hey All, I'm planning on starting to study for the Java Certification, although as always there seems to be as many book/study guides out there that there is testing centers!!! I book that seems to be defacto at the moment is : SCJP Sun Certified Pro