1 20 21 package org.apache.derby.impl.drda; 22 23 31 final class DRDAString { 32 33 private byte[] buffer; 34 35 private final CcsidManager ccsidManager; 36 37 39 private boolean modified; 40 41 42 private String cachedString; 43 44 50 DRDAString(CcsidManager m) { 51 this.buffer = new byte[0]; 52 this.ccsidManager = m; 53 this.cachedString = null; 54 } 55 56 66 private boolean equalTo(byte[] buf, int offset, int size) { 67 int len = buffer.length; 68 if (len != size) return false; 69 for (int i = 0; i < len; ++i) { 70 if (buffer[i] != buf[i+offset]) return false; 71 } 72 return true; 73 } 74 75 83 public void setBytes(byte[] src, int offset, int size) { 84 if (equalTo(src, offset, size)) { 85 modified = false; 86 return; 87 } 88 if (buffer.length != size) { 89 buffer = new byte[size]; 90 } 91 System.arraycopy(src, offset, buffer, 0, size); 92 modified = true; 93 cachedString = null; 94 } 95 96 102 public boolean wasModified() { 103 return modified; 104 } 105 106 112 public String toString() { 113 if (cachedString == null) { 114 cachedString = 115 ccsidManager.convertToUCS2(buffer); 116 } 117 return cachedString; 118 } 119 120 126 public int length() { 127 return buffer.length; 128 } 129 130 139 public byte[] getBytes() { 140 return buffer; 141 } 142 } 143 | Popular Tags |