Example #1
0
 /**
  * Convert the {@code PlainText} object to a UTF-8 encoded {@code String}.
  *
  * @return A {@code String} representing the {@code PlainText} object.
  */
 public String toString() {
   try {
     return new String(rawBytes, "UTF-8");
   } catch (UnsupportedEncodingException e) {
     logger.error(
         EventType.EVENT_FAILURE.getEvent() + " {}" + " {}",
         "PlainText.toString() failed: Can't find UTF-8 byte-encoding!",
         e);
     throw new RuntimeException("Can't find UTF-8 byte-encoding!", e);
   }
 }
Example #2
0
 /**
  * Construct a {@code PlainText} object from a {@code String}.
  *
  * @param str The {@code String} that is converted to a UTF-8 encoded byte array to create the
  *     {@code PlainText} object.
  * @throws IllegalArgumentException If {@code str} argument is null.
  */
 public PlainText(String str) {
   try {
     if (str == null) {
       throw new IllegalArgumentException("String for plaintext may not be null!");
     }
     rawBytes = str.getBytes("UTF-8");
   } catch (UnsupportedEncodingException e) {
     logger.error(
         EventType.EVENT_FAILURE.getEvent() + " {}" + " {}",
         "PlainText(String) CTOR failed: Can't find UTF-8 byte-encoding!",
         e);
     throw new RuntimeException("Can't find UTF-8 byte-encoding!", e);
   }
 }