Java reads the gzip compressed string of the webpage stored in memcached by C and decompress the webpage text

Source: Internet
Author: User

Recently, companies have to capture, Java is not efficient, and then C is selected to capture, to improve transmission efficiency, they need to capture the gzip compressed data of webpages,

Therefore, you must use Java to read the gzip compressed string of the webpage stored in memcached by C, decompress the webpage text,

After several days of tossing and turning over the official documentation, I read the source code and finally solved the reading problem.

 

1. memcached default replica set is a UTF-8, so if the ordinary text is saved, it is no problem to take it out.
But now the stored is compressed text string, so with the default UTF-8 to take out there will be a problem, it is necessary to change its default limit set
Memcachedclient MCC = new memcachedclient ("server" + IND );
MCC. setdefaultencoding ("ISO-8859-1"); // change the default replica set (it seems that only other tests with the ISO-8859-1 do not work)

2. do not replace the default MCC. Get (key) method with MCC. Get (Key, null, true) When retrieving data. The difference lies in the third parameter.

It indicates that the string is returned directly when get is not decoded.

 

3. If you set the default delimiter set to ISO-8859-1, but take the common text needs to be converted as follows
S = new string (S. getbytes ("ISO-8859-1"), "UTF-8 ");

 

 

4. memcached uses urlencoder encoding for the key by default. If your key contains special characters, the key value will be changed. For example, @ will change to % 40.

// The value setting does not encode the key.

MCC. setsanitizekeys (false );

 

All of the above are processed by the COM. danga. memcached. memcachedclient client, and the system environment is win7.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.