Document verification and Google Gson use

Source: Internet
Author: User
Tags crc32 crc32 checksum

One, the CRC32 file is more test

A file check can ensure that the contents of the file are not tampered with, just in the work, recorded.

1 Private voiddochecksum (String fileName) {2     Try {3             4LOG.D ("checksum", fileName);5             6Checkedinputstream CIS =NULL;7             LongFileSize = 0;8             Try {9                 //Computer CRC32 ChecksumTenCIS =NewCheckedinputstream ( One                         NewFileInputStream (FileName),NewCRC32 ()); A   -FileSize =NewFile (fileName). Length (); -                  the}Catch(FileNotFoundException e) { -System.err.println ("File not found.")); -System.exit (1); -             } +   -             byte[] buf =New byte[256]; +              while(Cis.read (BUF) >= 0) { A                  at             } -   -             //----------------------------------------------- -                         -             LongChecksum =cis.getchecksum (). GetValue (); -Showtext = checksum + "+ fileSize +" +FileName; in              - System.out.println (showtext); toLOG.D ("checksum", showtext); +Mhanler.sendemptymessage (1); -              the              *}Catch(IOException e) { $ e.printstacktrace ();Panax NotoginsengSystem.exit (1); -         } the}

Second, Google Gson

Gson is quite handy for working with JSON data, and the example

1  Public classWechatconfig {2     Private intId;3     4      Public intgetId () {5         returnId;6     }7      Public voidSetId (intId) {8          This. Id =Id;9     }Ten  One      A      -}

1 WeChat  new  WeChat (); 2 Wc.setid (+); 3 4 String json = mgson.tojson (WC); 5 6 {"Id": 20}

Reference: http://www.oschina.net/code/snippet_12_257

Http://www.cnblogs.com/haippy/archive/2012/05/20/2509329.html

Document verification and Google Gson use

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.