1 8 9 package com.sleepycat.bind.tuple; 10 11 import com.sleepycat.je.DatabaseEntry; 12 13 26 public class TupleBase { 27 28 private int outputBufferSize; 29 30 37 public TupleBase() { 38 outputBufferSize = 0; 39 } 40 41 51 public void setTupleBufferSize(int byteSize) { 52 outputBufferSize = byteSize; 53 } 54 55 62 public int getTupleBufferSize() { 63 return outputBufferSize; 64 } 65 66 87 protected TupleOutput getTupleOutput(Object object) { 88 int byteSize = getTupleBufferSize(); 89 if (byteSize != 0) { 90 return new TupleOutput(new byte[byteSize]); 91 } else { 92 return new TupleOutput(); 93 } 94 } 95 96 104 public static void outputToEntry(TupleOutput output, DatabaseEntry entry) { 105 106 entry.setData(output.getBufferBytes(), output.getBufferOffset(), 107 output.getBufferLength()); 108 } 109 110 118 public static void inputToEntry(TupleInput input, DatabaseEntry entry) { 119 120 entry.setData(input.getBufferBytes(), input.getBufferOffset(), 121 input.getBufferLength()); 122 } 123 124 133 public static TupleInput entryToInput(DatabaseEntry entry) { 134 135 return new TupleInput(entry.getData(), entry.getOffset(), 136 entry.getSize()); 137 } 138 139 146 public static TupleOutput newOutput() { 147 148 return new TupleOutput(); 149 } 150 151 159 public static TupleOutput newOutput(byte[] buffer) { 160 161 return new TupleOutput(buffer); 162 } 163 } 164 | Popular Tags |