01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.internal;
22:
23: import com.db4o.marshall.*;
24:
25: /**
26: * @exclude
27: */
28: public class LatinStringIO {
29:
30: public int bytesPerChar() {
31: return 1;
32: }
33:
34: public byte encodingByte() {
35: return Const4.ISO8859;
36: }
37:
38: static LatinStringIO forEncoding(byte encodingByte) {
39: switch (encodingByte) {
40: case Const4.ISO8859:
41: return new LatinStringIO();
42: default:
43: return new UnicodeStringIO();
44: }
45: }
46:
47: public int length(String str) {
48: return str.length() + Const4.OBJECT_LENGTH + Const4.INT_LENGTH;
49: }
50:
51: public String read(ReadBuffer buffer, int length) {
52: char[] chars = new char[length];
53: for (int ii = 0; ii < length; ii++) {
54: chars[ii] = (char) (buffer.readByte() & 0xff);
55: }
56: return new String(chars, 0, length);
57: }
58:
59: public String read(byte[] bytes) {
60: char[] chars = new char[bytes.length];
61: for (int i = 0; i < bytes.length; i++) {
62: chars[i] = (char) (bytes[i] & 0xff);
63: }
64: return new String(chars, 0, bytes.length);
65: }
66:
67: public int shortLength(String str) {
68: return str.length() + Const4.INT_LENGTH;
69: }
70:
71: public void write(WriteBuffer buffer, String str) {
72: final int length = str.length();
73: char[] chars = new char[length];
74: str.getChars(0, length, chars, 0);
75: for (int i = 0; i < length; i++) {
76: buffer.writeByte((byte) (chars[i] & 0xff));
77: }
78: }
79:
80: byte[] write(String str) {
81: final int length = str.length();
82: char[] chars = new char[length];
83: str.getChars(0, length, chars, 0);
84: byte[] bytes = new byte[length];
85: for (int i = 0; i < length; i++) {
86: bytes[i] = (byte) (chars[i] & 0xff);
87: }
88: return bytes;
89: }
90:
91: }
|