Skip to main content
summaryrefslogtreecommitdiffstats
blob: 601b9561a30a67f7725d6cd37ccddce6f96da327 (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
/*******************************************************************************
 * Copyright (c) 2010, 2011 Peter Stibrany 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:
 *     Peter Stibrany - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;

/**
 * @author Peter Stibrany
 */
public class AttachmentFileStorage extends PlatformObject implements IStorage {

	private final File file;

	private final String name;

	public AttachmentFileStorage(File file, String name) {
		this.file = file;
		this.name = name;
	}

	public InputStream getContents() throws CoreException {
		try {
			return new FileInputStream(file);
		} catch (FileNotFoundException e) {
			throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
					Messages.FileStorage_unableToReadAttachmentFile, e));
		}
	}

	public IPath getFullPath() {
		return Path.fromOSString(file.getAbsolutePath());
	}

	public String getName() {
		return name;
	}

	public boolean isReadOnly() {
		return true;
	}

}

Back to the top