Ejemplo n.º 1
0
 /**
  * Returns <code>byte[]</code> representation of <code>value</code>.
  *
  * <p>If <code>value</code> is a {@link SVNPropertyValue#isString() string} property value, then
  * bytes of the string are encoded using the <span class="javastring">"UTF-8"</span> charset and
  * returned by this method. If encoding fails, then bytes are encoded using the default platform's
  * charset.
  *
  * <p>Otherwise, {@link SVNPropertyValue#getBytes()} is returned.
  *
  * @param value property value object
  * @return bytes of the property value represented by <code>value</code>; <span
  *     class="javakeyword">null</span> if <code>value</code> is <span
  *     class="javakeyword">null</span>
  */
 public static byte[] getPropertyAsBytes(SVNPropertyValue value) {
   if (value == null) {
     return null;
   }
   if (value.isString()) {
     try {
       return value.getString().getBytes("UTF-8");
     } catch (UnsupportedEncodingException e) {
       return value.getString().getBytes();
     }
   }
   return value.getBytes();
 }
Ejemplo n.º 2
0
 /**
  * Returns <code>String</code> representation of <code>value</code>.
  *
  * <p>If <code>value</code> is a {@link SVNPropertyValue#isBinary() binary} property value, then
  * its bytes are converted to a <code>String</code> encoding them with the <span
  * class="javastring">"UTF-8"</span> charset and returned back to the caller. If that encoding
  * fails, bytes are encoded with the default platform's charset.
  *
  * <p>Otherwise, {@link SVNPropertyValue#getString()} is returned.
  *
  * @param value property value object
  * @return string property value; <span class="javakeyword">null</span> if <code>value</code> is
  *     <span class="javakeyword">null</span>
  */
 public static char[] getPropertyAsChars(SVNPropertyValue value) {
   if (value == null) {
     return null;
   }
   if (value.isBinary()) {
     return SVNEncodingUtil.getChars(value.getBytes(), "UTF-8");
   }
   return value.getString().toCharArray();
 }
Ejemplo n.º 3
0
 /**
  * Returns <code>String</code> representation of <code>value</code>.
  *
  * <p>If <code>value</code> is a {@link SVNPropertyValue#isBinary() binary} property value, then
  * its bytes are converted to a <code>String</code> encoding them with the <span
  * class="javastring">"UTF-8"</span> charset and returned back to the caller. If that encoding
  * fails, bytes are encoded with the default platform's charset.
  *
  * <p>Otherwise, {@link SVNPropertyValue#getString()} is returned.
  *
  * @param value property value object
  * @return string property value; <span class="javakeyword">null</span> if <code>value</code> is
  *     <span class="javakeyword">null</span>
  */
 public static String getPropertyAsString(SVNPropertyValue value) {
   if (value == null) {
     return null;
   }
   if (value.isBinary()) {
     try {
       return new String(value.getBytes(), "UTF-8");
     } catch (UnsupportedEncodingException e) {
       return new String(value.getBytes());
     }
   }
   return value.getString();
 }
Ejemplo n.º 4
0
  /**
   * Says whether this object and <code>obj</code> are equal or not.
   *
   * @param obj object to compare with
   * @return <span class="javakeyword">true</span> in the following cases:
   *     <ul>
   *       <li/><code>obj</code> is the same as this one (by reference)
   *       <li/>if <code>obj</code> is an <code>SVNPropertyValue</code> and either has got the same
   *           <code>String</code> value in case this object holds a <code>String</code> value, or
   *           the same byte array contents if this object represents a binary property value
   *     </ul>
   */
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }

    if (obj instanceof SVNPropertyValue) {
      SVNPropertyValue value = (SVNPropertyValue) obj;
      if (isString()) {
        return myValue.equals(value.getString());
      } else if (isBinary()) {
        return Arrays.equals(myData, getPropertyAsBytes(value));
      }
    }
    return false;
  }