1 11 package org.eclipse.core.internal.resources; 12 13 import java.io.DataInputStream ; 14 import java.io.IOException ; 15 import java.util.*; 16 import org.eclipse.core.internal.utils.Messages; 17 import org.eclipse.core.resources.IResourceStatus; 18 import org.eclipse.core.runtime.*; 19 20 24 public class MarkerSnapshotReader_2 extends MarkerSnapshotReader { 25 26 public static final byte INDEX = 1; 28 public static final byte QNAME = 2; 29 30 public static final byte ATTRIBUTE_NULL = 0; 32 public static final byte ATTRIBUTE_BOOLEAN = 1; 33 public static final byte ATTRIBUTE_INTEGER = 2; 34 public static final byte ATTRIBUTE_STRING = 3; 35 36 public MarkerSnapshotReader_2(Workspace workspace) { 37 super(workspace); 38 } 39 40 61 public void read(DataInputStream input) throws IOException , CoreException { 62 IPath path = new Path(input.readUTF()); 63 int markersSize = input.readInt(); 64 MarkerSet markers = new MarkerSet(markersSize); 65 ArrayList readTypes = new ArrayList(); 66 for (int i = 0; i < markersSize; i++) 67 markers.add(readMarkerInfo(input, readTypes)); 68 ResourceInfo info = workspace.getResourceInfo(path, false, false); 71 if (info == null) 72 return; 73 info.setMarkers(markers); 74 info.clear(ICoreConstants.M_MARKERS_SNAP_DIRTY); 75 } 76 77 private Map readAttributes(DataInputStream input) throws IOException { 78 short attributesSize = input.readShort(); 79 if (attributesSize == 0) 80 return null; 81 Map result = new MarkerAttributeMap(attributesSize); 82 for (int j = 0; j < attributesSize; j++) { 83 String key = input.readUTF(); 84 byte type = input.readByte(); 85 Object value = null; 86 switch (type) { 87 case ATTRIBUTE_INTEGER : 88 int intValue = input.readInt(); 89 switch (intValue) { 90 case 0: 91 value = MarkerInfo.INTEGER_ZERO; 92 break; 93 case 1: 94 value = MarkerInfo.INTEGER_ONE; 95 break; 96 case 2: 97 value = MarkerInfo.INTEGER_TWO; 98 break; 99 default: 100 value = new Integer (intValue); 101 } 102 break; 103 case ATTRIBUTE_BOOLEAN : 104 value = input.readBoolean() ? Boolean.TRUE : Boolean.FALSE; 105 break; 106 case ATTRIBUTE_STRING : 107 value = input.readUTF(); 108 break; 109 case ATTRIBUTE_NULL : 110 break; 112 } 113 if (value != null) 114 result.put(key, value); 115 } 116 return result.isEmpty() ? null : result; 117 } 118 119 private MarkerInfo readMarkerInfo(DataInputStream input, List readTypes) throws IOException , CoreException { 120 MarkerInfo info = new MarkerInfo(); 121 info.setId(input.readLong()); 122 byte constant = input.readByte(); 123 switch (constant) { 124 case QNAME : 125 String type = input.readUTF(); 126 info.setType(type); 127 readTypes.add(type); 128 break; 129 case INDEX : 130 info.setType((String ) readTypes.get(input.readInt())); 131 break; 132 default : 133 String msg = Messages.resources_readMarkers; 135 throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, null, msg, null); 136 } 137 info.internalSetAttributes(readAttributes(input)); 138 info.setCreationTime(input.readLong()); 139 return info; 140 } 141 } 142 | Popular Tags |