1 21 package com.db4o.inside.marshall; 22 23 import com.db4o.*; 24 25 26 public abstract class StringMarshaller { 27 28 29 public abstract boolean inlinedStrings(); 30 31 public abstract void calculateLengths(Transaction trans, ObjectHeaderAttributes header, boolean topLevel, Object obj, boolean withIndirection); 32 33 protected final int linkLength(){ 34 return YapConst.INT_LENGTH + YapConst.ID_LENGTH; 35 } 36 37 public abstract Object writeNew(Object a_object, boolean topLevel, YapWriter a_bytes, boolean redirect); 38 39 public final String read(YapStream stream, YapReader reader) throws CorruptionException { 40 if (reader == null) { 41 return null; 42 } 43 if (Deploy.debug) { 44 reader.readBegin(YapConst.YAPSTRING); 45 } 46 String ret = readShort(stream, reader); 47 if (Deploy.debug) { 48 reader.readEnd(); 49 } 50 return ret; 51 } 52 53 public String readFromOwnSlot(YapStream stream, YapReader reader){ 54 try { 55 return read(stream, reader); 56 } catch (Exception e) { 57 if(Deploy.debug || Debug.atHome) { 58 e.printStackTrace(); 59 } 60 } 61 return ""; 62 } 63 64 public String readFromParentSlot(YapStream stream, YapReader reader, boolean redirect) throws CorruptionException { 65 if(! redirect){ 66 return read(stream, reader); 67 } 68 return read(stream, readSlotFromParentSlot(stream, reader)); 69 } 70 71 public abstract YapReader readIndexEntry(YapWriter parentSlot) throws CorruptionException; 72 73 public static String readShort(YapStream stream, YapReader bytes) throws CorruptionException { 74 return readShort(stream.stringIO(),stream.configImpl().internStrings(),bytes); 75 } 76 77 public static String readShort(YapStringIO io, boolean internStrings, YapReader bytes) throws CorruptionException { 78 int length = bytes.readInt(); 79 if (length > YapConst.MAXIMUM_BLOCK_SIZE) { 80 throw new CorruptionException(); 81 } 82 if (length > 0) { 83 String str = io.read(bytes, length); 84 if(! Deploy.csharp){ 85 if(internStrings){ 86 str = str.intern(); 87 } 88 } 89 return str; 90 } 91 return ""; 92 } 93 94 public abstract YapReader readSlotFromParentSlot(YapStream stream, YapReader reader) throws CorruptionException; 98 99 public static YapReader writeShort(YapStream stream, String str){ 100 YapReader reader = new YapReader(stream.stringIO().length(str)); 101 writeShort(stream, str, reader); 102 return reader; 103 } 104 105 public static void writeShort(YapStream stream, String str, YapReader reader){ 106 int length = str.length(); 107 if (Deploy.debug) { 108 reader.writeBegin(YapConst.YAPSTRING); 109 } 110 reader.writeInt(length); 111 stream.stringIO().write(reader, str); 112 if (Deploy.debug) { 113 reader.writeEnd(); 114 } 115 } 116 117 public abstract void defrag(SlotReader reader); 118 } 119 | Popular Tags |