ggregory

Apache Commons Code LetterCase proposal

Apr 4th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. Index: src/main/java/org/apache/commons/codec/binary/Hex.java
  2. ===================================================================
  3. --- src/main/java/org/apache/commons/codec/binary/Hex.java (revision 1464242)
  4. +++ src/main/java/org/apache/commons/codec/binary/Hex.java (working copy)
  5. @@ -26,6 +26,8 @@
  6. import org.apache.commons.codec.DecoderException;
  7. import org.apache.commons.codec.EncoderException;
  8.  
  9. +import org.apache.commons.codec.LetterCase;
  10. +
  11. /**
  12. * Converts hexadecimal Strings. The charset used for certain operation can be set, the default is set in
  13. * {@link #DEFAULT_CHARSET_NAME}
  14. @@ -132,6 +134,22 @@
  15. *
  16. * @param data
  17. * a byte[] to convert to Hex characters
  18. + * @param letterCase
  19. + * the lettercase to use for ouput
  20. + * @return A char[] containing hexadecimal characters
  21. + * @since 1.8
  22. + */
  23. + public static char[] encodeHex(final byte[] data, final LetterCase letterCase) {
  24. + return encodeHex(data, LetterCase.LOWER == letterCase ? DIGITS_LOWER : DIGITS_UPPER);
  25. + }
  26. +
  27. + /**
  28. + * Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
  29. + * The returned array will be double the length of the passed array, as it takes two characters to represent any
  30. + * given byte.
  31. + *
  32. + * @param data
  33. + * a byte[] to convert to Hex characters
  34. * @param toDigits
  35. * the output alphabet
  36. * @return A char[] containing hexadecimal characters
  37. Index: src/main/java/org/apache/commons/codec/LetterCase.java
  38. ===================================================================
  39. --- src/main/java/org/apache/commons/codec/LetterCase.java (revision 0)
  40. +++ src/main/java/org/apache/commons/codec/LetterCase.java (working copy)
  41. @@ -0,0 +1,19 @@
  42. +package org.apache.commons.codec;
  43. +
  44. +/**
  45. + * Enumerates letter cases, upper and lower.
  46. + *
  47. + * @since 1.8
  48. + */
  49. +public enum LetterCase {
  50. +
  51. + /**
  52. + * Upper case.
  53. + */
  54. + UPPER,
  55. +
  56. + /**
  57. + * Lower case.
  58. + */
  59. + LOWER
  60. +}
  61. Index: src/main/java/org/apache/commons/codec/LetterCase.java
  62. ===================================================================
  63. --- src/main/java/org/apache/commons/codec/LetterCase.java (revision 0)
  64. +++ src/main/java/org/apache/commons/codec/LetterCase.java (working copy)
  65.  
  66. Property changes on: src/main/java/org/apache/commons/codec/LetterCase.java
  67. ___________________________________________________________________
  68. Added: svn:keywords
  69. ## -0,0 +1 ##
  70. +Id
  71. \ No newline at end of property
  72. Added: svn:eol-style
  73. ## -0,0 +1 ##
  74. +native
  75. \ No newline at end of property
Advertisement
Add Comment
Please, Sign In to add comment