1 21 package com.db4o; 22 23 26 public class YapStringIO { 27 28 protected char[] chars = new char[0]; 29 30 public int bytesPerChar(){ 31 return 1; 32 } 33 34 public byte encodingByte(){ 35 return YapConst.ISO8859; 36 } 37 38 static YapStringIO forEncoding(byte encodingByte){ 39 switch (encodingByte) { 40 case YapConst.ISO8859: 41 return new YapStringIO(); 42 default: 43 return new YapStringIOUnicode(); 44 } 45 } 46 47 48 50 62 public int length(String a_string){ 63 return a_string.length() + YapConst.OBJECT_LENGTH + YapConst.INT_LENGTH; 64 } 65 66 protected void checkBufferLength(int a_length){ 67 if(a_length > chars.length){ 68 chars = new char[a_length]; 69 } 70 } 71 72 public String read(YapReader bytes, int a_length){ 73 checkBufferLength(a_length); 74 for(int ii = 0; ii < a_length; ii++){ 75 chars[ii] = (char)(bytes._buffer[bytes._offset ++]& 0xff); 76 } 77 return new String (chars,0,a_length); 78 } 79 80 public String read(byte[] a_bytes){ 81 checkBufferLength(a_bytes.length); 82 for(int i = 0; i < a_bytes.length; i++){ 83 chars[i] = (char)(a_bytes[i]& 0xff); 84 } 85 return new String (chars,0,a_bytes.length); 86 } 87 88 public int shortLength(String a_string){ 89 return a_string.length() + YapConst.INT_LENGTH; 90 } 91 92 protected int writetoBuffer(String str){ 93 final int len = str.length(); 94 checkBufferLength(len); 95 str.getChars(0, len, chars, 0); 96 return len; 97 } 98 99 100 public void write(YapReader bytes, String string){ 101 final int len = writetoBuffer(string); 102 for (int i = 0; i < len; i ++){ 103 bytes._buffer[bytes._offset++] = (byte) (chars[i] & 0xff); 104 } 105 } 106 107 byte[] write(String string){ 108 final int len = writetoBuffer(string); 109 byte[] bytes = new byte[len]; 110 for (int i = 0; i < len; i ++){ 111 bytes[i] = (byte) (chars[i] & 0xff); 112 } 113 return bytes; 114 } 115 116 } 117
| Popular Tags
|