Skip to main content
summaryrefslogtreecommitdiffstats
blob: b76f1f4016a0f4f8804f40dd2124d8a775fb4ab0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Prashant Deva - Bug 194674 [prov] Provide write access to metadata repository
 *******************************************************************************/
package org.eclipse.equinox.internal.prov.metadata.repository;

import com.thoughtworks.xstream.XStream;
import java.io.*;
import org.eclipse.equinox.prov.core.repository.RepositoryCreationException;
import org.eclipse.equinox.prov.metadata.repository.IMetadataRepository;

/**
 * This class reads and writes provisioning metadata.
 * The implementation currently uses XStream.
 */
class MetadataRepositoryIO {

	/**
	 * Reads metadata from the given stream, and returns the contained array
	 * of abstract metadata repositories.
	 * This method performs buffering, and closes the stream when finished.
	 */
	public static IMetadataRepository read(InputStream input) throws RepositoryCreationException {
		XStream stream = new XStream();
		BufferedInputStream bufferedInput = null;
		try {
			try {
				bufferedInput = new BufferedInputStream(input);
				return (IMetadataRepository) stream.fromXML(bufferedInput);
			} finally {
				if (bufferedInput != null)
					bufferedInput.close();
			}
		} catch (IOException e) {
			throw new RepositoryCreationException(e);
		}
	}

	public static void write(AbstractMetadataRepository repository, OutputStream output) {
		XStream stream = new XStream();
		OutputStream bufferedOutput = null;
		try {
			try {
				bufferedOutput = new BufferedOutputStream(output);
				stream.toXML(repository, bufferedOutput);
			} finally {
				if (bufferedOutput != null)
					bufferedOutput.close();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Back to the top