Apache Commons ソースリーディングの会:Codec

4,273 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,273
On SlideShare
0
From Embeds
0
Number of Embeds
60
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Apache Commons ソースリーディングの会:Codec

  1. 1. Apache Commons Codec ※ → encode decode)
  2. 2. • • • • (ex.Base64)
  3. 3. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  4. 4. http://commons.apache.org/codec/ 2009 1.4 Ver.UP Java1.4
  5. 5. • org.apache.commons.codec.binary - - Base64 / Hex / Binary Codec • org.apache.commons.codec.digest - MD5 SHA1 • org.apache.commons.codec.language - - Soundex / Metaphone • org.apache.commons.codec.net - - URLCodec(URL Encode) / Quoted Printable Codec / BCodec / QCodec
  6. 6. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  7. 7. org.apache.commons.codec • • Exception - Encoder / Decoder - BinaryEncoder / BinaryDecoder - StringEncoder / StringDecoder - StringEncoderComparator - DecoderException / EncoderException - CharEncoding(charset )
  8. 8. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  9. 9. org.apache.commons.codec.binary • - BinaryEncoder / BinaryDecoder - Base64 - Base64InputStream / Base64OutputStream - Hex - BinaryCodec - StringUtils
  10. 10. Base64 • 64 • Basic • 4/3
  11. 11. Base64 Encoding • • [0-9a-zA-Z+/] • Commons Codec • STANDARD_ENCODE_TABLE • [0-9a-zA-Z+/] • URL_SAFE_ENCODE_TABLE • [0-9a-zA-Z-_] • RFC http://www.ietf.org/rfc/rfc2045.txt
  12. 12. • • urlSafe:boolean • lineLength:int • lineLength:int, lineSeparator:byte[] • lineLength:int, lineSeparator:byte[], urlSafe:boolean
  13. 13. • lineLength • • 76 • RFC2045 section 6.8. http://tools.ietf.org/html/rfc2045#section-6.8
  14. 14. • lineSeparator • • CRLF rn • RFC2045 section 2.1. http://tools.ietf.org/html/rfc2045#section-2.1 mail RFC RF822
  15. 15. • urlSafe • • true:URL_SAFE_ENCODE_TABLE • false:STANDARD_ENCODE_TABLE (default)
  16. 16. encodeBase64 • binaryData:byte[] • binaryData:byte[] ,isChunked:boolean • binaryData:byte[] ,isChunked:boolean ,urlSafe:boolean • binaryData:byte[] ,isChunked:boolean ,urlSafe:boolean, maxResultSize:int
  17. 17. encodeBase64 • binaryData • • null
  18. 18. encodeBase64 • isChunked • • true 76 lineLength ( lineLength / 4 * 4) • false:
  19. 19. encodeBase64 • urlSafe • • Base64.encodeBase64()
  20. 20. encodeBase64 • maxResultSize • • IllegalArgumentException
  21. 21. encodeBase64 • • null • maxResultSize • Base64 • encode • null • • EOF •
  22. 22. decodeBase64 • base64data:byte[] • base64String:String • StringUtils.getBytesUtf8() UTF-8
  23. 23. decodeBase64 • • • EOF
  24. 24. org.apache.commons.codec.binary • - BinaryEncoder / BinaryDecoder - Base64 - Base64InputStream / Base64OutputStream - Hex - BinaryCodec - StringUtils
  25. 25. Hex • 16 char • LOWER or UPPER •
  26. 26. org.apache.commons.codec.binary • - BinaryEncoder / BinaryDecoder - Base64 - Base64InputStream / Base64OutputStream - Hex - BinaryCodec - StringUtils
  27. 27. BinaryCodec • 2 char •
  28. 28. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  29. 29. org.apache.commons.codec.digest • MessageDigest - DigestUtils
  30. 30. MessageDigest? • • MD5 SHA1 • Java java.security.MessageDigest • DigestUtils MessageDigest
  31. 31. DigestUtils • • MD5 SHA1 SHA256 SHA384 SHA51 2 • • Stream UTF-8 • • 16
  32. 32. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  33. 33. org.apache.commons.codec.language • Phonetic Algorithm ※Phonetic Algorithm: - StringEncoder - Soundex - Metaphone - RefinedSoundex - DoubleMetaphone - Caverphone - SoundexUtils
  34. 34. Soundex • • • • Soundex • “Robert”,”Rupert” → R163
  35. 35. • Soundex http://en.wikipedia.org/wiki/Soundex • Metaphone http://en.wikipedia.org/wiki/Metaphone • Caverphone http://en.wikipedia.org/wiki/Caverphone
  36. 36. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  37. 37. org.apache.commons.codec.net • - BinaryEncoder / BinaryDecoder / StringEncoder / StringDecoder - URLCodec - QuotedPrintableCodec - RFC1522Codec - QCodec - BCodec - Utils
  38. 38. URLCodec • URL • java.net.URLEncoder / URLDecoder • Commons Codec • URLCodec QuotedPrintable
  39. 39. • • charset:String • charset • UTF-8
  40. 40. encode • bytes:byte[] • pObject:Object • pString:String • pString:String, charset:String • charset charset
  41. 41. encode • • • • URL Safe ʼ+ʼ • URL Safe:[0-9a-zA-Z-_.* ] • URL Safe ʼ%ʼ + 16
  42. 42. decode • bytes:byte[] • pObject:Object • pString:String • pString:String, charset:String • charset charset
  43. 43. decode • • • • URL Safe ʼ+ʼ • URL Safe:[0-9a-zA-Z-_.* ] • URL Safe ʼ%ʼ
  44. 44. org.apache.commons.codec.net • - BinaryEncoder / BinaryDecoder / StringEncoder / StringDecoder - URLCodec - QuotedPrintableCodec - RFC1522Codec - QCodec - BCodec - Utils
  45. 45. QuotedPrintableCodec • RFC1521 • 8 7 • Content-Transfer-Encoding: quoted-printable • • 0x21(10 :33) 0x3c(60) 0x3e(62) 0x72(126) • ʼ=ʼ + 4 2 ) 16 (ex.ʼ=ʼ→”=3D”)
  46. 46. • • charset:String • charset • UTF-8
  47. 47. encode • bytes:byte[] • pObject:Object • pString:String • pString:String, charset:String • charset charset
  48. 48. encode • • • • • ʼ=ʼ + 16
  49. 49. decode • bytes:byte[] • pObject:Object • pString:String • pString:String, charset:String • charset charset
  50. 50. decode • • • ʼ=ʼ • ʻ=ʻ • ʻ=ʻ
  51. 51. org.apache.commons.codec.net • - BinaryEncoder / BinaryDecoder / StringEncoder / StringDecoder - URLCodec - QuotedPrintableCodec - RFC1522Codec - QCodec - BCodec - Utils
  52. 52. RFC1522Codec • RFC1521 1522 MIME RFC • ASCII • RFC1522Codec • [sample] =?ISO-2022-JP?B?GyRCJD8hIxsoQg==?= • QCodec:Quoted Printable • BCodec:Base64 • BCodec
  53. 53. QCodec • • charset:String • charset • UTF-8
  54. 54. encode • pObject:Object • pString:String • pString:String, charset:String • charset charset
  55. 55. encode • • PREFIX (“=?”) • charset • (ʻ?ʼ) • (QCodec ʼQʼ) • (ʻ?ʼ) • Quoted Printable • POSTFIX (“?=”)
  56. 56. decode • pObject:Object • pString:String • ※QCodec charset
  57. 57. decode • • PREFIX POSTFIX • charset (QCodec or BCodec) •
  58. 58. BCodec • QCodec QCodec • ʼBʼ • Base64
  59. 59. ✓Commons Codec ✓org.apache.commons.codec ✓org.apache.commons.codec.binary ✓org.apache.commons.codec.digest ✓org.apache.commons.codec.language ✓org.apache.commons.codec.net ✓
  60. 60. Commons Codec

×