1 11 package org.eclipse.core.internal.resources; 12 13 import java.io.DataOutputStream ; 14 import java.io.IOException ; 15 import java.util.*; 16 import org.eclipse.core.internal.watson.IPathRequestor; 17 import org.eclipse.core.runtime.QualifiedName; 18 19 public class SyncInfoWriter { 20 protected Synchronizer synchronizer; 21 protected Workspace workspace; 22 23 public static final int SYNCINFO_SAVE_VERSION = 3; 25 public static final int SYNCINFO_SNAP_VERSION = 3; 26 27 public static final byte INDEX = 1; 29 public static final byte QNAME = 2; 30 31 public SyncInfoWriter(Workspace workspace, Synchronizer synchronizer) { 32 super(); 33 this.workspace = workspace; 34 this.synchronizer = synchronizer; 35 } 36 37 public void savePartners(DataOutputStream output) throws IOException { 38 Set registry = synchronizer.getRegistry(); 39 output.writeInt(registry.size()); 40 for (Iterator i = registry.iterator(); i.hasNext();) { 41 QualifiedName qname = (QualifiedName) i.next(); 42 output.writeUTF(qname.getQualifier()); 43 output.writeUTF(qname.getLocalName()); 44 } 45 } 46 47 59 public void saveSyncInfo(ResourceInfo info, IPathRequestor requestor, DataOutputStream output, List writtenPartners) throws IOException { 60 Map table = info.getSyncInfo(false); 61 if (table == null) 62 return; 63 if (output.size() == 0) 66 output.writeInt(SYNCINFO_SAVE_VERSION); 67 output.writeUTF(requestor.requestPath().toString()); 68 output.writeInt(table.size()); 69 for (Iterator i = table.entrySet().iterator(); i.hasNext();) { 70 Map.Entry entry = (Map.Entry) i.next(); 71 QualifiedName name = (QualifiedName) entry.getKey(); 72 int index = writtenPartners.indexOf(name); 75 if (index == -1) { 76 output.writeByte(QNAME); 78 output.writeUTF(name.getQualifier()); 79 output.writeUTF(name.getLocalName()); 80 writtenPartners.add(name); 81 } else { 82 output.writeByte(INDEX); 83 output.writeInt(index); 84 } 85 byte[] bytes = (byte[]) entry.getValue(); 86 output.writeInt(bytes.length); 87 output.write(bytes); 88 } 89 } 90 91 101 public void snapSyncInfo(ResourceInfo info, IPathRequestor requestor, DataOutputStream output) throws IOException { 102 if (!info.isSet(ICoreConstants.M_SYNCINFO_SNAP_DIRTY)) 103 return; 104 Map table = info.getSyncInfo(false); 105 if (table == null) 106 return; 107 output.writeInt(SYNCINFO_SNAP_VERSION); 109 output.writeUTF(requestor.requestPath().toString()); 110 output.writeInt(table.size()); 111 for (Iterator i = table.entrySet().iterator(); i.hasNext();) { 112 Map.Entry entry = (Map.Entry) i.next(); 113 QualifiedName name = (QualifiedName) entry.getKey(); 114 output.writeUTF(name.getQualifier()); 115 output.writeUTF(name.getLocalName()); 116 byte[] bytes = (byte[]) entry.getValue(); 117 output.writeInt(bytes.length); 118 output.write(bytes); 119 } 120 info.clear(ICoreConstants.M_SYNCINFO_SNAP_DIRTY); 121 } 122 } 123 | Popular Tags |