| /******************************************************************************* |
| * Copyright (c) 2009, 2017 xored software, Inc. and others. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * xored software, Inc. - initial API and Implementation (Alex Panchenko) |
| *******************************************************************************/ |
| package org.eclipse.dltk.ui.documentation; |
| |
| import java.io.File; |
| import java.io.FileInputStream; |
| import java.io.FileNotFoundException; |
| import java.io.InputStream; |
| import java.io.InputStreamReader; |
| import java.io.Reader; |
| import java.io.UnsupportedEncodingException; |
| import java.net.MalformedURLException; |
| import java.net.URL; |
| |
| /** |
| * @since 2.0 |
| */ |
| public class DocumentationFileResponse extends AbstractDocumentationResponse { |
| |
| private final File file; |
| private final String encoding; |
| |
| /** |
| * @param file |
| * @param encoding |
| */ |
| public DocumentationFileResponse(Object object, File file) { |
| this(object, file, null); |
| } |
| |
| /** |
| * @param file |
| * @param encoding |
| */ |
| public DocumentationFileResponse(Object object, File file, String encoding) { |
| super(object); |
| this.file = file; |
| this.encoding = encoding; |
| } |
| |
| @Override |
| public Reader getReader() throws FileNotFoundException, |
| UnsupportedEncodingException { |
| final InputStream stream = new FileInputStream(file); |
| return encoding != null ? new InputStreamReader(stream, encoding) |
| : new InputStreamReader(stream); |
| } |
| |
| @Override |
| public URL getURL() throws MalformedURLException { |
| return file.toURI().toURL(); |
| } |
| |
| } |