db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r518240 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java
Date Wed, 14 Mar 2007 17:50:00 GMT
Author: kmarsden
Date: Wed Mar 14 10:49:59 2007
New Revision: 518240

URL: http://svn.apache.org/viewvc?view=rev&rev=518240
Log:
DERBY-2429  Add Utilities file missed with first checkin

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java   (with
props)

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java?view=auto&rev=518240
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java Wed Mar
14 10:49:59 2007
@@ -0,0 +1,83 @@
+/*
+ *
+ * Derby - Class Utilities
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, 
+ * software distributed under the License is distributed on an 
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
+ * either express or implied. See the License for the specific 
+ * language governing permissions and limitations under the License.
+ */
+package org.apache.derbyTesting.junit;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * General non-JDBC related utilities relocated from TestUtil
+ *
+ *
+ */
+public class Utilities {
+
+    public Utilities() {
+        // TODO Auto-generated constructor stub
+    }
+        /**
+         * Just converts a string to a hex literal to assist in converting test
+         * cases that used to insert strings into bit data tables
+         * Converts using UTF-16BE just like the old casts used to.
+         *
+         * @param s  String to convert  (e.g
+         * @return hex literal that can be inserted into a bit column.
+         */
+        public static String stringToHexLiteral(String s)
+        {
+                byte[] bytes;
+                String hexLiteral = null;
+                try {
+                        bytes = s.getBytes("UTF-16BE");
+                        hexLiteral = convertToHexString(bytes);
+                }
+                catch (UnsupportedEncodingException ue)
+                {
+                        System.out.println("This shouldn't happen as UTF-16BE should be supported");
+                        ue.printStackTrace();
+                }
+
+                return hexLiteral;
+        }
+
+        /**
+         * Convert a byte array to a hex string suitable for insert 
+         * @param buf  byte array to convert
+         * @return     formated string representing byte array
+         */
+        private static String convertToHexString(byte [] buf)
+        {
+                StringBuffer str = new StringBuffer();
+                str.append("X'");
+                String val;
+                int byteVal;
+                for (int i = 0; i < buf.length; i++)
+                {
+                        byteVal = buf[i] & 0xff;
+                        val = Integer.toHexString(byteVal);
+                        if (val.length() < 2)
+                                str.append("0");
+                        str.append(val);
+                }
+                return str.toString() +"'";
+        }
+
+
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message