1 11 package org.eclipse.core.internal.resources; 12 13 import java.io.DataInputStream ; 14 import java.io.IOException ; 15 import java.util.HashSet ; 16 import java.util.Set ; 17 import org.eclipse.core.internal.utils.Messages; 18 import org.eclipse.core.resources.IResourceStatus; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.QualifiedName; 21 import org.eclipse.osgi.util.NLS; 22 23 27 public class SyncInfoReader { 28 protected Workspace workspace; 29 protected Synchronizer synchronizer; 30 31 public SyncInfoReader(Workspace workspace, Synchronizer synchronizer) { 32 super(); 33 this.workspace = workspace; 34 this.synchronizer = synchronizer; 35 } 36 37 40 protected SyncInfoReader getReader(int formatVersion) throws IOException { 41 switch (formatVersion) { 42 case 2 : 43 return new SyncInfoReader_2(workspace, synchronizer); 44 case 3 : 45 return new SyncInfoReader_3(workspace, synchronizer); 46 default : 47 throw new IOException (NLS.bind(Messages.resources_format, new Integer (formatVersion))); 48 } 49 } 50 51 public void readPartners(DataInputStream input) throws CoreException { 52 try { 53 int size = input.readInt(); 54 Set registry = new HashSet (size); 55 for (int i = 0; i < size; i++) { 56 String qualifier = input.readUTF(); 57 String local = input.readUTF(); 58 registry.add(new QualifiedName(qualifier, local)); 59 } 60 synchronizer.setRegistry(registry); 61 } catch (IOException e) { 62 String message = NLS.bind(Messages.resources_readSync, e); 63 throw new ResourceException(new ResourceStatus(IResourceStatus.INTERNAL_ERROR, message)); 64 } 65 } 66 67 public void readSyncInfo(DataInputStream input) throws IOException , CoreException { 68 int formatVersion = readVersionNumber(input); 71 SyncInfoReader reader = getReader(formatVersion); 72 reader.readSyncInfo(input); 73 } 74 75 protected static int readVersionNumber(DataInputStream input) throws IOException { 76 return input.readInt(); 77 } 78 } 79 | Popular Tags |