KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > SyncInfoReader_3


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.resources;
12
13 import java.io.*;
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16 import org.eclipse.core.internal.utils.Messages;
17 import org.eclipse.core.internal.utils.ObjectMap;
18 import org.eclipse.core.resources.IResourceStatus;
19 import org.eclipse.core.runtime.*;
20 import org.eclipse.osgi.util.NLS;
21
22 /**
23  * This class is used to read sync info from disk. This is the implementation
24  * for reading files with version number 3.
25  */

26 public class SyncInfoReader_3 extends SyncInfoReader {
27
28     // for sync info
29
public static final byte INDEX = 1;
30     public static final byte QNAME = 2;
31
32     public SyncInfoReader_3(Workspace workspace, Synchronizer synchronizer) {
33         super(workspace, synchronizer);
34     }
35
36     /**
37      * SAVE_FILE -> VERSION_ID RESOURCE+
38      * VERSION_ID -> int
39      * RESOURCE -> RESOURCE_PATH SIZE SYNCINFO*
40      * RESOURCE_PATH -> String
41      * SIZE -> int
42      * SYNCINFO -> TYPE BYTES
43      * TYPE -> INDEX | QNAME
44      * INDEX -> byte int
45      * QNAME -> byte String
46      * BYTES -> byte[]
47      *
48      */

49     public void readSyncInfo(DataInputStream input) throws IOException, CoreException {
50         try {
51             List JavaDoc readPartners = new ArrayList JavaDoc(5);
52             while (true) {
53                 IPath path = new Path(input.readUTF());
54                 readSyncInfo(path, input, readPartners);
55             }
56         } catch (EOFException e) {
57             // ignore end of file
58
}
59     }
60
61     private void readSyncInfo(IPath path, DataInputStream input, List JavaDoc readPartners) throws IOException, CoreException {
62         int size = input.readInt();
63         ObjectMap table = new ObjectMap(size);
64         for (int i = 0; i < size; i++) {
65             QualifiedName name = null;
66             byte type = input.readByte();
67             switch (type) {
68                 case QNAME :
69                     String JavaDoc qualifier = input.readUTF();
70                     String JavaDoc local = input.readUTF();
71                     name = new QualifiedName(qualifier, local);
72                     readPartners.add(name);
73                     break;
74                 case INDEX :
75                     name = (QualifiedName) readPartners.get(input.readInt());
76                     break;
77                 default :
78                     //if we get here then the sync info file is corrupt
79
String JavaDoc msg = NLS.bind(Messages.resources_readSync, path == null ? "" : path.toString()); //$NON-NLS-1$
80
throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, path, msg, null);
81             }
82             // read the bytes
83
int length = input.readInt();
84             byte[] bytes = new byte[length];
85             input.readFully(bytes);
86             // put them in the table
87
table.put(name, bytes);
88         }
89         // set the table on the resource info
90
ResourceInfo info = workspace.getResourceInfo(path, true, false);
91         if (info == null)
92             return;
93         info.setSyncInfo(table);
94         info.clear(ICoreConstants.M_SYNCINFO_SNAP_DIRTY);
95     }
96 }
97
Popular Tags