1 21 package com.db4o.inside.marshall; 22 23 import com.db4o.*; 24 25 26 public class StringMarshaller1 extends StringMarshaller{ 27 28 private static final int DEFRAGMENT_INCREMENT_OFFSET = YapConst.INT_LENGTH * 2; 29 30 public boolean inlinedStrings(){ 31 return true; 32 } 33 34 public void calculateLengths(Transaction trans, ObjectHeaderAttributes header, boolean topLevel, Object obj, boolean withIndirection) { 35 36 if(topLevel){ 37 header.addBaseLength(linkLength()); 38 header.prepareIndexedPayLoadEntry(trans); 39 }else{ 40 if(withIndirection){ 41 header.addPayLoadLength(linkLength()); 42 } 43 } 44 45 if(obj == null){ 46 return; 47 } 48 49 header.addPayLoadLength(trans.stream().stringIO().length((String )obj)); 50 } 51 52 public Object writeNew(Object obj, boolean topLevel, YapWriter writer, boolean redirect) { 53 54 YapStream stream = writer.getStream(); 55 String str = (String ) obj; 56 57 if(! redirect){ 58 if(str != null){ 59 writeShort(stream,str , writer); 60 } 61 return str; 65 } 66 67 if (str == null) { 68 writer.writeEmbeddedNull(); 69 return null; 70 } 71 72 int length = stream.stringIO().length(str); 73 74 YapWriter bytes = new YapWriter(writer.getTransaction(), length); 75 writeShort(stream, str, bytes); 76 77 writer.writePayload(bytes, topLevel); 78 return bytes; 79 } 80 81 public YapReader readIndexEntry(YapWriter parentSlot) throws CorruptionException{ 82 int payLoadOffSet = parentSlot.readInt(); 83 int length = parentSlot.readInt(); 84 if(payLoadOffSet == 0){ 85 return null; 86 } 87 return parentSlot.readPayloadWriter(payLoadOffSet, length); 88 } 89 90 public YapReader readSlotFromParentSlot(YapStream stream, YapReader reader) throws CorruptionException { 91 int payLoadOffSet = reader.readInt(); 92 int length = reader.readInt(); 93 if(payLoadOffSet == 0){ 94 return null; 95 } 96 return reader.readPayloadReader(payLoadOffSet, length); 97 } 98 99 public void defrag(SlotReader reader) { 100 reader.incrementOffset(DEFRAGMENT_INCREMENT_OFFSET); 101 } 102 103 } 104 | Popular Tags |