avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util StringUtils.java
Date Fri, 26 Apr 2002 14:30:11 GMT
rana_b      02/04/26 07:30:11

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver/util
                        StringUtils.java
  Log:
  string to hex methods added
  
  Revision  Changes    Path
  1.2       +31 -1     jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/StringUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringUtils.java	31 Mar 2002 16:45:01 -0000	1.1
  +++ StringUtils.java	26 Apr 2002 14:30:11 -0000	1.2
  @@ -1,3 +1,4 @@
  +// $Id: StringUtils.java,v 1.2 2002/04/26 14:30:11 rana_b Exp $
   /*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
  @@ -130,5 +131,34 @@
               return sb.toString() + src;
           }
       }   
  +     
  +    /**
  +     * Get hex string from byte array
  +     */
  +    public static String toHexString(byte[] res) {
  +        StringBuffer sb = new StringBuffer(res.length << 1);
  +        for(int i=0; i<res.length; i++) {
  +            String digit = Integer.toHexString(0xFF & res[i]);
  +            if (digit.length() == 1) {
  +                digit = '0' + digit;
  +            }
  +            sb.append(digit);
  +        }
  +        return sb.toString().toUpperCase();
  +    } 
  +    
  +    /**
  +     * Get byte array from hex string
  +     */
  +    public static byte[] toByteArray(String hexString) {
  +        int arrLength = hexString.length() >> 1;
  +        byte buff[] = new byte[arrLength];
  +        for(int i=0; i<arrLength; i++) {
  +            int index = i << 1;
  +            String digit = hexString.substring(index, index+2);
  +            buff[i] = (byte)Integer.parseInt(digit, 16);
  +        }
  +        return buff;
  +    }    
          
  -} 
  \ No newline at end of file
  +} 
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message