Java quoted-printable Decoder source code

Source: Internet
Author: User

The following is a method rewritten based on a set of methods in apache-jcommons. It can be used to solve quoted-printable encoded strings, similar
= B9 = E3 = B6 = AB = D2 = BB = BA = DA = CD = F8 = B0 = C9 = C9 = EE = D2 = B9 = C6 = F0 = BB = F0 = B4 =
= F3 = BB = F0 4 = C8 = CB = D4 = E1 = C9 = ED = BB = F0 = BA = A3
This encoding is usually used in emails. This encoding is also used in the MHT files stored by IE. It is difficult to find java Implementation on the Internet, so it is provided here.
Public final String qpDecoding (String str)
{
If (str = null)
{
Return "";
}
Try
{
Str = str. replaceAll ("= ","");
Byte [] bytes = str. getBytes ("US-ASCII ");
For (int I = 0; I <bytes. length; I ++)
{
Byte B = bytes [I];
If (B! = 95)
{
Bytes [I] = B;
}
Else
{
Bytes [I] = 32;
}
}
If (bytes = null)
{
Return "";
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream ();
For (int I = 0; I <bytes. length; I ++)
{
Int B = bytes [I];
If (B =)
{
Try
{
Int u = Character. digit (char) bytes [++ I], 16 );
Int l = Character. digit (char) bytes [++ I], 16 );
If (u =-1 | l =-1)
{
Continue;
}
Buffer. write (char) (u <4) + l ));
}
Catch (ArrayIndexOutOfBoundsException e)
{
E. printStackTrace ();
}
}
Else
{
Buffer. write (B );
}
}
Return new String (buffer. toByteArray (), "GBK ");
}
Catch (Exception e)
{
E. printStackTrace ();
Return "";
}
}

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.