1 11 package org.eclipse.core.internal.watson; 12 13 import java.io.*; 14 import org.eclipse.core.internal.dtree.DataTreeReader; 15 import org.eclipse.core.internal.dtree.IDataFlattener; 16 import org.eclipse.core.internal.utils.Messages; 17 import org.eclipse.core.runtime.*; 18 19 34 public class ElementTreeReader { 35 37 protected IElementInfoFlattener elementInfoFlattener; 38 39 42 protected DataTreeReader dataTreeReader; 43 44 48 public ElementTreeReader(final IElementInfoFlattener factory) { 49 Assert.isNotNull(factory); 50 elementInfoFlattener = factory; 51 52 53 IDataFlattener f = new IDataFlattener() { 54 public void writeData(IPath path, Object data, DataOutput output) { 55 } 57 58 public Object readData(IPath path, DataInput input) throws IOException { 59 if (!Path.ROOT.equals(path)) 62 return factory.readElement(path, input); 63 return null; 64 } 65 }; 66 dataTreeReader = new DataTreeReader(f); 67 } 68 69 72 public ElementTreeReader getReader(int formatVersion) throws IOException { 73 if (formatVersion == 1) 74 return new ElementTreeReaderImpl_1(elementInfoFlattener); 75 throw new IOException(Messages.watson_unknown); 76 } 77 78 82 public ElementTree readDelta(ElementTree completeTree, DataInput input) throws IOException { 83 84 ElementTreeReader realReader = getReader(readNumber(input)); 85 return realReader.readDelta(completeTree, input); 86 } 87 88 93 public ElementTree[] readDeltaChain(DataInput input) throws IOException { 94 95 ElementTreeReader realReader = getReader(readNumber(input)); 96 return realReader.readDeltaChain(input); 97 } 98 99 105 protected static int readNumber(DataInput input) throws IOException { 106 byte b = input.readByte(); 107 int number = (b & 0xff); 109 if (number == 0xff) { number = input.readInt(); 111 } 112 return number; 113 } 114 115 120 public ElementTree readTree(DataInput input) throws IOException { 121 122 ElementTreeReader realReader = getReader(readNumber(input)); 123 return realReader.readTree(input); 124 } 125 } 126 | Popular Tags |