01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Vladimir N. Molotkov
20: * @version $Revision$
21: */package org.apache.harmony.security.tests.support;
22:
23: import java.util.Properties;
24:
25: /**
26: * Test utility class
27: */
28: public class TestUtils {
29:
30: /**
31: * No need to instantiate
32: */
33: private TestUtils() {
34: }
35:
36: /**
37: * Prints byte array <code>data</code> as hex to the
38: * <code>System.out</code> in the customizable form.
39: *
40: * @param perLine how many numbers put on single line
41: * @param prefix custom output number prefix
42: * @param delimiter custom output number delimiter
43: * @param data data to be printed
44: */
45: public static void printAsHex(int perLine, String prefix,
46: String delimiter, byte[] data) {
47: for (int i = 0; i < data.length; i++) {
48: String tail = Integer.toHexString(0x000000ff & data[i]);
49: if (tail.length() == 1) {
50: tail = "0" + tail;
51: }
52: System.out.print(prefix + "0x" + tail + delimiter);
53:
54: if (((i + 1) % perLine) == 0) {
55: System.out.println("");
56: }
57: }
58: System.out.println("");
59: }
60:
61: /**
62: * Sets system property
63: *
64: * @param key - the name of the system property.
65: * @param value - the value to be set
66: */
67: public static void setSystemProperty(String key, String value) {
68: Properties properties = System.getProperties();
69: if (value == null) {
70: properties.remove(key);
71: } else {
72: properties.setProperty(key, value);
73: }
74: System.setProperties(properties);
75: }
76: }
|