1 21 package com.db4o; 22 23 26 public final class YapStringIOUnicode extends YapStringIO{ 27 28 public int bytesPerChar(){ 29 return 2; 30 } 31 32 public byte encodingByte(){ 33 return YapConst.UNICODE; 34 } 35 36 38 53 public int length(String a_string){ 54 return (a_string.length() * 2) + YapConst.OBJECT_LENGTH + YapConst.INT_LENGTH; 55 } 56 57 public String read(YapReader bytes, int a_length){ 58 checkBufferLength(a_length); 59 for(int ii = 0; ii < a_length; ii++){ 60 chars[ii] = (char)((bytes._buffer[bytes._offset ++]& 0xff) | ((bytes._buffer[bytes._offset ++]& 0xff) << 8)); 61 } 62 return new String (chars,0,a_length); 63 } 64 65 public String read(byte[] a_bytes){ 66 int len = a_bytes.length / 2; 67 checkBufferLength(len); 68 int j = 0; 69 for(int ii = 0; ii < len; ii++){ 70 chars[ii] = (char)((a_bytes[j++]& 0xff) | ((a_bytes[j++]& 0xff) << 8)); 71 } 72 return new String (chars,0,len); 73 } 74 75 public int shortLength(String a_string){ 76 return (a_string.length() * 2) + YapConst.INT_LENGTH; 77 } 78 79 public void write(YapReader bytes, String string){ 80 final int len = writetoBuffer(string); 81 for (int i = 0; i < len; i ++){ 82 bytes._buffer[bytes._offset++] = (byte) (chars[i] & 0xff); 83 bytes._buffer[bytes._offset++] = (byte) (chars[i] >> 8); 84 } 85 } 86 87 byte[] write(String string){ 88 final int len = writetoBuffer(string); 89 byte[] bytes = new byte[len * 2]; 90 int j = 0; 91 for (int i = 0; i < len; i ++){ 92 bytes[j++] = (byte) (chars[i] & 0xff); 93 bytes[j++] = (byte) (chars[i] >> 8); 94 } 95 return bytes; 96 } 97 98 } 99 | Popular Tags |