KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > hook > impl > JavaLangArrayHelpers


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.bytecode.hook.impl;
5
6 import com.tc.object.TCObject;
7 import com.tc.object.bytecode.ManagerUtil;
8
9 public class JavaLangArrayHelpers {
10   public static final String JavaDoc CLASS = "com/tc/object/bytecode/hook/impl/JavaLangArrayHelpers";
11
12   /**
13    * Optimization used by String.getChars(int, int, char[], int)
14    */

15   public static void charArrayCopy(char[] src, int srcPos, char[] dest, int destPos, int length) {
16     TCObject tco = ManagerUtil.getObject(dest);
17     if (tco != null) {
18       ManagerUtil.charArrayCopy(src, srcPos, dest, destPos, length, tco);
19     } else {
20       System.arraycopy(src, srcPos, dest, destPos, length);
21     }
22   }
23
24   /**
25    * The entire implementation of String.getBytes() is replaced by a call to this method
26    */

27   public static void javaLangStringGetBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin, int count, int offset,
28                                             char[] value) {
29     if (srcBegin < 0) { throw new StringIndexOutOfBoundsException JavaDoc(srcBegin); }
30     if (srcEnd > count) { throw new StringIndexOutOfBoundsException JavaDoc(srcEnd); }
31     if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException JavaDoc(srcEnd - srcBegin); }
32     int j = dstBegin;
33     int n = offset + srcEnd;
34     int i = offset + srcBegin;
35     char[] val = value;
36
37     TCObject tco = ManagerUtil.getObject(dst);
38     if (tco != null) {
39       while (i < n) {
40         dst[j] = (byte) val[i++];
41         tco.byteFieldChanged(null, null, dst[j], j++);
42       }
43     } else {
44       while (i < n) {
45         dst[j++] = (byte) val[i++];
46       }
47     }
48   }
49
50   /**
51    * Called by the 1.5 implementation of java/lang/AbstractStringBuilder.append(int|long)
52    */

53   public static void javaLangAbstractStringBuilderAppend(char[] value, int appendLength, int bufferLength) {
54     TCObject tco = ManagerUtil.getObject(value);
55
56     if (tco != null) {
57       int index = bufferLength - appendLength;
58
59       while (index < bufferLength) {
60         tco.charFieldChanged(null, null, value[index], index++);
61       }
62     }
63   }
64
65 }
66
Popular Tags